I know this has been discussed alot but can't find what I'm looking for. How can I make a Top Down Wall that can't be passed from either top down left right? Thanks in advance. Xd
// the code where you move
if (Greenfoot.isKeyDown("left")) {
Actor a = getOneObjectAtOffset(-1,0,Wall.class); // get an object of the class Wall, at 1 cell to the left and 0 cells up or down
if (a == null) { // no wall
// move the player
}
}
// the same for other directionspublic void move()
{
int dx = 0, dy = 0;
if (Greenfoot.isKeyDown("up")) dy--;
if (Greenfoot.isKeyDown("down")) dy++;
if (Greenfoot.isKeyDown("left")) dx--;
if (Greenfoot.isKeyDown("right")) dx++;
// do nothing if conflicting,invalid or no input given
if (dx*dy != 0 || dx+dy == 0) return;
// attempt move
setLocation(getX()+dx, getY()+dy);
// if intersecting wall, move back
if (getOneIntersectingObject(Wall.class) != null) setLocation(getX()-dx, getY()-dy);
}