My Shark's movement won't work in my game, it stutters from now and then. My Seacreature doesn't move at all and I don't know what is wrong with the code. If someone could help it will be very helpfull
MY SHARK CODE
MY SeaCreature Code:
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class SeaCreature here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class SeaCreature extends Actor
{
/**
* Act - do whatever the SeaCreature wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void Act()
{
// Add your action code here.
move(4);
moveAround();
}
public void moveAround()
{
move(4);
turn(Greenfoot.getRandomNumber(90));
}
}
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) /** * Write a description of class Shark here. * * @author (your name) * @version (a version number or a date) */ public class Shark extends Actor { /** * Act - do whatever the Shark wants to do. This method is called whenever * the 'Act' or 'Run' button gets pressed in the environment. */ public void act() { moveAndTurn(); eat(); } public void moveAndTurn() { if (Greenfoot.isKeyDown("a")) { turn(-3); } if (Greenfoot.isKeyDown("d")) { turn(3); } if (Greenfoot.isKeyDown("w")) { move(3); } if (Greenfoot.isKeyDown("s")) { move(-3); } } public void eat() { Actor SeaCreature; SeaCreature = getOneObjectAtOffset(0, 0, SeaCreature.class); if (SeaCreature != null) { World world; world = getWorld(); world.removeObject(SeaCreature); } } }