Example #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)
        {
            switch (gs)
            {
            case GameState.mainMenu:


                MenuControls.update(gameTime);


                if (MenuControls.getExit())
                {
                    gameExit();
                }
                if (MenuControls.getSelect())
                {
                    switch (mainMenu.getIndex())
                    {
                    case 0:
                        newGame();
                        break;

                    case 1:
                        gs = GameState.leaderboard;
                        break;

                    case 2:
                        gameExit();
                        break;
                    }
                }
                if (MenuControls.getNextKey())
                {
                    mainMenu.nextOption();
                }
                if (MenuControls.getPrevKey())
                {
                    mainMenu.previousOption();
                }


                break;

            case GameState.leaderboard:

                MenuControls.update(gameTime);

                if (MenuControls.getExit())
                {
                    gs = GameState.mainMenu;
                    updateScoreMenu = false;
                }
                if (MenuControls.getSelect())
                {
                    gs = GameState.mainMenu;
                    updateScoreMenu = false;
                }

                if (!updateScoreMenu)
                {
                    updateScoreMenu = true;
                }

                break;

            case GameState.running:

                if (updateScoreMenu)
                {
                    updateScoreMenu = false;
                }
                PlayControls.update(gameTime);

                //Poll inputs

                if (PlayControls.getPause())
                {
                    gs = GameState.paused;
                }

                Vector2 playerMovement = new Vector2(0, 0);
                if (PlayControls.getMoveDown())
                {
                    playerMovement.Y        += currMap.player.movementSpeed;
                    currMap.player.direction = CollisionHandler.Direction.South;
                }
                if (PlayControls.getMoveUp())
                {
                    playerMovement.Y        -= currMap.player.movementSpeed;
                    currMap.player.direction = CollisionHandler.Direction.North;
                }
                if (PlayControls.getMoveRight())
                {
                    playerMovement.X        += currMap.player.movementSpeed;
                    currMap.player.direction = CollisionHandler.Direction.East;
                }
                if (PlayControls.getMoveLeft())
                {
                    playerMovement.X        -= currMap.player.movementSpeed;
                    currMap.player.direction = CollisionHandler.Direction.West;
                }
                if (PlayControls.getShootKey())
                {
                    currMap.player._mainweapon.IsUsing = true;
                }
                else
                {
                    currMap.player._mainweapon.IsUsing = false;
                }
                if (playerMovement.X != 0 || playerMovement.Y != 0)
                {
                    currMap.player.move(playerMovement * (float)gameTime.ElapsedGameTime.TotalSeconds);
                }


                //End inputs

                EventHandler.handle(gameTime);
                currMap.update(gameTime);

                break;

            case GameState.paused:


                MenuControls.update(gameTime);

                //Poll inputs

                if (MenuControls.getNextKey())
                {
                    pauseMenu.nextOption();
                }
                if (MenuControls.getPrevKey())
                {
                    pauseMenu.previousOption();
                }
                if (MenuControls.getSelect())
                {
                    switch (pauseMenu.getIndex())
                    {
                    case 0:
                        gs = GameState.running;
                        break;

                    case 1:
                        updateScore(currMap.hud.Score);
                        gs = GameState.mainMenu;
                        break;
                    }
                }

                if (MenuControls.getExit())
                {
                    gs = GameState.running;
                }
                //End inputs
                break;

            case GameState.shop:
                MenuControls.update(gameTime);

                //Poll inputs

                if (MenuControls.getNextKey())
                {
                    shopMenu.nextOption();
                }
                if (MenuControls.getPrevKey())
                {
                    shopMenu.previousOption();
                }
                if (MenuControls.getSelect())
                {
                    switch (shopMenu.getIndex())
                    {
                    case 0:
                        if (currMap.hud.Currency >= 10)
                        {
                            currMap.player._mainweapon._Damage += 5;
                            currMap.hud.Currency -= 10;
                        }
                        break;

                    case 1:
                        if (currMap.hud.Currency >= 10)
                        {
                            currMap.player.increaseMax(5);
                            currMap.hud.Currency -= 10;
                        }
                        break;

                    case 2:
                        gs = GameState.running;
                        break;
                    }
                }
                if (MenuControls.getExit())
                {
                    gs = GameState.running;
                }
                //End inputs

                currMap.hud.update(gameTime);

                break;

            case GameState.death:
                MenuControls.update(gameTime);

                if (!updateScoreMenu)
                {
                    updateScore(currMap.hud.Score);
                    updateScoreMenu = true;
                }
                deathMenuScore.setText("Your Score: " + currMap.hud.Score);

                //Poll inputs

                if (MenuControls.getNextKey())
                {
                    deathMenu.nextOption();
                }
                if (MenuControls.getPrevKey())
                {
                    deathMenu.previousOption();
                }
                if (MenuControls.getSelect())
                {
                    switch (deathMenu.getIndex())
                    {
                    case 0:
                        gs = GameState.mainMenu;
                        break;

                    case 1:
                        gameExit();
                        break;
                    }
                }
                if (MenuControls.getExit())
                {
                    gs = GameState.mainMenu;
                }
                break;

            default: break;
            }

            base.Update(gameTime);
        }
Example #2
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)
        {
            switch (gs)
            {
            case GameState.mainMenu:


                MenuControls.update(gameTime);

                //Poll inputs



                //currentTime += gameTime.ElapsedGameTime.Milliseconds;
                //if(currentTime >= goalTime) {

                if (MenuControls.getExit())
                {
                    Exit();
                }
                if (MenuControls.getSelect())
                {
                    newGame();
                }
                if (MenuControls.getNextKey())
                {
                    mainMenu.nextOption();
                }
                if (MenuControls.getPrevKey())
                {
                    mainMenu.previousOption();
                }

                //End inputs
                //currentTime -= goalTime;
                //}
                break;

            case GameState.running:

                PlayControls.update(gameTime);

                //Poll inputs



                if (PlayControls.getPause())
                {
                    gs = GameState.paused;
                }

                Vector2 playerMovement = new Vector2(0, 0);
                if (PlayControls.getMoveDown())
                {
                    playerMovement.Y += currMap.player.movementSpeed;
                }
                if (PlayControls.getMoveUp())
                {
                    playerMovement.Y -= currMap.player.movementSpeed;
                }
                if (PlayControls.getMoveRight())
                {
                    playerMovement.X += currMap.player.movementSpeed;
                }
                if (PlayControls.getMoveLeft())
                {
                    playerMovement.X -= currMap.player.movementSpeed;
                }
                if (playerMovement.X != 0 || playerMovement.Y != 0)
                {
                    currMap.player.move(playerMovement * (float)gameTime.ElapsedGameTime.TotalSeconds);
                }


                //End inputs

                currMap.update(gameTime);

                break;

            case GameState.paused:


                MenuControls.update(gameTime);

                //Poll inputs

                if (MenuControls.getNextKey())
                {
                    pauseMenu.nextOption();
                }
                if (MenuControls.getPrevKey())
                {
                    pauseMenu.previousOption();
                }
                if (MenuControls.getSelect())
                {
                    gs = GameState.mainMenu;
                }
                if (MenuControls.getExit())
                {
                    gs = GameState.running;
                }
                //End inputs
                break;

            default: break;
            }

            base.Update(gameTime);
        }