/// <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 (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape)) { this.Exit(); } if (generatedPercent >= 100) { MouseState cms = Mouse.GetState(); KeyboardState cks = Keyboard.GetState(); GamePadState cgs = GamePad.GetState(PlayerIndex.One); Vector2 mp2D = Vector2.Clamp(new Vector2(cms.X, cms.Y), Vector2.Zero, new Vector2(GraphicsDevice.Viewport.Width, GraphicsDevice.Viewport.Height)); Vector3 mousePos = Helper.ProjectMousePosition(mp2D, GraphicsDevice.Viewport, gameCamera.worldMatrix, gameCamera.viewMatrix, gameCamera.projectionMatrix, 0f); Vector2 virtualJoystick = Vector2.Zero; if (cks.IsKeyDown(Keys.W) || cks.IsKeyDown(Keys.Up)) { virtualJoystick.Y = -1; } if (cks.IsKeyDown(Keys.A) || cks.IsKeyDown(Keys.Left)) { virtualJoystick.X = -1; } if (cks.IsKeyDown(Keys.S) || cks.IsKeyDown(Keys.Down)) { virtualJoystick.Y = 1; } if (cks.IsKeyDown(Keys.D) || cks.IsKeyDown(Keys.Right)) { virtualJoystick.X = 1; } if (virtualJoystick.Length() > 0f) { virtualJoystick.Normalize(); } if (cgs.ThumbSticks.Left.Length() > 0.1f) { virtualJoystick = cgs.ThumbSticks.Left; virtualJoystick.Y = -virtualJoystick.Y; } if (gameHero.introTargetReached) { gameHero.Move(virtualJoystick); } if ((cks.IsKeyDown(Keys.Space) && !lks.IsKeyDown(Keys.Space)) || (cgs.Buttons.B == ButtonState.Pressed && lgs.Buttons.B != ButtonState.Pressed)) { gameHero.TryPlantBomb(currentRoom); } if (cks.IsKeyDown(Keys.Z) || cks.IsKeyDown(Keys.Enter) || cgs.Buttons.A == ButtonState.Pressed) { gameHero.DoAttack(); } if (cks.IsKeyDown(Keys.X) || cks.IsKeyDown(Keys.RightShift) || cgs.Buttons.X == ButtonState.Pressed) { gameHero.DoDefend(true, virtualJoystick); } else { gameHero.DoDefend(false, virtualJoystick); } int openCount = 0; foreach (Door d in Doors) { if (d.IsOpen) { openCount++; } } if (gameHero.introTargetReached) { #region ROOM STATE SHIT switch (roomState) { case RoomState.DoorsOpening: OpenDoors(); if (openCount > 0) { roomState = RoomState.DoorsOpen; } doorCountdown = doorCountdownTarget; break; case RoomState.DoorsOpen: if (doorCountdown > 0) { doorCountdown -= gameTime.ElapsedGameTime.TotalMilliseconds; if (doorCountdown <= 0) { roomState = RoomState.DoorsClosing; } } break; case RoomState.DoorsClosing: foreach (Door d in Doors) { d.Close(false); } if (openCount == 0) { roomMovesLeft = 3 + Helper.Random.Next(5); DoRoomShift(); roomState = RoomState.RoomsShifting; } break; case RoomState.RoomsShifting: foreach (Door d in Doors) { d.Close(true); } if (roomShift != null) { roomShift.Update(gameTime, gameHero, ref Rooms); if (roomShift.Complete) { if (roomMovesLeft > 0) { DoRoomShift(); } else { roomShift = null; } } } if (roomShift == null && roomMovesLeft == 0) { roomState = RoomState.DoorsOpening; } break; } #endregion } else { if (Vector3.Distance(gameHero.Position, gameHero.IntroTarget) < 5f) { exitDoor.Close(false); } } if (gameHero.RoomX == exitRoomX && gameHero.RoomY == exitRoomY) { if (exitDoor.IsOpen) { particleController.Spawn(exitDoor.ParticlePosition, new Vector3(-0.05f + ((float)Helper.Random.NextDouble() * 0.1f), -0.05f + ((float)Helper.Random.NextDouble() * 0.1f), -0.05f + ((float)Helper.Random.NextDouble() * 0.1f)) + exitDoor.ParticleDir * 0.2f, 2f, Color.White * 0.5f, 1000, false); } } if (roomShift != null) { gameCamera.Update(gameTime, currentRoom.World, roomShift.cameraShake); } else { gameCamera.Update(gameTime, currentRoom.World, Vector3.Zero); } foreach (Room r in Rooms) { if (r.World != null) { r.World.Update(gameTime, gameCamera, currentRoom == r); } } //currentRoom.World.Update(gameTime, gameCamera); gameHero.Update(gameTime, gameCamera, currentRoom, Doors, ref Rooms, allRoomsComplete, exitRoomX, exitRoomY, exitDoor); currentRoom = Rooms[gameHero.RoomX, gameHero.RoomY]; currentRoom.Update(gameTime); enemyController.Update(gameTime, gameCamera, currentRoom, gameHero, Doors); particleController.Update(gameTime, gameCamera, currentRoom.World); pickupController.Update(gameTime, gameCamera, gameHero, currentRoom); projectileController.Update(gameTime, gameCamera, gameHero, currentRoom); bombController.Update(gameTime, currentRoom, gameHero); AudioController.Update(gameTime); foreach (Door d in Doors) { d.Update(gameTime); } drawEffect.View = gameCamera.viewMatrix; drawEffect.World = gameCamera.worldMatrix; lms = cms; lks = cks; lgs = cgs; if (gameHero.Dead || gameHero.exitReached) { deadTime += gameTime.ElapsedGameTime.TotalMilliseconds; if (deadTime >= 5000) { Reset(); } if (showCompleteAlpha < 1f) { showCompleteAlpha += 0.1f; } AudioController.StopMusic(); } allRoomsComplete = true; foreach (Room r in Rooms) { if (!r.IsComplete) { allRoomsComplete = false; } } if (allRoomsComplete && !shownComplete) { if (gameHero.RoomX == exitRoomX && gameHero.RoomY == exitRoomY && roomState == RoomState.DoorsOpen) { exitDoor.Open(false); } if (showCompleteAlpha < 1f) { showCompleteAlpha += 0.1f; } showCompleteTime += gameTime.ElapsedGameTime.TotalMilliseconds; if (showCompleteTime > 5000) { shownComplete = true; } } if (shownComplete && showCompleteAlpha > 0f && !gameHero.exitReached) { showCompleteAlpha -= 0.1f; } //if (gameHero.exitReached && showCompleteAlpha < 1f) showCompleteAlpha += 0.1f; //if (gameHero.exitReached) //{ // dead //} } else { titleFrameTime += gameTime.ElapsedGameTime.TotalMilliseconds; if (titleFrameTime >= 100) { titleFrameTime = 0; titleCurrentFrame++; if (titleCurrentFrame == 4) { titleCurrentFrame = 0; } } titleScrollPos += Vector2.One; if (titleScrollPos.X == texTitleBG.Width) { titleScrollPos = Vector2.Zero; } } 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) { if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape)) { this.Exit(); } if (generatedPercent >= 100) { MouseState cms = Mouse.GetState(); KeyboardState cks = Keyboard.GetState(); GamePadState cgs = GamePad.GetState(PlayerIndex.One); Vector2 mp2D = Vector2.Clamp(new Vector2(cms.X, cms.Y), Vector2.Zero, new Vector2(GraphicsDevice.Viewport.Width, GraphicsDevice.Viewport.Height)); Vector3 mousePos = Helper.ProjectMousePosition(mp2D, GraphicsDevice.Viewport, gameCamera.worldMatrix, gameCamera.viewMatrix, gameCamera.projectionMatrix, 0f); Vector2 virtualJoystick = Vector2.Zero; if (cks.IsKeyDown(Keys.W) || cks.IsKeyDown(Keys.Up)) { virtualJoystick.Y = -1; } if (cks.IsKeyDown(Keys.S) || cks.IsKeyDown(Keys.Left)) { virtualJoystick.X = -1; } if (cks.IsKeyDown(Keys.A) || cks.IsKeyDown(Keys.Down)) { virtualJoystick.Y = 1; } if (cks.IsKeyDown(Keys.D) || cks.IsKeyDown(Keys.Right)) { virtualJoystick.X = 1; } if (virtualJoystick.Length() > 0f) { virtualJoystick.Normalize(); } if (cgs.ThumbSticks.Left.Length() > 0.1f) { virtualJoystick = cgs.ThumbSticks.Left; virtualJoystick.Y = -virtualJoystick.Y; } gameHero.Move(virtualJoystick); if ((cks.IsKeyDown(Keys.Space) && !lks.IsKeyDown(Keys.Space)) || (cgs.Buttons.B == ButtonState.Pressed && lgs.Buttons.B != ButtonState.Pressed)) { gameHero.TryPlantBomb(currentRoom); } if (cks.IsKeyDown(Keys.Z) || cks.IsKeyDown(Keys.Enter) || cgs.Buttons.A == ButtonState.Pressed) { gameHero.DoAttack(); } if (cks.IsKeyDown(Keys.X) || cks.IsKeyDown(Keys.RightShift) || cgs.Buttons.X == ButtonState.Pressed) { gameHero.DoDefend(true, virtualJoystick); } else { gameHero.DoDefend(false, virtualJoystick); } int openCount = 0; foreach (Door d in Doors) { if (d.IsOpen) { openCount++; } } #region ROOM STATE SHIT switch (roomState) { case RoomState.DoorsOpening: OpenDoors(); if (openCount > 0) { roomState = RoomState.DoorsOpen; } doorCountdown = doorCountdownTarget; break; case RoomState.DoorsOpen: if (doorCountdown > 0) { doorCountdown -= gameTime.ElapsedGameTime.TotalMilliseconds; if (doorCountdown <= 0) { roomState = RoomState.DoorsClosing; } } break; case RoomState.DoorsClosing: foreach (Door d in Doors) { d.Close(false); } if (openCount == 0) { roomMovesLeft = 3 + Helper.Random.Next(5); DoRoomShift(); roomState = RoomState.RoomsShifting; } break; case RoomState.RoomsShifting: foreach (Door d in Doors) { d.Close(true); } if (roomShift != null) { roomShift.Update(gameTime, gameHero, ref Rooms); if (roomShift.Complete) { if (roomMovesLeft > 0) { DoRoomShift(); } else { roomShift = null; } } } if (roomShift == null && roomMovesLeft == 0) { roomState = RoomState.DoorsOpening; } break; } #endregion if (roomShift != null) { gameCamera.Update(gameTime, currentRoom.World, roomShift.cameraShake); } else { gameCamera.Update(gameTime, currentRoom.World, Vector3.Zero); } foreach (Room r in Rooms) { if (r.World != null) { r.World.Update(gameTime, gameCamera, currentRoom == r); } } //currentRoom.World.Update(gameTime, gameCamera); gameHero.Update(gameTime, gameCamera, currentRoom, Doors, ref Rooms); currentRoom = Rooms[gameHero.RoomX, gameHero.RoomY]; currentRoom.Update(gameTime); enemyController.Update(gameTime, gameCamera, currentRoom, gameHero, Doors); particleController.Update(gameTime, gameCamera, currentRoom.World); projectileController.Update(gameTime, gameCamera, gameHero, currentRoom); bombController.Update(gameTime, currentRoom, gameHero); foreach (Door d in Doors) { d.Update(gameTime); } drawEffect.View = gameCamera.viewMatrix; drawEffect.World = gameCamera.worldMatrix; lms = cms; lks = cks; lgs = cgs; } base.Update(gameTime); }