xxxxxxxxxx
106
let caught = 0;
let missed = 0;
class Fish {
constructor() {
this.x = random(-width, 0);
this.y = random(height / 2, height);
this.speedX = random(1, 6);
this.speedY = random(-1, 1);
this.size = random(40, 80);
}
swim() {
this.x += this.speedX;
this.y += this.speedY;
if (this.x > width) {
this.x = random(-width, -100);
missed++;
}
if (this.y > height - this.size || this.y < height / 3) {
this.speedY *= -1;
}
}
show() {
fill("red");
drawFish(this.x, this.y, this.size);
}
}
function drawFish(x, y, size) {
image(fishImg, x, y, size * 1.28, size);
}
function showFisher() {
fill("yellow");
circle(mouseX + 30, height / 3 - 62, 20);
circle(mouseX + 35, height / 3 - 30, 40);
fill("brown");
stroke("black");
strokeWeight(1);
quad(
mouseX + 10,
height / 3 - 35,
mouseX + 100,
height / 3 - 35,
mouseX + 90,
height / 3,
mouseX + 20,
height / 3
);
strokeWeight(3);
line(mouseX + 30, height / 3 - 35, mouseX, height / 3 - 60);
noFill();
strokeWeight(2);
arc(mouseX, mouseY + 110, 30, 30, 0, HALF_PI);
stroke("white");
strokeWeight(0.75);
line(mouseX, height / 3 - 60, mouseX, mouseY + 125);
}
let fishes = [];
let fishImg;
function preload() {
fishImg = loadImage("fish.png");
}
function setup() {
createCanvas(window.innerWidth, window.innerHeight);
for (let i = 0; i < 10; i++) {
fishes.push(new Fish());
}
}
function draw() {
background("blue");
fill("skyblue");
noStroke();
rect(0, 0, width, height / 3);
for (let fish of fishes) {
fish.show();
fish.swim();
if (
mouseX > fish.x &&
mouseX < fish.x + fish.size &&
mouseY + 110 > fish.y &&
mouseY + 125 < fish.y + fish.size
) {
caught++;
fish.x = random(-width, -100);
}
}
showFisher();
textAlign(CENTER);
noStroke();
fill("black");
text("Fishes Hooked : " + caught, width / 2, 20);
text("Fishes Missed : " + missed, width / 2, 40);
if (caught - missed >= 100) {
noLoop();
textSize(45);
text("You're an Expert!", width / 2, height / 2);
}
}