Example #1
0
 // Clicked event
 protected void WireUpEvents(Game1 game)
 {
     // if this button is for change menu state
     if (change != null) {
         Clicked += delegate(object sender, EventArgs e) {
             ((Button)sender).state = ButtonStatus.Up;
             game.Menu.ChangeState(change.Value, ((Button)sender).Text);
         };
     } else {
         Clicked += delegate(object sender, EventArgs e) {
             ((Button)sender).state = ButtonStatus.Up;
             if (Text.Contains("Exit")) {
                 game.Exit();
             }
             if (Text.Contains("Resume")) {
                 game.State = GameState.InGame;
             }
         };
     }
 }
        //method for mouse on main menu
        public Rectangle MouseClicked(int x, int y, Game1 game, ref int currentLevel, ref List<Enemy> enemies, ref List<PickUpItem> Items, ref List<Projectile> projectiles, ref int timer, ContentManager Content, ref Character player, ref string wepUnl, ref bool songPlaying, ref SoundEffectInstance song) {
            Rectangle mouseClickRect = new Rectangle(x, y, 1, 1);
            Rectangle startbuttonRect = new Rectangle((int)startButtonPosition.X, (int)startButtonPosition.Y, 300, 108);
            Rectangle exitbuttonRect = new Rectangle((int)exitButtonPosition.X, (int)exitButtonPosition.Y, 600, 192);

            if (gameState == "StartMenu") {
                //player clicks start
                if (mouseClickRect.Intersects(startbuttonRect)) {
                    try {
                        gameState = "Case";
                        CheckGameState();
                    } catch (GameStateNotFoundException) {
                        
                        gameState = "Case";
                    }

                }
                //player exits game
                else if (mouseClickRect.Intersects(exitbuttonRect)) {
                    game.Exit();
                }
                // player clicked on options
                else if (mouseClickRect.Intersects(optionsButtonPosition)) {
                    try {
                        gameState = "OptionsMenu";
                        lastState = "StartMenu";
                        CheckGameState();
                    } catch (GameStateNotFoundException e) {
                        Console.WriteLine(e.ToString());
                        gameState = "";
                    }
                } else if (mouseClickRect.Intersects(levelSelectButtonPosition)) {
                    try {
                        gameState = "LevelSelect";
                        lastState = "StartMenu";
                        CheckGameState();
                    } catch (GameStateNotFoundException e) {
                        Console.WriteLine(e.ToString());
                        gameState = "";
                    }
                }
            }
            //level select menu
            else if (gameState == "LevelSelect") {
                // back button clicked
                if (mouseClickRect.Intersects(backButtonPosition)) {
                    try {
                        gameState = lastState;
                        CheckGameState();
                    } catch (GameStateNotFoundException e) {
                        Console.WriteLine(e.ToString());
                        gameState = "";
                        lastState = "";
                    }
                } else if (mouseClickRect.Intersects(levelRect[0]) || mouseClickRect.Intersects(levelRect[1]) || mouseClickRect.Intersects(levelRect[2]) || mouseClickRect.Intersects(levelRect[3]) || mouseClickRect.Intersects(levelRect[4]) || mouseClickRect.Intersects(levelRect[5]) || mouseClickRect.Intersects(levelRect[6]) || mouseClickRect.Intersects(levelRect[7])) {
                    Shooting.CreateWeapons(Content);
                    if (mouseClickRect.Intersects(levelRect[0]) && levelClears[0] != 0) {
                        currentLevel = 1;
                        SkillSystem.CreateSkills(Content, player);
                        player.Health = player.MaxHealth;
                        player.Stamina = 100;
                        wepUnl = "";
                        player.Weapon = Shooting.weapons[1];
                        player.FrameLevel = 1;
                        enemies.Clear();
                        Items.Clear();
                        projectiles.Clear();
                        timer = 0;
                        gameState = "LevelSwitch";
                        CheckGameState();
                    } else if (mouseClickRect.Intersects(levelRect[1]) && levelClears[1] != 0) {
                        currentLevel = 2;
                        Shooting.weapons[2].IsAcquired = true;
                        SkillSystem.CreateSkills(Content, player);
                        player.Health = player.MaxHealth;
                        player.Stamina = 100;
                        wepUnl = "";
                        player.Weapon = Shooting.weapons[1];
                        player.FrameLevel = 1;
                        enemies.Clear();
                        Items.Clear();
                        projectiles.Clear();
                        timer = 0;
                        gameState = "LevelSwitch";
                        CheckGameState();
                    } else if (mouseClickRect.Intersects(levelRect[2]) && levelClears[2] != 0) {
                        currentLevel = 3;
                        Shooting.weapons[2].IsAcquired = true;
                        SkillSystem.CreateSkills(Content, player);
                        player.Health = player.MaxHealth;
                        player.Stamina = 100;
                        wepUnl = "";
                        player.Weapon = Shooting.weapons[1];
                        player.FrameLevel = 1;
                        enemies.Clear();
                        Items.Clear();
                        projectiles.Clear();
                        timer = 0;
                        gameState = "LevelSwitch";
                        CheckGameState();
                    } else if (mouseClickRect.Intersects(levelRect[3]) && levelClears[3] != 0) {
                        currentLevel = 4;
                        Shooting.weapons[2].IsAcquired = true;
                        Shooting.weapons[3].IsAcquired = true;
                        SkillSystem.CreateSkills(Content, player);
                        player.Health = player.MaxHealth;
                        player.Stamina = 100;
                        wepUnl = "";
                        player.Weapon = Shooting.weapons[1];
                        player.FrameLevel = 1;
                        enemies.Clear();
                        Items.Clear();
                        projectiles.Clear();
                        timer = 0;
                        gameState = "LevelSwitch";
                        CheckGameState();
                    } else if (mouseClickRect.Intersects(levelRect[4]) && levelClears[4] != 0) {
                        currentLevel = 5;
                        Shooting.weapons[2].IsAcquired = true;
                        Shooting.weapons[3].IsAcquired = true;
                        SkillSystem.CreateSkills(Content, player);
                        player.Health = player.MaxHealth;
                        player.Stamina = 100;
                        wepUnl = "";
                        player.Weapon = Shooting.weapons[1];
                        player.FrameLevel = 1;
                        enemies.Clear();
                        Items.Clear();
                        projectiles.Clear();
                        timer = 0;
                        gameState = "LevelSwitch";
                        CheckGameState();
                    }
                    else if (mouseClickRect.Intersects(levelRect[5]) && levelClears[5] != 0)
                    {
                        currentLevel = 6;
                        Shooting.weapons[2].IsAcquired = true;
                        Shooting.weapons[3].IsAcquired = true;
                        Shooting.weapons[4].IsAcquired = true;
                        SkillSystem.CreateSkills(Content, player);
                        player.Health = player.MaxHealth;
                        player.Stamina = 100;
                        wepUnl = "";
                        player.Weapon = Shooting.weapons[1];
                        player.FrameLevel = 1;
                        enemies.Clear();
                        Items.Clear();
                        projectiles.Clear();
                        timer = 0;
                        gameState = "LevelSwitch";
                        CheckGameState();
                    }
                    else if (mouseClickRect.Intersects(levelRect[6]) && levelClears[6] != 0)
                    {
                        currentLevel = 7;
                        Shooting.weapons[2].IsAcquired = true;
                        Shooting.weapons[3].IsAcquired = true;
                        Shooting.weapons[4].IsAcquired = true;
                        SkillSystem.CreateSkills(Content, player);
                        player.Health = player.MaxHealth;
                        player.Stamina = 100;
                        wepUnl = "";
                        player.Weapon = Shooting.weapons[1];
                        player.FrameLevel = 1;
                        enemies.Clear();
                        Items.Clear();
                        projectiles.Clear();
                        timer = 0;
                        gameState = "LevelSwitch";
                        CheckGameState();
                    }
                    else if (mouseClickRect.Intersects(levelRect[7]) && levelClears[7] != 0)
                    {
                        currentLevel = 8;
                        Shooting.weapons[2].IsAcquired = true;
                        Shooting.weapons[3].IsAcquired = true;
                        Shooting.weapons[4].IsAcquired = true;
                        SkillSystem.CreateSkills(Content, player);
                        player.Health = player.MaxHealth;
                        player.Stamina = 100;
                        wepUnl = "";
                        player.Weapon = Shooting.weapons[1];
                        player.FrameLevel = 1;
                        enemies.Clear();
                        Items.Clear();
                        projectiles.Clear();
                        timer = 0;
                        gameState = "LevelSwitch";
                        CheckGameState();
                    }

                }
            }
            //Death screen 
            else if (gameState == "Death") {
                if (mouseClickRect.Intersects(exitbuttonRect)) {
                    gameState = "StartMenu";
                    CheckGameState();
                }
            }//Victory state for beating the game
            else if (gameState == "Victory") {
                if (mouseClickRect.Intersects(rightStartButton)) {
                    gameState = "StartMenu";
                    CheckGameState();
                }
            }//Page for the Case story 
            else if (gameState == "Case") {
                if (mouseClickRect.Intersects(rightStartButton)) {
                    SkillSystem.CreateSkills(Content, player);
                    Shooting.CreateWeapons(Content);
                    player.Health = player.MaxHealth;
                    player.Stamina = 100;
                    wepUnl = "";
                    player.Weapon = Shooting.weapons[1];
                    player.FrameLevel = 1;
                    currentLevel = 1;
                    enemies.Clear();
                    Items.Clear();
                    projectiles.Clear();
                    timer = 0;
                    gameState = "LevelSwitch";
                    CheckGameState();
                }
            }
               //puased screen
               else if (gameState == "Paused") {
                if (mouseClickRect.Intersects(exitbuttonRect)) {
                    saveLevelClears();
                    song.Stop();
                    songPlaying = false;
                    gameState = "StartMenu";
                    CheckGameState();
                } else if (mouseClickRect.Intersects(optionsButtonPosition)) {
                    try {
                        gameState = "OptionsMenu";
                        lastState = "Paused";
                        CheckGameState();
                    } catch (GameStateNotFoundException e) {
                        Console.WriteLine(e.ToString());
                        gameState = "";
                    }
                } else if (mouseClickRect.Intersects(resumeButtonPosition)) {
                    try {
                        song.Resume();
                        gameState = "Playing";
                        CheckGameState();
                    } catch (GameStateNotFoundException e) {
                        Console.WriteLine(e.ToString());
                        gameState = "";
                    }
                }
            }

            //options screen method
            else if (gameState == "OptionsMenu") {
                // back button clicked
                if (mouseClickRect.Intersects(backButtonPosition)) {
                    try {
                        gameState = lastState;
                        CheckGameState();
                    } catch (GameStateNotFoundException e) {
                        Console.WriteLine(e.ToString());
                        gameState = "";
                        lastState = "";
                    }
                }
                // sounds button clicked
                else if (mouseClickRect.Intersects(soundsButtonPosition)) {
                    try {
                        gameState = "SoundsMenu";
                    } catch (GameStateNotFoundException e) {
                        Console.WriteLine(e.ToString());
                        gameState = "";
                    }
                }
                // graphics button clicked
                else if (mouseClickRect.Intersects(graphicsButtonPosition)) {
                    try {
                        gameState = "GraphicsMenu";
                    } catch (GameStateNotFoundException e) {
                        Console.WriteLine(e.ToString());
                        gameState = "";
                    }
                }
                // controls button clicked
                else if (mouseClickRect.Intersects(controlButtonPosition)) {
                    try {
                        gameState = "Controls";
                    } catch (GameStateNotFoundException e) {
                        Console.WriteLine(e.ToString());
                        gameState = "";
                    }
                }
            }

            // Sounds menu
            else if (gameState == "SoundsMenu") {
                if (mouseClickRect.Intersects(backButtonPosition)) {
                    try {
                        gameState = "OptionsMenu";
                    } catch (GameStateNotFoundException e) {
                        Console.WriteLine(e.ToString());
                        gameState = "";
                    }
                }
            }


            // Controls menu
            else if (gameState == "Controls") {
                if (mouseClickRect.Intersects(controlBackButtonPosition)) {
                    try {
                        gameState = "OptionsMenu";
                    } catch (GameStateNotFoundException e) {
                        Console.WriteLine(e.ToString());
                        gameState = "";
                    }
                }
            }
            // graphics menu
            else if (gameState == "GraphicsMenu") {
                if (mouseClickRect.Intersects(backButtonPosition)) {
                    try {
                        gameState = "OptionsMenu";
                    } catch (GameStateNotFoundException e) {
                        Console.WriteLine(e.ToString());
                        gameState = "";
                    }
                }
            }
            return mouseClickRect;
        }
 public void Update(Game1 game)
 {
     oldState = currentState;
     currentState = Keyboard.GetState();
     if ((currentState.IsKeyDown(Keys.Up) && oldState.IsKeyUp(Keys.Up)) || (currentState.IsKeyDown(Keys.Down) && oldState.IsKeyUp(Keys.Down)))
     {
         play = !play;
     }
     if (currentState.IsKeyDown(Keys.Enter))
     {
         if (play)
         {
             game.transition = true;
         }
         else
         {
             game.Exit();
         }
     }
 }
 public void Update(Game1 game)
 {
     if (game.keyState.IsKeyDown(Keys.Up) && game.oldState.IsKeyUp(Keys.Up))
     {
         if (!exitSelected && !resumeSelected)
         {
             resumeSelected = true;
             exitSelected = false;
         }
         else if (resumeSelected)
         {
             exitSelected = true;
             resumeSelected = false;
         }
         else if (exitSelected)
         {
             resumeSelected = true;
             exitSelected = false;
         }
     }
     if (game.keyState.IsKeyDown(Keys.Down) && game.oldState.IsKeyUp(Keys.Down))
     {
         if (!exitSelected && !resumeSelected)
         {
             exitSelected = true;
             resumeSelected = false;
         }
         else if (resumeSelected)
         {
             exitSelected = true;
             resumeSelected = false;
         }
         else if (exitSelected)
         {
             resumeSelected = true;
             exitSelected = false;
         }
     }
     if (exitSelected)
     {
         exit = game.Content.Load<Texture2D>(@"Game\Menu\exitSelected");
         resume = game.Content.Load<Texture2D>(@"Game\Menu\resume");
     }
     if (resumeSelected)
     {
         exit = game.Content.Load<Texture2D>(@"Game\Menu\exit");
         resume = game.Content.Load<Texture2D>(@"Game\Menu\resumeSelected");
     }
     if (game.keyState.IsKeyDown(Keys.Enter))
     {
         if (exitSelected)
         {
             game.Exit();
         }
         if (resumeSelected)
         {
             Game1.currentGameState = Game1.GameState.PLAY;
             paused = false;
         }
     }
 }