public bool CanMoveInDirection(PacManDirection direction) { bool result = true; PacManDirection currentDirection = direction; for (int r = 0; r < GameEngine.backLayer.Rows; r++) { for (int c = 0; c < GameEngine.backLayer.Columns; c++) { if (GameEngine.backLayer.TileObject[c, r] == null) { continue; } if (GameEngine.backLayer.TileObject[c, r].IsWall == true) { Sprite wall = GameEngine.backLayer.TileObject[c, r].Sprite; switch (currentDirection) { case PacManDirection.Up: result = !wall.IsCollidingWithRectangleBased(DetectU); break; case PacManDirection.Down: result = !wall.IsCollidingWithRectangleBased(DetectD); break; case PacManDirection.Left: result = !wall.IsCollidingWithRectangleBased(DetectL); break; case PacManDirection.Right: result = !wall.IsCollidingWithRectangleBased(DetectR); break; } if (result == false) { break; } } //if } //for if (result == false) { break; } }//for return(result); }
public bool Move() { bool result = false; //if can move in next direction if (CanMoveInDirection(pacManNextDirection) == true) { pacManDirection = pacManNextDirection; //set current direction } if (CanMoveInDirection(pacManDirection) == false) { return(false); } bool isEating = this.IsEating(); //set location and bitmap int x = base.Location.X; int y = base.Location.Y; switch (pacManDirection) { case PacManDirection.Up: y -= pacManSpeed; if (isEating) { base.CurrentFrame = FrameEatU; } else { base.CurrentFrame = FrameU; } break; case PacManDirection.Down: y += pacManSpeed; if (isEating) { base.CurrentFrame = FrameEatD; } else { base.CurrentFrame = FrameD; } break; case PacManDirection.Left: x -= pacManSpeed; if (isEating) { base.CurrentFrame = FrameEatL; } else { base.CurrentFrame = FrameL; } break; case PacManDirection.Right: x += pacManSpeed; if (isEating) { base.CurrentFrame = FrameEatR; } else { base.CurrentFrame = FrameR; } break; case PacManDirection.None: break; } base.Location = new Point(x, y); SetProximityDetectionRectangles(); //set detection rectangles location return(result); }