Esempio n. 1
0
        /// <summary>
        /// Allows the game to run logic such as updating the world,
        /// checking for collisions, gathering input, and playing audio.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Update(GameTime gameTime)
        {
            // if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape))
            //   Exit();

            previousKBState = kbState;
            kbState         = Keyboard.GetState();

            previousMState = mState;
            mState         = Mouse.GetState();

            marioQuad = quadTree.GetContainingQuad(player.O_Position);

            if (!quitActive)
            {
                switch (gameState)
                {
                case GameState.Menu:
                    if (!quitActive)
                    {
                        mainMenu.Update(mState, previousMState, kbState, previousKBState);
                    }
                    break;

                case GameState.World:
                    if (reader.RoomNumber >= 31)
                    {
                        WinGame();
                    }

                    if (SingleKeyPress(Keys.P))     //Swtch to pause menu
                    {
                        PauseGame();
                    }

                    player.Update(gameTime.ElapsedGameTime.TotalSeconds, kbState, previousKBState);

                    for (int i = 0; i < reader.EnemyList.Count; i++)
                    {
                        if (player.O_Position.Intersects(reader.EnemyList[i].O_Position))
                        {
                            Battle(reader.EnemyList[i]);
                            killedEnemy = reader.EnemyList[i];
                        }
                    }

                    //Put in player collision with enemy here
                    //Player Movement
                    if (kbState.IsKeyDown(Keys.Left))
                    {
                        player.O_X -= 5;
                    }
                    else if (kbState.IsKeyDown(Keys.Right))
                    {
                        player.O_X += 5;
                    }

                    if (kbState.IsKeyDown(Keys.Up))
                    {
                        player.O_Y -= 5;
                    }
                    else if (kbState.IsKeyDown(Keys.Down))
                    {
                        player.O_Y += 5;
                    }

                    //Deals with players x directional movement
                    switch (playerXState)
                    {
                    case PlayerXState.StandRight:
                        if (kbState.IsKeyDown(Keys.D))
                        {
                            playerXState     = PlayerXState.WalkRight;
                            player.Direction = CharDirection.right;
                            player.State     = CharacterState.o_walk;
                        }

                        else if (kbState.IsKeyDown(Keys.A))
                        {
                            playerXState     = PlayerXState.WalkLeft;
                            player.Direction = CharDirection.left;
                            player.State     = CharacterState.o_walk;
                        }
                        break;

                    case PlayerXState.WalkRight:
                        player.Move(3);
                        player.UpdateDetectors();

                        if (reader.Right && player.O_X >= GraphicsDevice.Viewport.Width - reader.CurrentRoom.Tile.Width - player.O_Width)
                        {
                            player.O_X = GraphicsDevice.Viewport.Width - reader.CurrentRoom.Tile.Width - player.O_Width;
                        }

                        for (int i = 0; i < reader.RectList.Count; i++)
                        {
                            if (player.Right.Intersects(reader.RectList[i]))
                            {
                                player.O_X = reader.RectList[i].X - player.O_Width - 1;
                                break;
                            }
                        }

                        if (kbState.IsKeyUp(Keys.D))
                        {
                            playerXState         = PlayerXState.StandRight;
                            player.State         = CharacterState.o_idle;
                            player.XAcceleration = 1;
                        }
                        break;

                    case PlayerXState.StandLeft:
                        if (kbState.IsKeyDown(Keys.A))
                        {
                            playerXState     = PlayerXState.WalkLeft;
                            player.Direction = CharDirection.left;
                            player.State     = CharacterState.o_walk;
                        }

                        else if (kbState.IsKeyDown(Keys.D))
                        {
                            playerXState     = PlayerXState.WalkRight;
                            player.Direction = CharDirection.right;
                            player.State     = CharacterState.o_walk;
                        }
                        break;

                    case PlayerXState.WalkLeft:
                        player.Move(-3);
                        player.UpdateDetectors();
                        //player.State = CharacterState.o_walk;

                        if (reader.Left && player.O_X <= reader.CurrentRoom.Tile.Width)
                        {
                            player.O_X = reader.CurrentRoom.Tile.Width;
                        }

                        for (int i = 0; i < reader.RectList.Count; i++)
                        {
                            if (player.Left.Intersects(reader.RectList[i]))
                            {
                                player.O_X = reader.RectList[i].X + player.O_Width + 1;
                                break;
                            }
                        }

                        if (kbState.IsKeyUp(Keys.A))
                        {
                            playerXState         = PlayerXState.StandLeft;
                            player.State         = CharacterState.o_idle;
                            player.XAcceleration = 1;
                        }
                        break;
                    }

                    //Deals with player's y directional movement
                    switch (playerYState)
                    {
                    case PlayerYState.Ground:
                        bool onPlatform = false;

                        for (int i = 0; i < reader.RectList.Count; i++)
                        {
                            if (player.Below.Intersects(reader.RectList[i]) || player.O_LocY >= GraphicsDevice.Viewport.Height - player.O_Height - reader.CurrentRoom.Tile.Height)
                            {
                                onPlatform = true;
                                break;
                            }
                        }

                        for (int i = 0; i < reader.ItemList.Count; i++)
                        {
                            if (player.O_Position.Intersects(reader.ItemList[i].Rect))
                            {
                                reader.ItemList[i].Collect(player);
                            }
                        }

                        if (player.O_LocY >= GraphicsDevice.Viewport.Height - player.O_Height)
                        {
                            onPlatform = true;
                        }

                        if (!onPlatform)
                        {
                            player.JumpAcceleration = -2;
                            playerYState            = PlayerYState.Jump;
                            player.State            = CharacterState.o_jump;
                        }

                        if (kbState.IsKeyDown(Keys.Space))
                        {
                            if (previousKBState.IsKeyUp(Keys.Space))
                            {
                                playerYState = PlayerYState.Jump;
                                player.State = CharacterState.o_jump;
                            }
                        }
                        break;



                    case PlayerYState.Jump:
                        player.Jump();
                        player.UpdateDetectors();

                        for (int i = 0; i < reader.RectList.Count; i++)
                        {
                            if (player.Above.Intersects(reader.RectList[i]))
                            {
                                player.JumpAcceleration = -2;
                                break;
                            }

                            else if (player.O_Position.Intersects(reader.RectList[i]))
                            {
                                player.O_Y = reader.RectList[i].Y - player.O_Height;
                                player.JumpAcceleration = 17;
                                playerYState            = PlayerYState.Ground;

                                if (kbState.IsKeyUp(Keys.A) && kbState.IsKeyUp(Keys.D))
                                {
                                    player.State = CharacterState.o_idle;
                                }

                                else
                                {
                                    if (kbState.IsKeyUp(Keys.A) && kbState.IsKeyDown(Keys.D))
                                    {
                                        player.State = CharacterState.o_walk;
                                        player.Move(5);
                                    }
                                    else if (kbState.IsKeyUp(Keys.D) && kbState.IsKeyDown(Keys.A))
                                    {
                                        player.State = CharacterState.o_walk;
                                        player.Move(-5);
                                    }
                                }

                                break;
                            }
                        }

                        if (reader.Up)
                        {
                            if (player.O_Y <= reader.CurrentRoom.Tile.Height)
                            {
                                player.JumpAcceleration = -2;
                            }
                        }

                        if (reader.Down)
                        {
                            if (player.O_Y >= GraphicsDevice.Viewport.Height - player.O_Height - reader.CurrentRoom.Tile.Height)
                            {
                                player.O_Y   = GraphicsDevice.Viewport.Height - player.O_Height - reader.CurrentRoom.Tile.Height;
                                playerYState = PlayerYState.Ground;
                                // IDLE HERE@@@@@@@@@@@@@@@@@@@
                                player.JumpAcceleration = 17;
                            }
                        }

                        else if (player.O_Y >= GraphicsDevice.Viewport.Height - player.O_Height)
                        {
                            player.O_Y   = GraphicsDevice.Viewport.Height - player.O_Height;
                            playerYState = PlayerYState.Ground;
                            // IDLE HERE@@@@@@@@@@@@@@@@@@@
                            player.JumpAcceleration = 17;
                        }
                        break;
                    }

                    break;


                case GameState.Pause:
                    if (!quitActive)
                    {
                        pauseMenu.Update(mState, previousMState, kbState,
                                         previousKBState);

                        if (SingleKeyPress(Keys.P))
                        {
                            UnpauseGame();
                        }
                    }
                    break;


                case GameState.Battle:
                    if (SingleKeyPress(Keys.P))     //Swtch to pause menu
                    {
                        PauseGame();
                    }

                    BattleManager.Update(gameTime.ElapsedGameTime.TotalSeconds, mState, previousMState, kbState, previousKBState);
                    break;

                case GameState.GameOver:
                    gameOverMenu.Update(mState, previousMState, kbState,
                                        previousKBState);
                    break;

                case GameState.Instructions:
                    instructionsMenu.Update(mState, previousMState, kbState, previousKBState);
                    break;

                case GameState.GameWon:
                    gameWinMenu.Update(mState, previousMState, kbState, previousKBState);
                    break;
                }
            }

            if (quitActive)
            {
                quitMenu.Update(mState, previousMState, kbState, previousKBState);
            }
            if (reader.SwitchRoom(player))
            {
                reader.ReadMap("../../../Content/Rooms/room" + reader.RoomNumber + ".txt", quadTree, collectibleTexture, enemyTexture);
                if (reader.RoomNumber > 10 && reader.RoomNumber < 21)
                {
                    int temp = rand.Next(2);
                    if (temp == 0)
                    {
                        sewerBG.Tex = sewerTexture;
                    }
                    else
                    {
                        sewerBG.Tex = sewerTexture2;
                    }
                }
            }
            base.Update(gameTime);
        }
Esempio n. 2
0
        /// <summary>
        /// Update everything contained within the BattleManager
        /// </summary>
        /// <param name="elapsedTime">The passed time since the last frame in
        /// seconds</param>
        /// <param name="mouse">The current mouse state</param>
        /// <param name="prevMouse">The previous mouse state</param>
        /// <param name="keyState">The current state of the Keyboard</param>
        /// <param name="prevKeyState">The previous state of the Keyboard
        /// </param>
        public static void Update(double elapsedTime, MouseState mouse,
                                  MouseState prevMouse, KeyboardState keyState,
                                  KeyboardState prevKeyState)
        {
            if (!gameOver)
            {
                // Update the total time that has passed
                totalTime += elapsedTime;

                // Once the battle starts, do this stuff
                if (battleStarted)
                {
                    // In between turns/a turn is NOT in progress, pause for a
                    // brief moment before advancing to the next turn
                    if (!turnInProgress)
                    {
                        // If Enemy
                        if (roster[currentTurn] is Enemy)
                        {
                            SelectRandomFriendly();
                        }

                        // If Friendly
                        else if (roster[currentTurn] is IFriendly)
                        {
                            enemySelectMenu.Update(mouse, prevMouse, keyState,
                                                   prevKeyState);
                        }
                    }

                    // While a turn is in progres, update the attack logistics
                    else
                    {
                        roster[currentTurn].QuickTimeAction.Update(elapsedTime, keyState, prevKeyState);
                        //if (!roster[currentTurn].QuickTimeAction.WindowOpen)
                        //{

                        //}@@@@@@@@@@@@@@@@@@@@@@@@@@WHAT Was I doing here? Was I maybe cancelling the event? We may never know. happy May twelfth: may the force be with you

                        UpdateAttack(elapsedTime);

                        if (attackExecuted)
                        {
                            if (totalTime > timeCounter &&
                                roster[targetIndex].Health > 0 &&
                                roster[targetIndex].Color != Color.White)
                            {
                                roster[targetIndex].Color = Color.White;
                                roster[targetIndex].HealthBar.CurrentColor
                                    = Color.LawnGreen;
                            }

                            else if (roster[targetIndex].Health == 0)
                            {
                                roster[targetIndex].Color = new Color(
                                    roster[targetIndex].Color.R - 1,
                                    roster[targetIndex].Color.G - 1,
                                    roster[targetIndex].Color.B - 1,
                                    roster[targetIndex].Color.A - 1);

                                roster[targetIndex].HealthBar.BaseColor = new Color(
                                    roster[targetIndex].HealthBar.BaseColor.R - 1,
                                    roster[targetIndex].HealthBar.BaseColor.G - 1,
                                    roster[targetIndex].HealthBar.BaseColor.B - 1,
                                    roster[targetIndex].HealthBar.BaseColor.A - 1);

                                roster[targetIndex].HealthBar.TextColor = new Color(
                                    roster[targetIndex].HealthBar.TextColor.R - 1,
                                    roster[targetIndex].HealthBar.TextColor.G - 1,
                                    roster[targetIndex].HealthBar.TextColor.B - 1,
                                    roster[targetIndex].HealthBar.TextColor.A - 1);
                            }
                        }
                    }

                    // If it's not the enemy's turn, update the menu select
                    // buttons to check to see if they've been activated.
                    if (!turnInProgress && roster[currentTurn] is IFriendly)
                    {
                        enemySelectMenu.Update(mouse, prevMouse, keyState,
                                               prevKeyState);
                    }

                    // Update all the Characters in the Battle
                    for (int i = 0; i < roster.Count; i++)
                    {
                        roster[i].Update(elapsedTime, keyState, prevKeyState);
                    }
                }

                // The pre-battle time buffer before the battle starts
                else
                {
                    if (totalTime > pauseCounter)
                    {
                        battleStarted = true;

                        if (roster[currentTurn] is IFriendly)
                        {
                            ActivateAllButtons();
                        }
                    }
                }
            }

            // End the battle when gameOver is true
            else
            {
                if (battleWon)
                {
                    battleWinFunction();
                }
                else
                {
                    gameOverFunction();
                }
            }
        }