I am attempting to have multiple animation commands on a single actor all on different keystrokes such as a walk forward animation, A walk back animation, and an attack animation. However I can only get a single one to work at a time when I need all 3 working at once. Any ideas on how to fix this?
public class Johnny extends Actor
{
private GreenfootImage image1;
private GreenfootImage image2;
private GreenfootImage image3;
private GreenfootImage image4;
public static int score = 50;
private boolean flag = false;
private int waitCycle;
/**
* Act - do whatever the Johnny wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()
{
move();
animate();
checkforSol();
}
public Johnny()
{
image1 = new GreenfootImage("Johnny3.png");
image2 = new GreenfootImage("JohnnyWalk.png");
image3 = new GreenfootImage("Jattack.png");
image4 = new GreenfootImage("Johnnywalkback.png");
}
public void move()
{
if (Greenfoot.isKeyDown("left"))
{
setLocation(getX()-2,getY());
}
if (Greenfoot.isKeyDown("right"))
{
setLocation(getX()+2,getY());
}
}
public void checkforSol()
{
Sol theSol = null;
theSol = (Sol)getOneIntersectingObject(Sol.class);
if(theSol != null)
{
if (flag == false)
{
Sol.score--;
flag = true;
}
else if (Greenfoot.isKeyDown("a"))
{
Johnny.score++;
flag = true;
}
}
}
public void animate()
{
if (Greenfoot.isKeyDown("left"))
{
setImage(image2);
}
else
{
setImage(image1);
}
if (Greenfoot.isKeyDown("right"))
{
setImage(image4);
}
else
{
setImage(image1);
}
if (Greenfoot.isKeyDown("a"))
{
setImage(image3);
}
else
{
setImage(image1);
}
}
}
