Пример #1
0
        public void Shoot(GameTime gameTime)
        {
            switch (CurrentGun)
            {
                #region RocketLauncher
            case GunType.RocketLauncher:
            {
                if (PreviousGamePadState.IsButtonUp(CurrentShootButton) &&
                    CurrentGamePadState.IsButtonDown(CurrentShootButton))
                {
                    switch (CurrentFacing)
                    {
                    case Facing.Left:
                        OnPlayerShootHappened(new Vector2(-35, 0));
                        //CreatePlayerShoot(new Vector2(-35, 0));
                        break;

                    case Facing.Right:
                        //CreatePlayerShoot(new Vector2(35, 0));
                        OnPlayerShootHappened(new Vector2(35, 0));
                        break;
                    }

                    NumShots++;
                }
            }
            break;
                #endregion

                #region Shotgun
            case GunType.Shotgun:
            {
                if (PreviousGamePadState.IsButtonUp(CurrentShootButton) &&
                    CurrentGamePadState.IsButtonDown(CurrentShootButton))
                {
                    Vector2 direction = Vector2.Zero;

                    switch (CurrentFacing)
                    {
                    case Facing.Left:
                        direction = new Vector2(-1, 0);
                        break;

                    case Facing.Right:
                        direction = new Vector2(1, 0);
                        break;
                    }

                    for (int i = 0; i < 4; i++)
                    {
                        float angle = MathHelper.ToRadians((float)Math.Atan2(direction.Y, direction.X) + Random.Next(-15, 15));

                        direction = new Vector2((float)Math.Cos(angle), (float)Math.Sin(angle)) * AimDirection.X;

                        LightProjectile newProjectile = new ShotgunProjectile(BarrelEnd, direction, 1);
                        CreateLightProjectile(newProjectile, this);
                    }

                    NumShots++;
                }
            }
            break;
                #endregion

                #region MachineGun
            case GunType.MachineGun:
            {
                if (ShotTiming.X < ShotTiming.Y)
                {
                    ShotTiming.X += (float)gameTime.ElapsedGameTime.TotalMilliseconds;
                }

                if (PreviousGamePadState.IsButtonDown(CurrentShootButton) &&
                    CurrentGamePadState.IsButtonDown(CurrentShootButton) &&
                    ShotTiming.X >= ShotTiming.Y)
                {
                    Vector2 direction = Vector2.Zero;

                    switch (CurrentFacing)
                    {
                    case Facing.Left:
                        direction = new Vector2(-1, 0);
                        break;

                    case Facing.Right:
                        direction = new Vector2(1, 0);
                        break;
                    }

                    //float angle = MathHelper.ToRadians((float)Math.Atan2(direction.Y, direction.X) + Random.Next(-15, 15));
                    float thing = Random.Next(-2, 2);
                    direction = new Vector2(MathHelper.ToRadians((float)Math.Cos(thing)), MathHelper.ToRadians((float)Math.Sin(thing))) + AimDirection;

                    LightProjectile newProjectile = new MachineGunProjectile(BarrelEnd, direction, 1);
                    CreateLightProjectile(newProjectile, this);

                    ShotTiming.X = 0;
                    NumShots++;
                }
            }
            break;
                #endregion
            }
        }
Пример #2
0
 public bool IsNewButtonRelease(Buttons button)
 {
     return(PreviousGamePadState.IsButtonDown(button) && GamePadState.IsButtonUp(button));
 }
Пример #3
0
 /// <summary>
 /// Gets whether the given button was just released.
 /// </summary>
 /// <param name="button">The given button.</param>
 /// <returns>True if the button was just released, false otherwise.</returns>
 public static bool GetButtonDownUp(Buttons button)
 {
     return(PreviousGamePadState.IsButtonDown(button) && CurrentGamePadState.IsButtonUp(button));
 }