private void UpdatePacman(Pacman pacman, Map map)
 {
     this.keyboard = Keyboard.GetState();
     if (pacman.Direction == DIRECTION.UP || pacman.Direction == DIRECTION.DOWN || pacman.Direction == DIRECTION.NONE)
     {
         if (keyboard.IsKeyDown(Keys.Up) || keyboard.IsKeyDown(Keys.Down))
         {
             pacman.Direction = (keyboard.IsKeyDown(Keys.Up) ? DIRECTION.UP : DIRECTION.DOWN);
             if (!Game.IN_GAME)
                 Game.IN_GAME = true;
         }
         else if (keyboard.IsKeyDown(Keys.Right) || keyboard.IsKeyDown(Keys.Left))
         {
             if (pacman.GetCaseYSup(map.Tile_size) != -1 || pacman.GetCaseYInf(map.Tile_size) != -1)
             {
                 pacman.Direction = (keyboard.IsKeyDown(Keys.Right) ? DIRECTION.RIGHT : DIRECTION.LEFT);
                 if (!Game.IN_GAME)
                     Game.IN_GAME = true;
             }
         }
     }
     if (pacman.Direction == DIRECTION.RIGHT || pacman.Direction == DIRECTION.LEFT || pacman.Direction == DIRECTION.NONE)
     {
         if (keyboard.IsKeyDown(Keys.Right) || keyboard.IsKeyDown(Keys.Left))
         {
             pacman.Direction = (keyboard.IsKeyDown(Keys.Right) ? DIRECTION.RIGHT : DIRECTION.LEFT);
             if (!Game.IN_GAME)
                 Game.IN_GAME = true;
         }
         else if (keyboard.IsKeyDown(Keys.Up) || keyboard.IsKeyDown(Keys.Down))
         {
             if (pacman.GetCaseXSup(map.Tile_size) != -1 || pacman.GetCaseXInf(map.Tile_size) != -1)
             {
                 pacman.Direction = (keyboard.IsKeyDown(Keys.Up) ? DIRECTION.UP : DIRECTION.DOWN);
                 if (!Game.IN_GAME)
                     Game.IN_GAME = true;
             }
         }
     }
 }
Example #2
0
 public Collision(Pacman pacman, Map map)
 {
     this.map = map;
 }
Example #3
0
 public Game()
 {
     graphics = new GraphicsDeviceManager(this);
     graphics.PreferredBackBufferWidth = 34*20;
     graphics.PreferredBackBufferHeight = 31*20;
     graphics.ApplyChanges();
     Content.RootDirectory = "Content";
     this.map = new Map(28, 31, new byte[,]{
         {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
         {0, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 3, 0},
         {0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0},
         {0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0},
         {0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0},
         {0, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1, 1, 0},
         {0, 1, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 1, 0},
         {0, 1, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 1, 0},
         {0, 1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1, 1, 1, 0},
         {0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0},
         {0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0},
         {0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0},
         {0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 4, 4, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0},
         {0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 4, 4, 4, 4, 4, 4, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0},
         {0, 2, 1, 1, 1, 1, 1, 1, 1, 1, 0, 4, 4, 4, 4, 4, 4, 0, 1, 1, 1, 1, 1, 1, 1, 1, 2, 0},
         {0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 4, 4, 4, 4, 4, 4, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0},
         {0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0},
         {0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0},
         {0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0},
         {0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0},
         {0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0},
         {0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0},
         {0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0},
         {0, 1, 1, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 1, 0},
         {0, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 0},
         {0, 0, 0, 2, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 2, 0, 0, 0},
         {0, 1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1, 1, 1, 0},
         {0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0},
         {0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0},
         {0, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 3, 0},
         {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
     });
     this.collision = new Collision(this.pacman, map);
     this.movementController = new MovementController();
     GHOSTS = new List<Ghost>();
 }
 public void Update(Pacman pacman, Map map)
 {
     this.UpdatePacman(pacman, map);
     this.UpdateGhosts();
 }