/// <summary> /// Logical updates occur here. /// </summary> /// <param name="gameTime">Delta time calculated by XNA.</param> public override void Update() { Scene scene = ServiceManager.Game.Renderer.ActiveScene; scene.PercentOfDayComplete = 0.5; if (tank >= 0) { tankObj.RotateZ(MathHelper.ToRadians((float)(10 * ServiceManager.Game.DeltaTime))); } if (turret >= 0) { turretObj.RotateZ(MathHelper.ToRadians((float)(10 * ServiceManager.Game.DeltaTime))); } ServiceManager.Game.Renderer.Update(); if (KeyPressHelper.IsPressed(Keys.Escape)) { SwitchToLoginScreenState(); } }
/// <summary> /// Checks for key presses from the user /// </summary> private void CheckInput() { // Do not process input if not active. if (!ServiceManager.Game.IsActive) { // If the tank is moving/rotating, stop it. ChangeMovement(VTankObject.Direction.NONE); ChangeRotation(VTankObject.Direction.NONE); return; } Options.KeyBindings keys = ServiceManager.Game.Options.KeySettings; bool localClientCollision = PerformCollisionChecks(); if (KeyPressHelper.IsPressed(keys.Camera)) { if (input.Visible == false) { if (renderer.ActiveScene.CurrentCamera == renderer.ActiveScene.AccessCamera(ChaseCamera)) { renderer.ActiveScene.CurrentCamera = renderer.ActiveScene.AccessCamera(OverheadCamera); } else if (renderer.ActiveScene.CurrentCamera == renderer.ActiveScene.AccessCamera(OverheadCamera)) { renderer.ActiveScene.CurrentCamera = renderer.ActiveScene.AccessCamera(ChaseCamera); } } } if (!input.Visible) { if (localClientCollision && !stuck) { ChangeMovement(VTankObject.Direction.NONE); previousCollision = true; } else { if (Keyboard.GetState().IsKeyDown(keys.Forward)) { ChangeMovement(VTankObject.Direction.FORWARD); } else if (Keyboard.GetState().IsKeyDown(keys.Backward)) { ChangeMovement(VTankObject.Direction.REVERSE); } else { ChangeMovement(VTankObject.Direction.NONE); } if (previousCollision) { previousCollision = false; Resync(); } } if (Keyboard.GetState().IsKeyDown(keys.RotateRight)) { ChangeRotation(VTankObject.Direction.RIGHT); } else if (Keyboard.GetState().IsKeyDown(keys.RotateLeft)) { ChangeRotation(VTankObject.Direction.LEFT); } else { ChangeRotation(VTankObject.Direction.NONE); } if (KeyPressHelper.IsPressed(keys.Minimap)) { miniMap.Enabled = !miniMap.Enabled; } if (Keyboard.GetState().IsKeyDown(keys.Score)) { Scores.Enabled = true; } else { Scores.Enabled = false; } if (KeyPressHelper.IsPressed(Keys.F1)) { helpOverlay.Enabled = !helpOverlay.Enabled; } } }
/// <summary> /// Logical updates occur here. /// </summary> public override void Update() { fps.Update(); // Chat input check: if (KeyPressHelper.IsPressed(Keys.Enter)) { if (input.AcceptEnter() && !ServiceManager.Game.Console.Visible && ServiceManager.Game.IsActive) { input.Visible = !input.Visible; if (input.Visible) { input.Focused = true; ChangeMovement(VTankObject.Direction.NONE); ChangeRotation(VTankObject.Direction.NONE); } else { DoChatMessage(input.GetText()); } } } //Menu press response block (Esc keypress by default) if (KeyPressHelper.IsPressed(ServiceManager.Game.Options.KeySettings.Menu)) { //rotating = true; // TODO: Show menu here. ServiceManager.DestroyTheaterCommunicator(); ServiceManager.Game.Renderer.ActiveScene.DeleteCamera(OverheadCamera); ServiceManager.Game.Renderer.ActiveScene.DeleteCamera(ChaseCamera); ServiceManager.Game.Renderer.ActiveScene.ClearAll(); ServiceManager.Game.SwitchToDefaultCamera(); input.Hide(); ServiceManager.StateManager.ChangeState(new TankListState()); return; } input.Update(); Chat.Update(); if (rotating) { // Check for chat messages. IEvent[] eventBuf = buffer.PopAll(); for (int i = 0; i < eventBuf.Length; ++i) { IEvent evt = eventBuf[i]; if (evt is Client.src.events.types.ChatMessageEvent) { evt.DoAction(); } } Scores.Enabled = true; cd.Update(); CheckForRotate(); //if (input.Visible) // input.Visible = false; return; } timeLeft -= ServiceManager.Game.DeltaTime; ServiceManager.Scene.PercentOfDayComplete = 0.6;//((4.5 * 60) - (timeLeft +2)) / (4.5 * 60); if (timeLeft <= 0) { RotateMap(); } // Process game events. IEvent[] events = buffer.PopAll(); for (int i = 0; i < events.Length; ++i) { events[i].DoAction(); } if (cameraLocked) { Camera overheadCamera = renderer.ActiveScene.AccessCamera(OverheadCamera); Camera chaseCamera = renderer.ActiveScene.AccessCamera(ChaseCamera); if (renderer.ActiveScene.CurrentCamera == chaseCamera) { ServiceManager.Game.Renderer.ActiveScene.CurrentCamera.LockTo( localPlayer, new Vector3(-500, 0, 200), new Vector3(0, 0, 75)); ServiceManager.Game.Renderer.ActiveScene.TransparentWalls = true; } else { ServiceManager.Game.Renderer.ActiveScene.CurrentCamera.Unlock(); ServiceManager.Game.Renderer.ActiveScene.TransparentWalls = false; } } Scene.Update(); RendererAssetPool.UniversalEffect.LightParameters.FogSeedPosition = localPlayer.Position; if (RendererAssetPool.ParticleEffect != null) { RendererAssetPool.ParticleEffect.Parameters["xFogSeedPosition"].SetValue(localPlayer.Position); } GraphicOptions.BackgroundColor = new Color(new Vector4(0.15f, 0.15f, 0.15f, 0f) * Scene.AmbientColor.ToVector4()); Projectiles.CheckCollisions(map, visibleTiles); if (!ServiceManager.Game.Console.Visible) { CheckInput(); if (rotating) { return; } CheckMouseInput(); } else { ChangeMovement(VTankObject.Direction.NONE); ChangeRotation(VTankObject.Direction.NONE); } // Update other components. tips.Update(); buffbar.Update(); mouseCursor.Update(); cd.Update(); hud.Update(); Bases.Update(); EnvironmentEffects.Update(); UpdateHUDValues(localPlayer); Projectiles.AddDelayedProjectiles(); ServiceManager.AudioManager.Update(localPlayer.Position); syncTimer += ServiceManager.Game.DeltaTime; if (syncTimer >= syncTimerMax) { if (localPlayer.DirectionMovement != VTankObject.Direction.NONE) { NeedsSync = true; } syncTimer = 0.0; } if (NeedsSync) { NeedsSync = false; Resync(); } }