Exemple #1
0
        //Pre: None
        //Post: Various options menu updates are made
        //Description: Subprogram to hold update logic for options menu
        private void OptionsUpdate()
        {
            //If exit button or 'B' button is [ressed, unpause game
            if ((NewButtonPress(newGamePadState.Buttons.A, oldGamePadState.Buttons.A) &&
                 CollisionDetection.PointToRectangle(exitButtonRect, GUI.Cursor.circle.center)) ||
                NewButtonPress(newGamePadState.Buttons.B, oldGamePadState.Buttons.B))
            {
                isGamePaused = false;
            }

            //If a certain option button is pressed, proceed with appropriate logic
            if (NewButtonPress(newGamePadState.Buttons.A, oldGamePadState.Buttons.A))
            {
                if (CollisionDetection.PointToRectangle(buttonRect[0], GUI.Cursor.circle.center))
                {
                    //Changing screen to main menu and stopping media player
                    screenMode = MAIN_MENU;
                    MediaPlayer.Stop();
                }
                else if (CollisionDetection.PointToRectangle(buttonRect[1], GUI.Cursor.circle.center))
                {
                    //Saving game and exiting
                    IO.SetUserData();
                    IO.SetGlobalData();
                    Exit();
                }
                else if (CollisionDetection.PointToRectangle(buttonRect[2], GUI.Cursor.circle.center))
                {
                    //Resetting game
                    ResetGame();
                }
                else if (CollisionDetection.PointToRectangle(buttonRect[3], GUI.Cursor.circle.center))
                {
                    //Going to settings screen and stopping media player
                    MediaPlayer.Stop();
                    screenMode = SETTINGS;
                }
            }
        }
Exemple #2
0
        //Pre: None
        //Post: Various game components are updated
        //Description: Subprogram to hold update logic for when game ends
        private void GameEndedUpdate()
        {
            //Selection for game screen
            if (GameLogic.currentGameState == GameLogic.GAME_ENDED)
            {
                //If 'Y' is pressed and user can revive
                if (NewButtonPress(newGamePadState.Buttons.Y, oldGamePadState.Buttons.Y))
                {
                    if (!GameData.Player.reviveUsed)
                    {
                        //If user is elidigible for purchase, complete purchase, reset wave and make misc. updates
                        if (GameData.Player.gold >= 10000)
                        {
                            GameData.Player.gold      -= 10000;
                            GameLogic.currentWave      = new Enemies.Wave(0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
                            GameLogic.currentGameState = GameLogic.WAVE_ENDED;
                            GameData.Player.lives      = 100;
                            GameData.Player.reviveUsed = true;

                            //Stopping background music
                            MediaPlayer.Stop();

                            //Saving game
                            IO.SetUserData();
                            IO.SetGlobalData();
                        }
                    }
                    else
                    {
                        //Playing error sound effect and informing user
                        GameData.ShopItem.errorSndInstance.Play();
                        GameLogic.gameStatusStr = "Already Used";
                    }
                }

                //Calling subprogram to update username
                GameLogic.UsernameUpdate();
            }
            else if (GameLogic.currentGameState == GameLogic.GAME_PENDING)
            {
                //If a certain option button is pressed, proceed with appropriate logic
                if (NewButtonPress(newGamePadState.Buttons.A, oldGamePadState.Buttons.A))
                {
                    if (CollisionDetection.PointToRectangle(buttonRect[0], GUI.Cursor.circle.center))
                    {
                        //Saving game, resetting game, and changing to main menu screen
                        ResetGame();
                        IO.SetUserData();
                        IO.SetGlobalData();
                        screenMode = MAIN_MENU;

                        //Stopping background music
                        MediaPlayer.Stop();
                    }
                    else if (CollisionDetection.PointToRectangle(buttonRect[1], GUI.Cursor.circle.center))
                    {
                        //Saving game, resetting game, and exiting
                        ResetGame();
                        IO.SetUserData();
                        IO.SetGlobalData();
                        Exit();
                    }
                    else if (CollisionDetection.PointToRectangle(buttonRect[2], GUI.Cursor.circle.center))
                    {
                        //Saving game, and resetting game
                        ResetGame();
                        IO.SetUserData();
                        IO.SetGlobalData();

                        //Stopping background music
                        MediaPlayer.Stop();
                    }
                    else if (CollisionDetection.PointToRectangle(buttonRect[3], GUI.Cursor.circle.center))
                    {
                        //Saving game, resetting game, and going to settings screen
                        ResetGame();
                        IO.SetUserData();
                        IO.SetGlobalData();
                        screenMode = SETTINGS;

                        //Stopping background music
                        MediaPlayer.Stop();
                    }
                }
            }
        }
        //Pre: None
        //Post: Various game components are updated
        //Description: Subprogram to hold game update logic
        public static void Update()
        {
            //If media player is not already playing, play game background song
            if (MediaPlayer.State != MediaState.Playing)
            {
                MediaPlayer.Play(Main.gameScreenBackMsc[0]);
            }

            //If game state button is pressed
            if (CollisionDetection.PointToRectangle(gameStateButtonRect, GUI.Cursor.circle.center) && Main.NewButtonPress(Main.newGamePadState.Buttons.A, Main.oldGamePadState.Buttons.A))
            {
                //Changing game state depending on current game state
                if (currentGameState == WAVE_ENDED)
                {
                    currentGameState = SPEED_1X;
                    currentSpeed     = 1;

                    //Adding wave
                    AddWave();

                    //Calling subprogram to set frame rate
                    Main.Instance.SetFrameRate(60.0f);
                }
                else if (currentGameState == SPEED_1X)
                {
                    currentGameState = SPEED_2X;
                    currentSpeed     = 2;

                    //Calling subprogram to set frame rate
                    Main.Instance.SetFrameRate(120.0f);
                }
                else
                {
                    currentGameState = SPEED_1X;
                    currentSpeed     = 1;

                    //Calling subprogram to set frame rate
                    Main.Instance.SetFrameRate(60.0f);
                }
            }

            //If there are no more enemies and wave/game has not ended
            if (!(currentWave.enemyList.Count > 0) && currentGameState != WAVE_ENDED && currentGameState != GAME_ENDED)
            {
                //Iterating through each tower
                foreach (KeyValuePair <Vector2, Towers.Tower> newTower in GUI.GameLevel.towerDictionary)
                {
                    //If the tower is a resource tower, add resources
                    if (newTower.Value is Towers.ResourceTower)
                    {
                        (newTower.Value as Towers.ResourceTower).AddResources();
                    }
                }

                //Saving game
                IO.SetUserData();
                IO.SetGlobalData();

                //Ending wave, increasing wave number and generating new wave
                currentGameState = WAVE_ENDED;
                currentWaveNo++;

                //Playing wave win soundeffect
                winSndInstance.Play();
            }

            //Only updating wave of wave and game has not ended
            if (currentGameState != WAVE_ENDED && currentGameState != GAME_ENDED)
            {
                currentWave.Update();
            }

            //If user ran out of health, reset game state, lives, cursor, and media player
            if (GameData.Player.lives <= 0 && (currentGameState == SPEED_1X || currentGameState == SPEED_2X))
            {
                currentGameState      = GAME_ENDED;
                GameData.Player.lives = 0;
                GUI.Cursor.gridRect   = false;
                MediaPlayer.Stop();
            }

            //Updating each tower defense
            foreach (KeyValuePair <Vector2, Towers.Tower> newTower in GUI.GameLevel.towerDictionary)
            {
                newTower.Value.Update();
            }

            //For loop to call each item in item list
            for (int i = 0; i < GUI.GameLevel.itemList.Count; i++)
            {
                //Updating item
                GUI.GameLevel.itemList[i].Update();

                //Removing item if it has been used
                if (GUI.GameLevel.itemList[i].isItemUsed)
                {
                    GUI.GameLevel.itemList.RemoveAt(i);
                    i--;
                }
            }

            //If a tower is selected
            if (GUI.GameLevel.towerDictionary.ContainsKey(GUI.Cursor.selectedGridLoc))
            {
                //If remove button is pressed, remove tower
                if (Main.NewButtonPress(Main.newGamePadState.Buttons.A, Main.oldGamePadState.Buttons.A) &&
                    CollisionDetection.PointToRectangle(Towers.Tower.removeButtonRect, GUI.Cursor.circle.center))
                {
                    GUI.GameLevel.towerDictionary.Remove(GUI.Cursor.selectedGridLoc);
                }
            }
        }