public void Update(GameTime gameTime) { background.Update(gameTime); HelpButton.Update(gameTime); ExitButton.Update(gameTime); SettingsButton.Update(gameTime); if (GameScreenManager.Instance.ClientID != -1) { User usr = RetroEnvironment.GetGame().GetClientManager().GetClientByUserID(GameScreenManager.Instance.ClientID).GetUser(); if (usr != null) { txtDiamond.SetText(usr.GetDiamonds()); txtCredit.SetText(usr.GetCredits()); txtDucket.SetText(usr.GetDuckets()); } } }
/// <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(); } MouseState mouseState = Mouse.GetState(); KeyboardState keyboardState = Keyboard.GetState(); if (GameSteate == GameSteates.MainMenu) { PlayButton.Update(gameTime, mouseState); SettingsButton.Update(gameTime, mouseState); ExitButton.Update(gameTime, mouseState); if (PlayButtonClicked && TimePlayClicked - gameTime.TotalGameTime.TotalSeconds < -Math.PI * 0.75) { GameSteate = GameSteates.Game; } } if (GameSteate == GameSteates.Game) { Global.MouseState = mouseState; Global.KeyboardState = keyboardState; if (PlanetOrSolarSwitchCulldown <= 0) { if (keyboardState.IsKeyDown(Keys.Left)) { Global.SelectedPlanet -= 1; PlanetOrSolarSwitchCulldown = 2000; } else if (keyboardState.IsKeyDown(Keys.Right)) { Global.SelectedPlanet += 1; PlanetOrSolarSwitchCulldown = 2000; } if (keyboardState.IsKeyDown(Keys.Up) && keyboardState.IsKeyUp(Keys.LeftControl)) { Global.SelectedSolarSystem += 1; PlanetOrSolarSwitchCulldown = 2000; } else if (keyboardState.IsKeyDown(Keys.Down) && keyboardState.IsKeyUp(Keys.LeftControl)) { Global.SelectedSolarSystem -= 1; PlanetOrSolarSwitchCulldown = 2000; } } else { PlanetOrSolarSwitchCulldown -= gameTime.ElapsedGameTime.TotalMilliseconds; } Global.Camera.Update(gameTime, mouseState, keyboardState); Vector2 mousePosition = mouseState.Position.ToVector2(); Vector3 nearPoint = new Vector3(mousePosition, 0); Vector3 farPoint = new Vector3(mousePosition, 1); nearPoint = GraphicsDevice.Viewport.Unproject(nearPoint, Global.Camera.ProjectionMatrix, Global.Camera.ViewMatrix, Matrix.Identity); farPoint = GraphicsDevice.Viewport.Unproject(farPoint, Global.Camera.ProjectionMatrix, Global.Camera.ViewMatrix, Matrix.Identity); Vector3 direction = farPoint - nearPoint; direction.Normalize(); Global.ClickRay = new Ray(nearPoint, direction); Space.Update(); if (keyboardState.IsKeyDown(Keys.NumPad1)) { Global.Camera.position = new Vector3(30, 30, 40); Global.Camera.lookAtVector = new Vector3(0, 0, 0); cameraPerspective = CameraPerspectives.closeUp; } else if (keyboardState.IsKeyDown(Keys.NumPad2)) { Global.Camera.position = new Vector3(600, 600, 600); Global.Camera.lookAtVector = new Vector3(80, 80, 0); cameraPerspective = CameraPerspectives.closeUp; } else if (keyboardState.IsKeyDown(Keys.NumPad3)) { Global.Camera.position = new Vector3(2100, 1800, 1800); Global.Camera.lookAtVector = new Vector3(300, 300, 0); cameraPerspective = CameraPerspectives.map; } } if (keyboardState.IsKeyDown(Keys.F12)) { goneFullScreen = true; graphics.PreferredBackBufferWidth = GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Width; graphics.PreferredBackBufferHeight = GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Height; _planetRenderTarget = new RenderTarget2D(GraphicsDevice, (int)(GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Width), GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Height, false, SurfaceFormat.Color, DepthFormat.None); Shaders.MainMenu.Parameters["resolution"].SetValue(new Vector2(_planetRenderTarget.Width * 1.25f, _planetRenderTarget.Height)); graphics.ToggleFullScreen(); graphics.ApplyChanges(); } base.Update(gameTime); }