# Need help on a final project

**URL:** https://discourse.processing.org/t/need-help-on-a-final-project/2756
**Category:** Processing
**Created:** [August 18, 2018, 3:55pm UTC](https://discourse.processing.org/t/need-help-on-a-final-project/2756 "2018-08-18T15:55:00Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![magic\_moose](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/magic_moose/32/1001_2.png) [@magic\_moose](https://discourse.processing.org/u/magic_moose)
#### Post date: [August 18, 2018, 3:55pm UTC](https://discourse.processing.org/t/need-help-on-a-final-project/2756/1 "2018-08-18T15:55:00Z")

</div>

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:

```auto
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:

```auto
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:

```auto
class Hook{
  PImage image;
  
  Hook(PImage hookImage) {
    image = hookImage;
  }
  
  void display(){
    imageMode(CENTER);
    image(image, mouseX, mouseY);

  }
}

```

any help would be greatly appreciated

---

<div class="post-metadata">

### Author: ![jb4x](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jb4x/32/789_2.png) [@jb4x](https://discourse.processing.org/u/jb4x)
#### Post date: [August 18, 2018, 3:59pm UTC](https://discourse.processing.org/t/need-help-on-a-final-project/2756/2 "2018-08-18T15:59:18Z")

</div>

Hi,

it seems that you are never asking to display your hook inside the `draw()` function.

Try adding this line at the end of the `draw()` function:  
`h1.display();`

---

<div class="post-metadata">

### Author: ![magic\_moose](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/magic_moose/32/1001_2.png) [@magic\_moose](https://discourse.processing.org/u/magic_moose)
#### Post date: [August 18, 2018, 3:59pm UTC](https://discourse.processing.org/t/need-help-on-a-final-project/2756/3 "2018-08-18T15:59:53Z")

</div>

EDIT:

I figured out my display issue on the hook.

Now I only don’t know how to get the fish to swim off screen when the mouse is at a certain location

---

<div class="post-metadata">

### Author: ![jb4x](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jb4x/32/789_2.png) [@jb4x](https://discourse.processing.org/u/jb4x)
#### Post date: [August 18, 2018, 4:08pm UTC](https://discourse.processing.org/t/need-help-on-a-final-project/2756/4 "2018-08-18T16:08:29Z")

</div>

To do that, you need to get, for every fish in your tank, the distance between that fish and the screen. Even better, you can figure out the direction from your fish to the hook.

You can do that by using [PVector](https://processing.org/reference/PVector.html) objects.

It means that you will also need to edit your fish class to add a new function that takes the x and y position of your mouse and gives you a PVector pointing to the mouse position:

```auto
PVector getDeltaFromPoint(x, y) {
  ...
}

```

Then with that vector, you can get the magnitude (=distance) with the [mag() function](https://processing.org/reference/PVector_mag_.html) and if the distance is lower than a certain value you make your fish go the opposite direction.
