/// <summary> /// Updates the state of the game. This method checks the GameScreen.IsActive /// property, so the game will stop updating when the pause menu is active, /// or if you tab away to a different application. /// </summary> public override void Update(GameTime gameTime, bool otherScreenHasFocus, bool coveredByOtherScreen) { base.Update(gameTime, otherScreenHasFocus, coveredByOtherScreen); if (IsActive) { gameCamera.Update(ScreenManager.GraphicsDevice.Viewport); gameHero.Update(gameTime); gameMinionManager.Update(gameTime); gameProjectileManager.Update(gameTime); if (gameHero.HP <= 0 || gameHero.ReachedPrincess) { finishGameTimer += gameTime.ElapsedGameTime.TotalMilliseconds; if (finishGameTimer >= 3000 && !shownFinishScreen) { shownFinishScreen = true; PauseBackgroundScreen pauseBG = new PauseBackgroundScreen(); ScreenManager.AddScreen(pauseBG, ControllingPlayer); ScreenManager.AddScreen(new PauseMenuScreen(pauseBG), ControllingPlayer); } } } floatingHeartPos -= new Vector2(0, 1f); if (gameHero.painAlpha == 1f) floatingHeartPos = HeartsPos + new Vector2((40 * (gameHero.HP)), 0); gameButtonManager.Update(gameTime); gameParallaxManager.Update(gameTime, gameCamera.Position); }
/// <summary> /// Lets the game respond to player input. Unlike the Update method, /// this will only be called when the gameplay screen is active. /// </summary> public override void HandleInput(InputState input) { if (input == null) throw new ArgumentNullException("input"); // Look up inputs for the active player profile. int playerIndex = (int)ControllingPlayer.Value; KeyboardState keyboardState = input.CurrentKeyboardStates[playerIndex]; GamePadState gamePadState = input.CurrentGamePadStates[playerIndex]; PlayerIndex player; if (input.IsPauseGame(ControllingPlayer)) { PauseBackgroundScreen pauseBG = new PauseBackgroundScreen(); ScreenManager.AddScreen(pauseBG, ControllingPlayer); ScreenManager.AddScreen(new PauseMenuScreen(pauseBG), ControllingPlayer); } if(IsActive) { if (input.MouseDragging) { gameCamera.Target -= input.MouseDelta; //gameCamera.cl } if (input.DragGesture.HasValue) { gameCamera.Target -= input.DragGesture.Value.Delta; } if (input.IsNewKeyPress(Keys.Space, null, out player)) gameHero.Position = gameHero.SpawnPoint; if (!gameButtonManager.HandleInput(input)) { if (input.TapPosition.HasValue) { Vector2 tapPos = input.TapPosition.Value; tapPos += gameCamera.Position; Point tilePos = new Point((int)tapPos.X / 64, (int)tapPos.Y / 64); var t = gameMap.Layers.Where(l => l.Name == "FG").First(); TileLayer tileLayer = t as TileLayer; bool found = false; int type = gameButtonManager.SelectedButton; if (gameButtonManager.Buttons[gameButtonManager.SelectedButton].CurrentCoolDown <= 0) { if (type != 4) { if (tilePos.X >= tileLayer.Tiles.GetLowerBound(0) || tilePos.X <= tileLayer.Tiles.GetUpperBound(0) && tilePos.Y >= tileLayer.Tiles.GetLowerBound(1) || tilePos.Y <= tileLayer.Tiles.GetUpperBound(1)) { if (tileLayer.Tiles[tilePos.X, tilePos.Y] != null) { while (!found) { if (tilePos.X >= tileLayer.Tiles.GetLowerBound(0) || tilePos.X <= tileLayer.Tiles.GetUpperBound(0) && tilePos.Y >= tileLayer.Tiles.GetLowerBound(1) || tilePos.Y <= tileLayer.Tiles.GetUpperBound(1)) { if (tileLayer.Tiles[tilePos.X, tilePos.Y] != null) { if (tilePos.Y - 1 >= tileLayer.Tiles.GetLowerBound(1)) { if (tileLayer.Tiles[tilePos.X, tilePos.Y - 1] == null) { gameMinionManager.Add(new Vector2((tilePos.X * 64) + 32, (tilePos.Y * 64) - 32), type); gameButtonManager.Buttons[gameButtonManager.SelectedButton].CurrentCoolDown = gameButtonManager.Buttons[gameButtonManager.SelectedButton].CoolDown; found = true; } else tilePos.Y -= 1; } else found = true; } else found = true; } else found = true; } } else { while (!found) { if (tilePos.X >= tileLayer.Tiles.GetLowerBound(0) || tilePos.X <= tileLayer.Tiles.GetUpperBound(0) && tilePos.Y >= tileLayer.Tiles.GetLowerBound(1) || tilePos.Y <= tileLayer.Tiles.GetUpperBound(1)) { if (tileLayer.Tiles[tilePos.X, tilePos.Y] == null) { if (tilePos.Y + 1 <= tileLayer.Tiles.GetUpperBound(1)) { if (tileLayer.Tiles[tilePos.X, tilePos.Y + 1] != null) { gameMinionManager.Add(new Vector2((tilePos.X * 64) + 32, ((tilePos.Y + 1) * 64) - 32), type); gameButtonManager.Buttons[gameButtonManager.SelectedButton].CurrentCoolDown = gameButtonManager.Buttons[gameButtonManager.SelectedButton].CoolDown; found = true; } else tilePos.Y += 1; } else found = true; } else found = true; } else found = true; } } } } else { gameMinionManager.Add(new Vector2((tilePos.X * 64) + 32, (tilePos.Y * 64) + 32), type); gameButtonManager.Buttons[gameButtonManager.SelectedButton].CurrentCoolDown = gameButtonManager.Buttons[gameButtonManager.SelectedButton].CoolDown; } } } } } }