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)
        {
            //Check if the window is active
            if (IsActive)
            {
                keyboard.Update();
                mouse.Update(cam, currentMenu);

                //If the current menu = null  we are in game
                if (currentMenu == null)
                {
                    if (!gameUi.textBounds[0].Contains(mouse.position))
                    {
                        if (mouse.LeftClickState == ClickState.Clicked)
                        {
                            LeftClick();
                        }
                        else if (mouse.LeftClickState == ClickState.Released)
                        {
                            Hover();
                        }
                        if (mouse.RightClickState == ClickState.Clicked)
                        {
                            RightClick();
                        }
                    }
                    else
                    {
                        if (clippedToMouse != null)
                        {
                            clippedToMouse = null;
                        }
                    }

                    gameUi.Update(mouse, keyboard);

                    if (keyboard.pressedKeysList.Contains(Keys.Escape))
                    {
                        currentMenu = ingamemenu;
                    }
                    wave.Update(gameTime, cellsWithTower);
                    for (int i = 0; i < cellsWithTower.Count; i++)
                    {
                        cellsWithTower[i].contains.Update(gameTime);
                    }

                    cam.Update(mouse, gameTime, gameUi);
                    if (playerLife == 0)
                    {
                        currentMenu = gameOverMenu;
                    }
                }

                else
                {
                    var oldMenuState = currentMenu.gameState;
                    var newMenu      = IMenu.UpdateMenu(mouse, currentMenu, keyboard);
                    if (newMenu != currentMenu)
                    {
                        currentMenu = newMenu;
                        if (currentMenu != null)
                        {
                            currentMenu.senderMenuState = oldMenuState;
                        }
                    }
                }
            }

            base.Update(gameTime);
        }