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
![Twitter](/assets/twitter-4e19209ef84344ee0c433f4c7bad8d49.png)
![Twitter.hover](/assets/twitter.hover-1fb19a5bafc50deace8f88eaec867845.png)
// 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 directions
public 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); }