Exemplo n.º 1
0
 /// <summary>
 /// Checks to see if the game is paused.
 /// </summary>
 private void CheckPaused()
 {
     if (!isDeathScreenUp)
     {
         if (GameResources.CheckInputButton(Keys.Escape, Buttons.Start, oldKeyState, newKeyState, oldGamePadState, newGamePadState))
         {
             if (isPaused)
             {
                 isPaused = false;
                 isFrozen = false;
                 pauseMenu.Dispose();
                 pauseMenu = null;
             }
             else
             {
                 isFrozen = true;
                 isPaused = true;
                 pauseMenu = new PauseMenu(MenuCallback, gameSettings);
             }
         }
     }
 }
Exemplo n.º 2
0
        /// <summary>
        /// Calls the Update method on all content managed by the GameManager.
        /// </summary>
        /// <param name="gameTime">The GameTime to use when calculating change over time.</param>
        public void Update(GameTime gameTime)
        {
            newKeyState = Keyboard.GetState();
            newGamePadState = GamePad.GetState(PlayerIndex.One);

            if (inGame)
            {
                CheckPaused();
                if (isPaused)
                {
                    if (pauseMenu != null)
                    {
                        pauseMenu.Update(gameTime);
                        if (!pauseMenu.IsPaused)
                        {
                            isPaused = false;
                            isFrozen = false;
                            pauseMenu.Dispose();
                            pauseMenu = null;
                        }
                    }
                }
                else
                {
                    if (!isFrozen)
                    {
                        if (player.DeathSequenceEnded)
                        {
                            ShowDeathScreen();
                            StaticBGM.SwitchMusic("Death");
                        }
                        else if (player.IsDead)
                        {
                            StaticBGM.Paused = true;
                            player.StartDeathSequence();
                        }
                        if (player.Position.Y >= currentRoom.CollisionMap.Height + player.HitBox.Height)
                        {
                            currentRoom.Reset();
                            player.ReceivePitFallDamage();
                            player.Position = currentRoom.SpawnLocation;
                        }
                        else if (player.CheckHazards(currentRoom))
                        {
                            currentRoom.Reset();
                            player.ReceiveHazardDamage();
                            player.Position = currentRoom.SpawnLocation;
                        }
                        else
                        {
                            if (player.IsVulnerable)
                                player.DetectEnemyCollisions(currentRoom);
                        }

                        for (int i = 0; i < currentRoom.ObjectArray.Length; i++)
                        {
                            if (currentRoom.ObjectArray[i].IsPhysicsObject && currentRoom.ObjectArray[i].IsSpawned &&
                                currentRoom.ObjectArray[i].Position.Y > currentRoom.CollisionMap.Height)
                                currentRoom.ObjectArray[i].Despawn();
                        }

                        foreach (GameObject obj in currentRoom.EnvironmentArray)
                        {
                            if(obj.IsPhysicsObject && ((PhysicsObject)obj).riding == null)
                                obj.Update(gameTime);
                        }

                        foreach (GameObject obj in currentRoom.EnvironmentArray)
                        {
                            if (!obj.IsPhysicsObject || (obj.IsPhysicsObject && ((PhysicsObject)obj).riding != null))
                                obj.Update(gameTime);
                        }

                        foreach (Enemy enemy in currentRoom.EnemyArray)
                                enemy.Update(gameTime, player);

                        player.Update(gameTime);

                        for (int i = 0; i < currentRoom.ObjectArray.Length; i++)
                        {
                            if (currentRoom.ObjectArray[i].IsPhysicsObject)
                            {
                                PhysicsEngine.Update((PhysicsObject)currentRoom.ObjectArray[i], currentRoom, gameTime);
                            }
                        }
                        PhysicsEngine.Update(player, currentRoom, gameTime); //Checks for collisions and modifies Velocity

                        for (int i = 0; i < currentRoom.ObjectArray.Length; i++)
                        {
                            if (currentRoom.ObjectArray[i].IsPhysicsObject)
                            {
                                ((PhysicsObject)currentRoom.ObjectArray[i]).Move();
                            }
                        }
                        player.Move(); //Actually sets the new position of the object

                        //Finally, update the drawing position of the objects in the room.
                        player.UpdateCoordinates(currentRoom.CollisionMap.Bounds);

                        currentRoom.UpdateCoordinates(player.Position, player.Coordinates, currentRoom.CollisionMap.Bounds);
                        player.updateControlFlags(); //new

                        //Check to see if the player is trying to do something
                        if (player.InteractionFlag)
                        {
                            GameObject tempObject = FindInteractionObject(player, InteractionTypes.PlayerAction);
                            if (tempObject != null)
                            {
                                InteractionActions interaction = player.InteractWith(tempObject, InteractionTypes.PlayerAction);
                                if (interaction != InteractionActions.None)
                                    currentRoom.PlayerInteraction(interaction);
                            }
                        }

                        for (int i = 0; i < currentRoom.ObjectArray.Length; i++)
                        {
                            if (currentRoom.ObjectArray[i].IsSpawned)
                            {
                                if (PhysicsEngine.CheckBoundingBoxCollision(player, currentRoom.ObjectArray[i]))
                                    player.InteractWith(currentRoom.ObjectArray[i], InteractionTypes.Collision);
                            }
                        }
                    }
                    else
                    {
                        if (player.CheckLoadedRoom())
                            InfoBoxCallback();

                        if (isDeathScreenUp && GameResources.CheckInputButton(Keys.Enter, Buttons.Start, oldKeyState, newKeyState, oldGamePadState, newGamePadState))
                        {
                            ResetGame();
                            LoadGame();
                        }

                        if (infoBox != null)
                            infoBox.Update(gameTime);
                    }

                    gameHUD.Update(gameTime, player);
                }
            }
            else
            {
                if (gameMenu != null)
                    gameMenu.Update(gameTime);
            }

            oldKeyState = newKeyState;
            oldGamePadState = newGamePadState; //add statement referencing isdead from the player class to call the deathmusic.
        }