I want a code where if my player jumps on top of the enemies he is removed.
Actor enemy = getOneIntersectingObject(Enemy.class); if (getX() > enemy.getX()-enemy.getImage().getWidth()/2 && getX() < enemy.getX()+enemy.getImage().getWidth()/2 && getY() < enemy.getY()) getWorld().removeObject(this);
Actor enemy = getOneIntersectingObject(Enemy.class); if (getX() > enemy.getX()-enemy.getImage().getWidth()/2 && getX() < enemy.getX()+enemy.getImage().getWidth()/2 && getY() < enemy.getY()) getWorld().removeObject(this);
// add instance int field private int stunTimer = 0; // start your act method with public void act() { if (stunTimer > 0) // if frozen { stunTimer--; if (stunTimer > 0) return; // if timer not done, exit method setImage("up.png"); // restore normal image } // rest of act method } // when enemy hit, do the following setImage("down.png"); stunTimer = 900;
// add instance int field private int stunTimer = 0; // start your act method with public void act() { if (stunTimer > 0) // if frozen { stunTimer--; if (stunTimer > 0) return; // if timer not done, exit method setImage("up.png"); // restore normal image } // rest of act method } // when enemy hit, do the following setImage("down.png"); stunTimer = 900;
public void setStunned() { setImage("down.png"); stunTimer = 900; }
Enemy enemy = (Enemy) getOneIntersectingObject(Enemy.class); if (enemy != null && getX() > enemy.getX()-enemy.getImage().getWidth()/2 && getX() < enemy.getX()+enemy.getImage().getWidth()/2 && getY() < enemy.getY()) enemy.setStunned();
public void setStunned() { setImage("down.png"); stunTimer = 900; }
Enemy enemy = (Enemy) getOneIntersectingObject(Enemy.class); if (enemy != null && getX() > enemy.getX()-enemy.getImage().getWidth()/2 && getX() < enemy.getX()+enemy.getImage().getWidth()/2 && getY() < enemy.getY()) enemy.setStunned();