I would like to make a "guard" that turn around my hero but I'm having some issues.
For now I have this code:
I wanted to make him follow the hero and then add the "turning around" effect but like that I have 2 problems:
- as soon as I hit an edge of the world the distance between guard-hero is altered.
- it doesn't "turn" around my actor properly
How can I fix that or do that?
public void act() { moveAroundHero(); checkKey(); } public void moveAroundHero() { PlayUniverse playUniverse = (PlayUniverse)getWorld(); Hero player = playUniverse.getplayer(); if (player.getY() < getY() && player.getX() < getX())setLocation(getX()+3, getY()-3); if (player.getY() >= getY() && player.getX() < getX())setLocation(getX()-3, getY()-3); if (player.getY() >= getY() && player.getX() >= getX())setLocation(getX()-3, getY()+3); if (player.getY() <= getY() && player.getX() >= getX())setLocation(getX()+3, getY()+3); } public void checkKey() { if (Greenfoot.isKeyDown("right")) { move(5); } if (Greenfoot.isKeyDown("left")) { move(-5); } if (Greenfoot.isKeyDown("up")) { setLocation(getX(), getY() - 5); } if (Greenfoot.isKeyDown("down")) { setLocation(getX(), getY() + 5); } }