/// <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) { IsActive = base.IsActive; if (!IsActive) return; if (Input.IsKeyPressed(Keys.F1)) { Debugging = !Debugging; DebugHud.DebugStringPanels[0].Get("toggle_debug").Text = "Debug Mode (F1): " + Debugging; } if (Input.IsKeyPressed(Keys.P)) { spectating = !spectating; DebugHud.DebugStringPanels[0].Get("spectate_info").Text = "Spectator Camera (P): " + spectating; } OnGameUpdate(gameTime); MainCamera.Update(gameTime); tank.Update(gameTime, map); MainCamera.Position = new Vector3(tank.Position.X - tank.Front.X * 8.0f, tank.Position.Y + 8.0f, tank.Position.Z - tank.Front.Z * 8.0f); SpectatorCamera.Update(gameTime); aiTank.Update(gameTime, map); SpectatorCamera.Position = new Vector3(aiTank.Position.X - aiTank.Front.X * 8.0f, aiTank.Position.Y + 8.0f, aiTank.Position.Z - aiTank.Front.Z * 8.0f); float camAngle = tank.Yaw + 90.0f; if (camAngle > 360.0f) { camAngle = camAngle - 360.0f; } MainCamera.Yaw = camAngle; camAngle = aiTank.Yaw + 90.0f; if (camAngle > 360.0f) { camAngle = camAngle - 360.0f; } SpectatorCamera.Yaw = camAngle; rainEmitter.Update(gameTime); dustEmitter.Start = tank.Position - tank.Right * 2 - tank.Front * 3.5f; dustEmitter.End = tank.Position + tank.Right * 2 - tank.Front * 3.5f; dustEmitter.Velocity = new Vector3(10.0f * -tank.Front.X, 25.0f, 10.0f * -tank.Front.Z); dustEmitter.Interval = tank.IsMoving ? 0.01f : float.MaxValue; dustEmitter.Update(gameTime); effect.Projection = MainCamera.Projection; effect.View = MainCamera.View; DebugHud.DebugStringPanels[0].Get("fps").Text = "FPS: " + gameTime.GetFramesPerSecond(); DebugHud.DebugStringPanels[0].Get("delta_time").Text = "Delta Time: " + gameTime.GetDeltaTime(); if (Input.IsKeyPressed(Keys.Escape)) { Exit(); } base.Update(gameTime); }