Hello all,
I would like to make my character show a certain image (call it Random.png for now) when she hits an enemy.
When she doesn't hit an enemy she shows the normal image. How do I implement that
this is what I have:
public class Alice extends Mover
{
public void act()
{
checkKeys();
checkCollisionEnemy();
}
private void checkKeys()
{
if (Greenfoot.isKeyDown("left") )
{
setImage("AliceLeft.png");
moveLeft();
}
if (Greenfoot.isKeyDown("right") )
{
setImage("AliceRight.png");
moveRight();
}
}
public void checkCollisionEnemy()
{
Actor enemy = getOneObjectAtOffset(0, getImage().getHeight()/2+5, Walker.class);
if (enemy != null) getWorld().removeObject(enemy);
Actor collided = getOneIntersectingObject(Enemy.class);
if (collided !=null && contactTimer ==0)
{
((Score)getWorld().getObjects(Score.class).get(0)).add(-1);
contactTimer = 100;
}
}
public void runCollisionTimer()
{
if (contactTimer > 0) contactTimer --;
}
}

