/// <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 (IsActive) { keyboard.Update(); mouse.Update(cam, currentMenu); if (currentMenu == null) { if (mouse.LeftClickState == ClickState.Clicked) { ClipTowersToCell(true); } if (mouse.RightClickState == ClickState.Clicked) { DeleteTower(); } else { ClipTowersToCell(false); } if (keyboard.pressedKeysList.Contains(Keys.Escape)) { currentMenu = ingamemenu; } cam.Update(mouse, gameTime); } else { currentMenu = IMenu.UpdateMenu(mouse, currentMenu, keyboard); } } base.Update(gameTime); }
/// <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); }