public override void Update(GameTime gametime) { _timer += (float)gametime.ElapsedGameTime.TotalSeconds; if (_timer > _lifeSpan) { _isRemoved = true; } _timer -= _lifeSpan; _position += _direction * _velocity; _bounds.X = (_position.X - 8 * _scale) + 5; _bounds.Y = (_position.Y - 8 * _scale); if (gameScreen.CheckCollision(_bounds)) { _isRemoved = true; } }
public override void Update(GameTime gametime) { keyboardState = Keyboard.GetState(); Vector2 positionXChecker = _position; Vector2 positionYChecker = _position; idlingPrior = idlingCurrent; if (keyboardState.IsKeyDown(Keys.Up) || keyboardState.IsKeyDown(Keys.W)) { positionYChecker += new Vector2(0, -2); running = true; _bounds.Y = positionYChecker.Y; if (!gameScreen.CheckCollision(_bounds)) { _position.Y = positionYChecker.Y; } else { _bounds.Y = _position.Y; } } if (keyboardState.IsKeyDown(Keys.Down) || keyboardState.IsKeyDown(Keys.S)) { positionYChecker += new Vector2(0, 2); running = true; _bounds.Y = positionYChecker.Y; if (!gameScreen.CheckCollision(_bounds)) { _position.Y = positionYChecker.Y; } else { _bounds.Y = _position.Y; } } if (keyboardState.IsKeyDown(Keys.Left) || keyboardState.IsKeyDown(Keys.A)) { positionXChecker += new Vector2(-2, 0); running = true; _bounds.X = positionXChecker.X - 23.75f; if (!gameScreen.CheckCollision(_bounds)) { _position.X = positionXChecker.X; } else { _bounds.X = _position.X - 23.75f; } } if (keyboardState.IsKeyDown(Keys.Right) || keyboardState.IsKeyDown(Keys.D)) { positionXChecker += new Vector2(2, 0); running = true; _bounds.X = positionXChecker.X - 23.75f; if (!gameScreen.CheckCollision(_bounds)) { _position.X = positionXChecker.X; } else { _bounds.X = _position.X - 23.75f; } } arm.Update(gametime); flipped = arm.Flipped; if (running) { _activeTexture = _runningTexture; _textureMapPosition = new Rectangle(0, 0, 19, 25); animationFrameNum = 5; idlingCurrent = false; Color = Color.White; } else { idlingCurrent = true; _activeTexture = _idleTexture; _textureMapPosition = new Rectangle(0, 0, 19, 25); animationFrameNum = 3; Color = Color.White; if (idlingCurrent && !idlingPrior) { animationFrame = 0; } } running = false; }