public override void Update(GameTime gameTime) { GuiHelper.UpdateSetup(); _ui.UpdateAll(gameTime); // Create your UI. Panel.Push().XY = new Vector2(100, 100); if (Button.Put("Show fun").Clicked) { _showFun = !_showFun; } if (_showFun) { Label.Put("This is fun!"); } if (Button.Put("Quit").Clicked) { //Exit(); } Panel.Pop(); // Call UpdateCleanup at the end. GuiHelper.UpdateCleanup(); base.Update(gameTime); base.Update(gameTime); }
protected override void Update(GameTime gameTime) { _keyboardState = Keyboard.GetState(); MouseState = Mouse.GetState(); Entity mainEntity = _manager.MainPlayer.Ball.Form; //Managing the different interactions following the current state of the game if (_launched) { //Updating the camera Camera.Update((float)gameTime.ElapsedGameTime.TotalSeconds); if (_keyboardState.IsKeyDown(Keys.Escape)) { //Quit using Escape Exit(); return; } //Managing the loading of the shot if (!_manager.MainPlayer.Ball.IsMoving()) { if (MouseState.LeftButton == ButtonState.Pressed) { if (_chargeBar.Charge <= _chargeBar.ChargeMax) { _chargeBar.Charge += 0.1f * (float)gameTime.ElapsedGameTime.TotalMilliseconds; } if (_chargeBar.Charge >= _chargeBar.ChargeMax) { _chargeBar.Charge = _chargeBar.ChargeMax; } } if (_lastMouseState.LeftButton == ButtonState.Pressed) { //Hitting the ball if (MouseState.LeftButton == ButtonState.Released) { mainEntity.LinearVelocity += Camera.Camera.ViewDirection * _chargeBar.Charge; _sound.Hit(_chargeBar); _chargeBar.Charge = 0; _manager.NbHits++; } } } else { _chargeBar.Charge = 0; } _lastMouseState = MouseState; //Managing the hole and the finish of the course if (mainEntity.CollisionInformation.BoundingBox.Intersects(_manager.MainLevel.BoundingArrive) && !_manager.Loading) { _sound.Success(); BoundingBox box = new BoundingBox(new Vector3(-1, -21, -1), new Vector3(1, -19, 1)); mainEntity.CollisionInformation.BoundingBox = box; mainEntity.Position = Vector3.Zero; mainEntity.LinearVelocity = Vector3.Zero; _manager.LoadNextLevel(); } //Managing a fall and the reset of position in case of bug if (mainEntity.Position.Y < -50f || _keyboardState.IsKeyDown(Keys.R)) { _sound.Out(); mainEntity.LinearVelocity = Vector3.Zero; mainEntity.Position = Vector3.Zero; } _chargeBar.Update(gameTime); _manager.Space.Update(); base.Update(gameTime); } //If the game is not launched or ended the start HUD is showed else if (!_launched && !_manager.Ended) { //Using Apos.GUI to show the HUD GuiHelper.UpdateSetup(); _ui.UpdateAll(gameTime); // Creating the HUD Panel.Push().XY = new Vector2(Graphics.PreferredBackBufferWidth / 2, Graphics.PreferredBackBufferHeight / 2); Label.Put("MiniGolf"); if (Button.Put("Launch Game").Clicked) { IsMouseVisible = false; _launched = true; _sound.PlayAmbiant(); } if (Button.Put("Quit").Clicked) { Exit(); } Panel.Pop(); GuiHelper.UpdateCleanup(); } //Showing the score board at the end using Apos.GUI if (_manager.Ended) { int i = 1; GuiHelper.UpdateSetup(); _ui.UpdateAll(gameTime); // Create your UI. Panel.Push().XY = new Vector2(Graphics.PreferredBackBufferWidth / 2, Graphics.PreferredBackBufferHeight / 2); Label.Put("Course finished"); Label.Put("Player : " + _manager.MainPlayer.Name); foreach (var score in _manager.MainPlayer.Score) { Label.Put($"Level {i} : " + score.ToString()); i++; } Label.Put("Press Echap to quit"); if (Button.Put("Quit").Clicked) { Exit(); return; } Panel.Pop(); // Call UpdateCleanup at the end. GuiHelper.UpdateCleanup(); if (_keyboardState.IsKeyDown(Keys.Escape)) { Exit(); return; } } base.Update(gameTime); }