public override bool AllowMovingThrough(GameThing other, int intoDirection) { int x = GetX(); int y = GetY(); int dx = DirectionDX(intoDirection); int dy = DirectionDY(intoDirection); GameThing inTheWay = GameController.game.GetThingAt(x + dx, y + dy); return(inTheWay.AllowMovingThrough(this, intoDirection)); }
bool TryToWalk() { if (!KeyPressed(RIGHT) && !KeyPressed(LEFT)) { return(false); } if (KeyPressed(RIGHT) && KeyPressed(LEFT)) { return(false); } int direction; int dx; if (KeyPressed(RIGHT)) { direction = RIGHT; dx = 1; } else { direction = LEFT; dx = -1; } FaceDirection(direction); int x = GetX(); int y = GetY(); GameThing inTheWay = GameController.game.GetThingAt(x + dx, y); if (!inTheWay.AllowMovingThrough(this, direction)) { return(false); } // Push if it's a block inTheWay.MovingIn(this, direction); ActuallyMove(x + dx, y); lastMoved = Time.timeSinceLevelLoad; return(true); }
bool TryToJump() { if (!KeyPressed(UP) || KeyPressed(DOWN)) { return(false); } int x = GetX(); int y = GetY(); GameThing inTheWay = GameController.game.GetThingAt(x, y + 1); if (!inTheWay.AllowMovingThrough(this, UP)) { return(false); } // Push if it's a rock inTheWay.MovingIn(this, UP); ActuallyMove(x, y + 1); lastJumped = Time.timeSinceLevelLoad; return(true); }