/// <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) { base.Update(gameTime); GameKeyboard.Update(gameTime); GameMouse.Update(gameTime); if (GameKeyboard.IsKeyPressed(Microsoft.Xna.Framework.Input.Keys.G)) { Settings.ShowCollidingBoxes = !Settings.ShowCollidingBoxes; } }
/// <summary> /// What happens when wandering around the area /// </summary> /// <param name="gameTime"></param> private void PlayerStateUpdate(GameTime gameTime) { if (GameKeyboard.IsKeyPressed(Microsoft.Xna.Framework.Input.Keys.G)) { _showGrid = !_showGrid; } _player.Update(gameTime); _currentArea.Update(gameTime); switch (_player.CollisionResult) { case Map.CollisionResults.OffRight: LoadArea(_currentArea.RightArea); _player.X = -_player.CurrentRectangle.Width; break; case Map.CollisionResults.OffLeft: LoadArea(_currentArea.LeftArea); _player.X = _gameModel.ScreenWidth; break; case Map.CollisionResults.OffTop: LoadArea(_currentArea.TopArea); _player.Y = -_player.CurrentRectangle.Height; break; case Map.CollisionResults.OffBottom: LoadArea(_currentArea.BottomArea); _player.Y = _gameModel.ScreenHeight; break; case Map.CollisionResults.Battle: _nextState = States.Battle; _battleState = new BattleState(_gameModel, _players); _battleState.LoadContent(); break; default: break; } }
private void SetMovementEvent(GameTime gameTime) { if (GameKeyboard.IsKeyPressed(Keys.D)) { Direction = Directions.Right; } else if (GameKeyboard.IsKeyPressed(Keys.A)) { Direction = Directions.Left; } else if (GameKeyboard.IsKeyPressed(Keys.W)) { Direction = Directions.Up; } else if (GameKeyboard.IsKeyPressed(Keys.S)) { Direction = Directions.Down; } else if (GameKeyboard.IsKeyDown(Keys.D)) { _moveComponent.Velocity = new Vector2(_moveComponent.Speed, 0); Direction = Directions.Right; } else if (GameKeyboard.IsKeyDown(Keys.A)) { _moveComponent.Velocity = new Vector2(-_moveComponent.Speed, 0); Direction = Directions.Left; } else if (GameKeyboard.IsKeyDown(Keys.W)) { _moveComponent.Velocity = new Vector2(0, -_moveComponent.Speed); Direction = Directions.Up; } else if (GameKeyboard.IsKeyDown(Keys.S)) { _moveComponent.Velocity = new Vector2(0, _moveComponent.Speed); Direction = Directions.Down; } }
public void Update(GameTime gameTime) { _timer += (float)gameTime.ElapsedGameTime.TotalSeconds; if (_currentText == _fullText) { if (GameKeyboard.IsKeyPressed(Microsoft.Xna.Framework.Input.Keys.Space)) { IsFinished = true; } } else { if (_timer >= 0.05f) { _timer = 0; var character = _fullText[_currentText.Length]; do { _currentText += character; if (_currentText.Length < _fullText.Length) { character = _fullText[_currentText.Length]; } } while (character == ' '); } if (GameKeyboard.IsKeyPressed(Microsoft.Xna.Framework.Input.Keys.Space)) { _currentText = _fullText; } } }
private void UpdateWakeUpText(GameTime gameTime) { _timer += (float)gameTime.ElapsedGameTime.TotalSeconds; if (_currentText == _texts.First()) { if (GameKeyboard.IsKeyPressed(Keys.Space)) { _textOpacity = 0; } if (_timer > 1f) { _textOpacity -= 0.01f; if (_textOpacity <= 0) { if (_texts.Count > 1) { _textOpacity = 1f; _texts.RemoveAt(0); _textIndex = 0; _currentText = ""; } } } if (_textOpacity <= -1) { _timer = 0; State = States.Flash; } return; } if (GameKeyboard.IsKeyPressed(Keys.Space)) { var text = _texts.First(); _currentText = text; _textIndex = text.Length; } if (_timer >= 0.3) { _timer = 0.0f; var text = _texts.First(); if (_textIndex < text.Length) { var value = text[_textIndex]; _currentText += value; while (value == ' ') { _textIndex++; value = text[_textIndex]; _currentText += value; } } _textIndex++; } }
public override void Update(GameTime gameTime) { _transition.Update(gameTime); if (_nextState != _currentState) { if (_transition.State == Transition.States.Waiting) { _transition.Start(); } if (_transition.State == Transition.States.FirstHalf) { return; } // Change the state at the half-way point so it can't be seen if (_transition.State == Transition.States.Middle) { _currentState = _nextState; } } switch (_currentState) { case States.Playing: if (GameKeyboard.IsKeyPressed(Microsoft.Xna.Framework.Input.Keys.Escape)) { _nextState = States.Paused; return; } if (GameKeyboard.IsKeyPressed(Microsoft.Xna.Framework.Input.Keys.M)) { _nextState = States.Map; _mapState.UpdateMap(_currentArea, _player); return; } if (GameKeyboard.IsKeyPressed(Microsoft.Xna.Framework.Input.Keys.E)) { foreach (var entity in _currentArea.Interactables) { if (_player.CanInteract(entity)) { var interactedComponent = entity.Components.GetComponent <InteractComponent>(); interactedComponent.OnInteract(); } } } PlayerStateUpdate(gameTime); break; case States.Battle: _battleState.Update(gameTime); if (_battleState.BattleFinished) { _nextState = States.AfterBattle; } break; case States.AfterBattle: _afterBattleState.Update(gameTime); if (_afterBattleState.Continue) { _nextState = States.Playing; } break; case States.Paused: if (GameKeyboard.IsKeyPressed(Microsoft.Xna.Framework.Input.Keys.Escape)) { _nextState = States.Playing; return; } _pauseState.Update(gameTime); break; case States.Map: if (GameKeyboard.IsKeyPressed(Microsoft.Xna.Framework.Input.Keys.Escape) || GameKeyboard.IsKeyPressed(Microsoft.Xna.Framework.Input.Keys.M)) { _nextState = States.Playing; return; } _mapState.Update(gameTime); break; default: throw new Exception("Unknown state: " + this._currentState.ToString()); } }