Hello everyone,
I got a problem. In my game I want it, that my enemy touches the Player.class and get animated... The enemy is moving from the right to the left with a counter and a direction method. Anyways, when I call it, only the negative animation get used like it completely doesnt matter wich direction the enemy is going to, it only animates "attack_l".
Here is the code for the Enemy class:
public class Enemy3 extends Enemy
{
private int speed = 4;
private int direction = 1;
private int frame = 3;
private int animationCounter = 0;
private int count = 0;
private GreenfootImage attack1 = new GreenfootImage("genga1left_s.png");
private GreenfootImage attack2 = new GreenfootImage("genga2left_s.png");
private GreenfootImage attack3 = new GreenfootImage("genga3left_s.png");
private GreenfootImage attack4 = new GreenfootImage("genga4left_s.png");
private GreenfootImage attack1_1 = new GreenfootImage("genga1right_s.png");
private GreenfootImage attack2_1 = new GreenfootImage("genga2right_s.png");
private GreenfootImage attack3_1 = new GreenfootImage("genga3right_s.png");
private GreenfootImage attack4_1 = new GreenfootImage("genga4right_s.png");
/**
* Act - do whatever the Enemy3 wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()
{
setLocation(getX() + speed,getY());
count = (count+1)%120;
if (count == 0) speed = -speed;
{
direction =-1;
}
if(isTouching(Player.class) && direction == -1)
{
if(animationCounter % 6 == 0)
animateattack_l();
}
else if(isTouching(Player.class) && direction == 1)
{
if(animationCounter % 6 == 0)
animateattack_r();
}
animationCounter++;
}
