basically if my character turns his back against a wall it just makes him walk out of the world unless i click another movement key which stops but i cannot figure out how to make him stop moving back if his back is against the wall. please help
import greenfoot.*;
public class Zee extends Actor {
private int timer;
public static boolean stabbing = false;
public boolean d = true;
boolean death = false;
//Level Progresser
private Door door;
public Zee(Door door) {
this.door = door;
}
//Character
public Zee() {
GreenfootImage image = getImage();
image.scale(80, 80);
}
public void act() {
//Controls
if (Greenfoot.isKeyDown("left") || (Greenfoot.isKeyDown("a"))){
setRotation(180);
move(3);
} else if (Greenfoot.isKeyDown("up") || (Greenfoot.isKeyDown("w"))){
setRotation(-90);
move(3);
} else if (Greenfoot.isKeyDown("right") || (Greenfoot.isKeyDown("d"))){
setRotation(360);
move(3);
} else if (Greenfoot.isKeyDown("down") || (Greenfoot.isKeyDown("s"))) {
setRotation(90);
move(3);
}
//Stabing
if (Greenfoot.isKeyDown("e") || (Greenfoot.isKeyDown("shift"))){
setImage("zeestab4.png");
stabbing = true;
timer = 6;
}
if (timer > 0 && --timer == 0) setImage("newzee.png");
//Restrictions and More
if (isTouching(Wall.class)) {
move(-3);
}
if (isTouching(Coins.class)) {
removeTouching(Coins.class);
int score = 1;
}
if (isTouching(Emerald.class)) {
removeTouching(Emerald.class);
getWorld().removeObject(this.door);
}
if (isTouching (Door.class)) {
getWorld().removeObject(getOneIntersectingObject(Zee.class));
death = true;
}
}
//Stabbing Animation
public void Stab() {
GreenfootImage zeestab2 = getImage();
zeestab2.scale(80, 80);
}
}
