xxxxxxxxxx
324
let mode = 0;
let stringscore = "SCORE: "
let score = 0
let fishes = [];
let boots = [];
let fishingline;
function preload() {
sea = loadImage("sea.jpg");
startingscreenbackground = loadImage("startingscreenbackground.jpg");
left_fish = loadImage("left_fish.png");
right_fish = loadImage("right_fish.png");
left_boot = loadImage("left_boot.png");
right_boot = loadImage("right_boot.png");
music = loadSound("music.mp3");
fishcaughtsound = loadSound("fishcaught.mp3");
bootcaughtsound = loadSound("bootcaught.mp3");
aquinofont = loadFont('AquinoDemo-511lj.ttf');
}
function setup() {
createCanvas(500, 600);
music.play();
fishingline = new FishingLine();
for (let i = 0; i < 15; i++) {
fishes.push(new Fish());
}
for (let i = 0; i < 7; i++) {
boots.push(new Boot());
}
}
function draw() {
switch (mode) {
case 0:
startingScreen();
break;
case 1:
imageMode(CENTER);
image(sea, width/2, height/2, width, height);
textFont("Impact", 25);
for (let i = 0; i < fishes.length; i++) {
fishes[i].run();
catchFish(i);
}
for (let i = 0; i < boots.length; i++) {
boots[i].run();
catchBoot(i);
}
fishingline.run();
text(stringscore, width-140, 50);
text(str(score), width-60, 50);
if (fishes.length == 0){
mode = 2;
}
break;
case 2:
restartScreen();
break;
}
}
class FishingLine{
constructor(){
this.linex = width/2;
this.liney = 0;
}
display(){
push();
strokeWeight(1);
stroke(0)
line(this.linex, this.liney, this.linex, mouseY);
noFill();
strokeWeight(2)
stroke(70);
arc(this.linex, mouseY-20, 40, 40, 100, HALF_PI);
pop();
}
run(){
this.display();
}
}
class Fish {
constructor(){
this.side = random(100);
this.start = random(0,width*5);
this.leftx = 0-this.start;
this.rightx = width+this.start;
this.y = random(25,height-25);
this.speed = random(1,5);
}
run(){
this.spawn();
this.swim();
this.goback();
}
spawn(){
if (this.side < 50){
image(left_fish, this.leftx,this.y,50,50);
}
else if (this.side >= 50){
image(right_fish, this.rightx,this.y,50,50);
}
}
swim(){
if (this.side < 50){
this.leftx += this.speed;
}
else if (this.side >= 50){
this.rightx -= this.speed;
}
}
goback(){
if (this.side < 50 && this.leftx > width+this.start){
this.leftx = 0-this.start;
}
else if(this.side >= 50 && this.rightx < 0-this.start){
this.rightx = width+this.start;
}
}
}
function catchFish(i){
let proximity;
if (fishes[i].side < 50){
proximity = dist(fishes[i].leftx, fishes[i].y, width/2,mouseY);
}
else if (fishes[i].side >= 50){
proximity = dist(fishes[i].rightx, fishes[i].y, width/2,mouseY);
}
if (proximity < 25){
fishes.splice(i,1);
fishcaughtsound.play();
score = score + 1;
}
}
class Boot{
constructor(){
this.side = random(100);
this.start = random(0,width*5);
this.leftx = 0-this.start;
this.rightx = width+this.start;
this.y = random(25,height-50);
this.speed = random(1,3);
}
run(){
this.spawn();
this.swim();
this.goback();
}
spawn(){
if (this.side < 50){
image(left_boot, this.leftx,this.y,150,150);
}
else if (this.side >= 50){
image(right_boot, this.rightx,this.y,150,150);
}
}
swim(){
if (this.side < 50){
this.leftx += this.speed;
}
else if (this.side >= 50){
this.rightx -= this.speed;
}
}
goback(){
if (this.side < 50 && this.leftx > width+this.start){
this.leftx = 0-this.start;
}
else if(this.side >= 50 && this.rightx < 0-this.start){
this.rightx = width+this.start;
}
}
}
function catchBoot(i){
let proximity;
if (boots[i].side < 50){
proximity = dist(boots[i].leftx, boots[i].y, width/2,mouseY);
}
else if (boots[i].side >= 50){
proximity = dist(boots[i].rightx, boots[i].y, width/2,mouseY);
}
if (proximity < 50){
bootcaughtsound.play();
mode = 2;
}
}
function startingScreen(){
push();
textAlign(CENTER);
textFont(aquinofont);
let s1 = "Fishing Simulator!";
let s2 = "Instructions";
let s3 = "Move your mouse vertically to control the fishing line";
let s4 = "Place the hook on fish to catch them";
let s5 = "Your score is on the top right";
let s6 = "Try to catch all twenty five;"
let s7 = "Stay away from the boots or it is GAME OVER :o";
let s8 = "START"
imageMode(CENTER);
image(startingscreenbackground, width/2, height/2, width, height);
textSize(35);
text(s1,width/2, height/7);
textSize(25);
text(s2,width/2, height/5+25);
textSize(12);
text(s3,width/2, height/5+50);
text(s4,width/2, height/5+75);
text(s5,width/2, height/5+100);
text(s6,width/2, height/5+125);
text(s7,width/2, height/5+150);
textSize(75)
fill(0,0,200)
text(s8, width/2, height/1.5);
rectMode(CENTER);
fill(255,100)
strokeWeight(3)
stroke(0,0,200)
rect(width/2, height/1.6, 350, 150, 20);
if (
mouseIsPressed &&
mouseX > width / 2 - 175 &&
mouseX < width / 2 + 175 &&
mouseY > height / 2 - 75 &&
mouseY < height / 2 + 75){
mode = 1
}
pop();
}
function restartScreen(){
push();
textAlign(CENTER);
let s1 = "Score";
let s2 = str(score);
let s3 = "retry"
let s4 = "winner"
imageMode(CENTER);
image(startingscreenbackground, width/2, height/2, width, height);
textFont(aquinofont,50);
text(s1,width/2, height/7);
textFont("Calibri", 70);
text(s2,width/2, height/5+35);
textFont(aquinofont,85)
if(score == 15){
text(s4,width/2, height/5+130);
}
textSize(75)
fill(0,0,200)
text(s3, width/2, height/1.5);
rectMode(CENTER);
fill(255,100)
strokeWeight(3)
stroke(0,0,200)
rect(width/2, height/1.6, 350, 150, 20);
if (
mouseIsPressed &&
mouseX > width / 2 - 175 &&
mouseX < width / 2 + 175 &&
mouseY > height / 2 - 75 &&
mouseY < height / 2 + 75){
mode = 1
score=0;
fishes=[];
boots=[];
for (let i = 0; i < 15; i++) {
fishes.push(new Fish());
}
for (let i = 0; i < 7; i++) {
boots.push(new Boot());
}
}
pop();
}