Hi All,
I need help with making the up and down arrows increase and decrease the distance the fish travels, effectively changing its speed. How do I do this? Here's what I have thus far:
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* The fish tries to eat the fly, while being chaces by a Dolphin.
* @author Thomas Dozer
* @version 10 November 2013
*/
public class Fish extends Animal
{
/**
* Act - do whatever the Fish wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()
{
moveFish(); //Key stroke method
lookForFly(); //look for the Fly method
}
/**
* Check whether a control key on the keyboard has been pressed.
* If it has, react accordingly.
*/
private void moveFish()
{
if(Greenfoot.isKeyDown("left"))
{
turn(-4);
}
if(Greenfoot.isKeyDown("right"))
{
turn(4);
}
if(Greenfoot.isKeyDown("up"))
{
move(5);
}
if(Greenfoot.isKeyDown("down"))
{
move(-5);
}
}
/**
* Check whether we have stumbled upon a Fly.
* If we have, eat it. If not, do nothing.
*/
public void lookForFly()
{
if ( canSee(Fly.class) ) //can the Fish see the Fly
{
eat(Fly.class); //if Fly is found, then crab eats it
Greenfoot.playSound("slurp.wav"); // .wav file is played when Fly is eaten
}
}
}

