I'm trying to move my actor one space up, then back down, then down again and finally up and then continue (Y-1,Y+1,Y+1,Y-1). I have the following code atm but it doesn't work any help would be grateful.
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
import java.util.List;
/**
* Write a description of class Mummie1 here.
*
* @author ()
* @version (a version number or a date)
*/
public class Mummie1 extends Actor
{
int startX;
int startY;
boolean goingup=true;
public Mummie1(int X, int Y)
{
setLocation(X,Y);
startX = X;
startY = Y;
}
public void act()
{
int currX=getX();
int currY=getY();
if(currY==startY)
{
if (goingup==false)
{
setLocation(startY+1,currX);
goingup=true;
}
else
{
setLocation(startY-1,currX);
goingup=false;
}
}
//else if (currY==startY+1)
else
setLocation(startY, currX);
//else if (currY==startY-1)
// setLocation(startY,currX);
FindCharacter();
}
private void FindCharacter()//Finds Character
{
Actor thisCharacter = getOneObjectAtOffset (0,0, Character.class);//Checks if characters is in that cell
if(thisCharacter!=null)
getWorld().removeObject(thisCharacter);//Removes the Character
List allCharacter = getWorld().getObjects(Character.class);//Find Character in the world
if (allCharacter.isEmpty())//Checks if Character have gone
Greenfoot.stop();
}
}


