Exemplo n.º 1
0
        /// <summary>
        /// Gamepad shooting
        /// </summary>
        private void Shoot(GamePadState currentGamePadState)
        {
            var thumb = new Vector2(currentGamePadState.ThumbSticks.Right.X, -currentGamePadState.ThumbSticks.Right.Y);

            if ((thumb.X > ThumbstickDeadZone || thumb.X < -ThumbstickDeadZone) || (thumb.Y > ThumbstickDeadZone || thumb.Y < -ThumbstickDeadZone))
            {
                var bullet = new Bullet();
                bullet.LoadContent(_contentManager);
                bullet.Fire(SpritePosition, thumb);
                Bullets.Add(bullet);
            }
            else
            {
                var bullet = new Bullet();
                bullet.LoadContent(_contentManager);
                bullet.Fire(SpritePosition, new Vector2(_previousThumb.X, -_previousThumb.Y));
                Bullets.Add(bullet);
            }

        }
Exemplo n.º 2
0
        /// <summary>
        /// Mouse shooting
        /// </summary>
        private void Shoot(MouseState currentMouseState)
        {
            var mousePos = new Vector2(currentMouseState.X, currentMouseState.Y);
            mousePos = Vector2.Transform(mousePos, _cam.InverseTransform); //Get the mouse pos relative to the camera
            var movement = mousePos - SpritePosition;

            if (movement != Vector2.Zero)
            {
                movement.Normalize();
            }

            var bullet = new Bullet();
            bullet.LoadContent(_contentManager);
            bullet.Fire(SpritePosition, movement);
            Bullets.Add(bullet);

        }