xxxxxxxxxx
130
let score = 0
let fishes = [];
let fishingline;
function preload() {
sea = loadImage("sea.jpg");
left_fish = loadImage("left_fish.png");
right_fish = loadImage("right_fish.png");
}
function setup() {
createCanvas(500, 600);
fishingline = new FishingLine();
for (let i = 0; i < 1; i++) {
fishes.push(new Fish());
}
}
function draw() {
imageMode(CENTER);
image(sea, width/2, height/2, width, height);
for (let i = 0; i < fishes.length; i++) {
fishes[i].run();
catchFish(i);
}
fishingline.run();
}
class FishingLine{
constructor(){
this.linex = width/2;
this.liney = 0;
}
display(){
strokeWeight(1);
stroke(0)
line(this.linex, this.liney, this.linex, mouseY);
noFill();
strokeWeight(2)
stroke(100);
arc(this.linex, mouseY-20, 40, 40, 100, HALF_PI);
}
run(){
this.display();
}
}
class Fish {
constructor(){
this.side = random(100);
this.start = random(0,width/2);
this.leftx = 0-this.start;
this.rightx = width+this.start;
this.y = random(25,height-25);
this.speed = random(1,5);
this.direction = 0;
if (this.side >= 50){
this.direction = 1;
}
}
run(){
this.spawn();
this.swim();
this.turn();
}
spawn(){
if (this.direction == 0){
ellipse(this.leftx+1,this.y,50,50);
image(left_fish, this.leftx+1,this.y,50,50);
}
else if (this.direction == 1){
ellipse(this.rightx+1,this.y,50,50);
image(right_fish, this.rightx-1,this.y,50,50);
}
}
swim(){
if (this.side < 50){
this.leftx += this.speed;
// print(this.leftx)
}
else if (this.side >= 50){
this.rightx -= this.speed;
// print(this.rightx)
}
}
turn(){
if (this.side < 50 && this.leftx > width+this.start){
this.direction = 1
this.spawn();
this.speed *= -1;
// print(this.leftx)
}
else if (this.side < 50 && this.leftx < 0-this.start){
this.direction = 0
this.spawn();
this.speed *= -1;
}
else if (this.side >= 50 && this.rightx < 0-this.start){
this.direction = 0
this.spawn();
this.speed *= -1;
}
else if (this.side >= 50 && this.rightx > width+this.start){
this.direction = 1
this.spawn();
this.speed *= -1;
}
}
}
function catchFish(i){
let proximity;
if (fishes[i].side < 50){
let proximity = dist(fishes[i].leftx, fishes[i].y, width/2,mouseY);
print(proximty)
}
else {
let proximity = dist(fishes[i].rightx, fishes[i].y, width/2,mouseY);
print(proximity)
}
if (proximity < 50){
score = score + 1
print(score);
}
}