We were told to create a Crab scenario for IT where the crab only eats seaweed.
The part that I'm having trouble with is getting the seaweed to look like it is waving in with the tide.
I'm able to get it to switch between 2 images but it switches too fast to be seen, can anyone help with coding please?
This is what I have so far:
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
public class Seaweed extends Animal
{
private GreenfootImage image1;
private GreenfootImage image2;
public Seaweed()
{
image1 = new GreenfootImage("seaweed.png");
image2 = new GreenfootImage("seaweed2.png");
setImage(image1);
}
public void act()
{
wave();
}
public void wave()
{
if ( getImage() == image1 )
{
setImage(image2);
}
else
{
setImage(image1);
}
}
}
I also need to give it a 15% chance of it moving every turn so if you could help with that too it would be great, thanks