I am working on a game, but one of my actors is not moving. In the code I have a timer, that is supposed to show the actor when to move. When the timer finishes, the actor should get a random number between 0 and 50, make an int with it plus his original coordinate and compare it with an int that shows the x coordinate he has at the moment.
If the x coordinate he has is smaller or the same as the original coordinate plus the random number he should move.
import greenfoot.*;
public class Cal1 extends Actor
{
int movetimer = 400;
public void act()
{
movehorse();
}
public void movehorse()
{
movetimer--;
if (movetimer == 0)
{
int d1 = Greenfoot.getRandomNumber(50);
if (d1 == 0) d1 = Greenfoot.getRandomNumber(50);
int x = getX();
int xw = 64 + d1;
if (x <= xw) move(5);
}
}
}
