Hello, I am currently doing a final for one of my beginner classes and we are doing custom classes. My project is to have fish swimming around and when your mouse comes into screen, there is a hook following the mouse and the fish swim off screen.
Here is where my problems arise, I have been able to make the fish swim around the screen with its own child class, however, I cannot get the hook image to appear at all following the mouse. I made the “hook” its own child class but it will not appear. I also don’t know where to begin when it comes to wrapping my head around how to make the fish swim off the screen when the mouse moves on screen.
here is my code:
Parent Class:
PImage water, fish1, fish2, hook;
Fish f1, f2;
Hook h1;
void setup() {
size(500,500);
water = loadImage("water.JPG");
fish1 = loadImage("fish 1.png");
fish2 = loadImage("fish 2.png");
hook = loadImage("hook.png");
f1 = new Fish(fish1);
f2= new Fish(fish2);
h1 = new Hook(hook);
}
void draw(){
image(water,0 ,0);
f1.move();
f1.display();
f2.move();
f2.display();
}
Child Class Fish:
class Fish{
int x, y;
int xTarget, yTarget;
int easeSpeed;
PImage Image;
Fish(PImage fishImage){
x = int(random(-width/2, width/2));
y = int(random(-height/2, height/2));
Image = fishImage;
makeTarget();
}
void move(){
int distanceX = x - xTarget;
int distanceY = y - yTarget;
x = x-distanceX/easeSpeed;
y = y-distanceY/easeSpeed;
if (abs(distanceX) < easeSpeed && abs(distanceY) < easeSpeed)
{
makeTarget();
}
}
void makeTarget(){
xTarget = int(random(-width/2, width/2));
yTarget = int(random(-height/2, height/2));
easeSpeed = int(random(20, 90));
}
void display(){
pushMatrix();
translate(width/2, height/2);
image(Image, x, y);
popMatrix();
}
}
Child Class Hook:
class Hook{
PImage image;
Hook(PImage hookImage) {
image = hookImage;
}
void display(){
imageMode(CENTER);
image(image, mouseX, mouseY);
}
}
any help would be greatly appreciated