示例#1
0
 //Used to initialize the program
 public void Start()
 {
     UpdateStates.TimerMaze.reset();
     pacman = new Pacman(new Rectangle(0, 0, gridSize, gridSize));
     pacman.PlayerCaught = Player.Left;
     Map.InitializeMap();
 }
示例#2
0
        public static void UpdateMaze(GameTime gameTime)
        {
            if (Maze)
            {
                if (PacmanGame.mapNumber == 0)
                {
                    Program.game.Start();
                }
                else
                {
                    UpdateStates.TimerMaze.reset();
                    PacmanGame.pacman = new Pacman(new Rectangle(0, 0, PacmanGame.gridSize, PacmanGame.gridSize));
                    PacmanGame.pacman.PlayerCaught = Player.Left;
                    Map.InitializeMap();
                }
                MediaPlayer.Stop();
                MediaPlayer.Play(PacmanGame.GameSong);
                Maze = false;
            }

            timerGhost.tick(gameTime);
            if (timerGhost.TimeMilliseconds >= timerGhost.Interval && Map.Ghosts.Count < 4)
            {
                Map.Ghosts.Add(new Ghost());
                timerGhost.reset();
            }
            timerGame.tick(gameTime);

            if (timerGame.TimeMilliseconds >= timerGame.Interval)
            {
                PacmanGame.gameState = GameState.LevelEnd;
                MediaPlayer.Stop();
                PacmanGame.GameEndSound.Play();
                if (Map.Paddles[0].Score > Map.Paddles[1].Score)
                {
                    Pacman.speed += 4 + PacmanGame.mapNumber;
                    Paddle.speed += 4 + PacmanGame.mapNumber;
                    PacmanGame.mapNumber++;
                    Map.Paddles[0].totalScore += Map.Paddles[0].Score;
                    if (PacmanGame.mapNumber > 3)
                    {
                        PacmanGame.gameState = GameState.GameEnd;
                    }
                }
                else if (Map.Paddles[1].Score > Map.Paddles[0].Score)
                {
                    PacmanGame.pacmanLives--;
                    if (PacmanGame.pacmanLives == 0)
                    {
                        PacmanGame.gameState = GameState.GameEnd;
                    }
                }
            }

            foreach (Keys key in PacmanGame.keyboard.GetPressedKeys())
            {
                Direction d;
                if (Map.Paddles[0].DirectionByKey.TryGetValue(key, out d))
                {
                    Map.Paddles[0].Move(d);
                    if (PacmanGame.pacman.currentControl == Map.Paddles[0].Player)
                    {
                        PacmanGame.pacman.changeDirection(d);
                    }
                }
            }
            Map.Paddles[1].MoveAI();
            if (PacmanGame.pacman.currentControl == Map.Paddles[1].Player)
            {
                PacmanGame.pacman.changeDirection((Direction)(new Random().Next(Enum.GetNames(typeof(Direction)).Length)));
            }
            foreach (Paddle paddle in Map.Paddles)
            {
                paddle.CatchPacman();
            }

            foreach (Invader invader in Map.Invaders)
            {
                invader.Update();
            }

            foreach (Shot shot in Map.Shots)
            {
                shot.Update();
            }

            if (PacmanGame.pacman.PlayerCaught != null)
            {
                timerCatch.tick(gameTime);
            }

            PacmanGame.pacman.oldMovementDirection = PacmanGame.pacman.movementDirection;
            if (PacmanGame.keyboard.IsKeyDown(Keys.Escape))
            {
                Program.game.Exit();
            }

            if (timerCatch.TimeMilliseconds >= timerCatch.Interval)
            {
                PacmanGame.pacman.PlayerCaught = null;
                if (PacmanGame.pacman.PlayerCaught == Player.Left)
                {
                    PacmanGame.pacman.changeDirection(Direction.Right);
                }
                else if (PacmanGame.pacman.PlayerCaught == Player.Right)
                {
                    PacmanGame.pacman.changeDirection(Direction.Left);
                }
                timerCatch.reset();
            }
            PacmanGame.pacman.update();
            if (!PacmanGame.pacman.IsPowerUp)
            {
                PacmanGame.pacman.checkIntersectionGhost();
            }
            else
            {
                PacmanGame.pacman.checkIntersectionGhostPowerup();
            }
            if (PacmanGame.pacman.IsPowerUp)
            {
                timerPowerup.tick(gameTime);
                if (timerPowerup.TimeMilliseconds >= timerPowerup.Interval)
                {
                    timerPowerup.reset();
                    PacmanGame.pacman.IsPowerUp = false;
                    PacmanGame.PowerDownSound.Play();
                }
            }

            if (!PacmanGame.pacman.IsPowerUp)
            {
                foreach (Ghost ghost in Map.Ghosts)
                {
                    ghost.move();
                }
            }
            else
            {
                foreach (Ghost ghost in Map.Ghosts)
                {
                    ghost.moveOpposite();
                }
            }
            foreach (Invader invader in Map.Invaders)
            {
                invader.move();
            }
        }