public override void Update(GameTime GameTime) { int ScrollVal = (int)(-Input.MouseWheelValue / Math.Abs(-Input.MouseWheelValue)); bool HasClick = Input.HasRegisteredMouseInput("Primary"); bool HasTick = LastClick > TickRate; switch (CrosshairState) { case 0: MouseCursor.Update(new Point(Game.GetScreenWidth() / 2, Game.GetScreenHeight() / 2)); Input.SetMouseLock(true); MouseCursor.Geometry.HasCull = true; break; case 1: CurrentMenuContainer.Update(Input.GetMousePosition(), ScrollVal, HasClick, HasTick, this); MouseCursor.Update(Input.GetMousePosition()); Input.SetMouseLock(false); MouseCursor.Geometry.HasCull = false; break; case 2: MouseCursor.Update(new Point(Game.GetScreenWidth() / 2, Game.GetScreenHeight() / 2)); Input.SetMouseLock(true); MouseCursor.Geometry.HasCull = false; break; } if (HasClick) { LastClick = 0; } LastClick += GameTime.ElapsedGameTime.Milliseconds; LastClick %= 10000; }
/// <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)) { Exit(); } MouseCursor.Update(); camera.Update(gameTime, map); mouseRectangle.Update(gameTime); unitManager.Update(gameTime, mouseRectangle, map); base.Update(gameTime); }
/// <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(); } }