/// <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 (!IsActive) { return; } if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape)) { Exit(); } /* Controllers */ KeyboardState newKeyboardState = Keyboard.GetState(); MouseState newMouseState = Mouse.GetState(); /* Process mouse move */ if (_oldMouseState.X != newMouseState.X) { if (newMouseState.X >= 0 || newMouseState.X < _screenWidth) { _ship.MoveTo(newMouseState.X); } } /* Process left-click */ if (newMouseState.LeftButton == ButtonState.Released && _oldMouseState.LeftButton == ButtonState.Pressed && _readyToShoot) { //TODO /* Process keyboard events */ if (newKeyboardState.IsKeyDown(Keys.Left)) { _ship.MoveLeft(); } } if (newKeyboardState.IsKeyDown(Keys.Right)) { _ship.MoveRight(); } if (_oldKeyboardState.IsKeyUp(Keys.Space) && newKeyboardState.IsKeyDown(Keys.Space) && _readyToShoot) { //TODO _oldMouseState = newMouseState; // this saves the old state } _oldKeyboardState = newKeyboardState; base.Update(gameTime); }