Esempio n. 1
0
 /// <summary>
 /// Checks if key is held this frame.
 /// </summary>
 /// <returns>If a bind is tapped.</returns>
 public bool IsBindTapped()
 {
     if (singleKeyBind)
     {
         if (KeyboardManager.IsTyping)
         {
             if (KeyboardManager.GetIfIgnoreKey(keys[0]))
             {
                 return(false);
             }
         }
         return(KeyboardManager.IsTapped(keys[0]));
     }
     else
     {
         for (int i = 0; i < keys.Length; i++)
         {
             if (KeyboardManager.IsTyping)
             {
                 if (KeyboardManager.GetIfIgnoreKey(keys[i]))
                 {
                     return(false);
                 }
             }
             if (KeyboardManager.IsTapped(keys[i]))
             {
                 return(true);
             }
         }
     }
     return(false);
 }
Esempio n. 2
0
        void _checkKeys(IGameTimeService gameTime)
        {
            if (PlayerPilot == null || PlayerPilot.PilotType != PilotType.Player)
            {
                return;//This is a semi ugly hack to enable bot clients for stress testing.
            }


            if (KeyboardManager.EnterMode.IsBindTapped() || GamepadManager.EnterMode.IsBindTapped())
            {
                if (PlayerShip.EnterMode == false)
                {
                    PlayerShip.EnterMode = true;
                }
                else
                {
                    PlayerShip.EnterMode = false;
                }
            }

#if ADMIN
            if (KeyboardManager.SetPosTo0.IsBindTapped())
            {
                PlayerShip.Position = new Microsoft.Xna.Framework.Vector2(0, 0);
            }
            if (KeyboardManager.AdminMoveDown.IsBindPressed())
            {
                Vector2 oldPos = PlayerShip.Position;
                Vector2 newPos = new Vector2(oldPos.X, oldPos.Y + 1);
                PlayerShip.Position = newPos;
            }
            if (KeyboardManager.AdminMoveUp.IsBindPressed())
            {
                Vector2 oldPos = PlayerShip.Position;
                Vector2 newPos = new Vector2(oldPos.X, oldPos.Y - 1);
                PlayerShip.Position = newPos;
            }
            if (KeyboardManager.AdminMoveLeft.IsBindPressed())
            {
                Vector2 oldPos = PlayerShip.Position;
                Vector2 newPos = new Vector2(oldPos.X - 1, oldPos.Y);
                PlayerShip.Position = newPos;
            }
            if (KeyboardManager.AdminMoveRight.IsBindPressed())
            {
                Vector2 oldPos = PlayerShip.Position;
                Vector2 newPos = new Vector2(oldPos.X + 1, oldPos.Y);
                PlayerShip.Position = newPos;
            }
#endif


            Ship playerShip = PlayerShip;


            if (PlayerShip != null && PlayerShip.Pilot.IsAlive)
            {
                PlayerPilot playerPilot = (PlayerPilot)playerShip.Pilot;

                #region Movement

                if (KeyboardManager.HoldPlayerPosition.IsBindTapped() || GamepadManager.HoldPlayerPosition.IsBindTapped())
                {
                    playerPilot.HoldingPosition = true;
                }

                if (playerPilot.HoldingPosition)
                {
                    playerPilot.StopShip(gameTime);
                }

                if (KeyboardManager.TurnLeft.IsBindPressed() || GamepadManager.TurnLeft.IsBindPressed())
                {
                    playerShip.IsTurningCounterClockwise = true;
                    playerPilot.HoldingPosition          = false;
                }
                else
                {
                    playerShip.IsTurningCounterClockwise = false;
                }
                if (KeyboardManager.TurnRight.IsBindPressed() || GamepadManager.TurnRight.IsBindPressed())
                {
                    playerShip.IsTurningClockwise = true;
                    playerPilot.HoldingPosition   = false;
                }
                else
                {
                    playerShip.IsTurningClockwise = false;
                }

                if (KeyboardManager.ThrustUp.IsBindPressed() || GamepadManager.ThrustUp.IsBindPressed())
                {
                    if (KeyboardManager.Boost.IsBindPressed() || GamepadManager.Boost.IsBindPressed()) //If boosting
                    {
                        playerShip.Thrust(ThrustTypes.BoostForward);
                    }
                    else //If not boosting
                    {
                        playerShip.Thrust(ThrustTypes.Forward);
                    }
                    playerShip.Thrusting        = true;
                    playerPilot.HoldingPosition = false;
                }
                else if (KeyboardManager.ThrustDown.IsBindPressed() || GamepadManager.ThrustDown.IsBindPressed())
                {
                    if (KeyboardManager.Boost.IsBindPressed() || GamepadManager.Boost.IsBindPressed())
                    {
                        playerShip.Thrust(ThrustTypes.BoostBackward);
                    }
                    else
                    {
                        playerShip.Thrust(ThrustTypes.Backward);
                    }
                    playerShip.Thrusting        = true;
                    playerPilot.HoldingPosition = false;
                }
                else if (KeyboardManager.ThrustLateralLeft.IsBindPressed())
                {
                    if (KeyboardManager.Boost.IsBindPressed() || GamepadManager.Boost.IsBindPressed())
                    {
                        playerShip.Thrust(ThrustTypes.BoostLeftLateral);
                    }
                    else
                    {
                        playerShip.Thrust(ThrustTypes.LeftLateral);
                    }
                    playerShip.Thrusting        = true;
                    playerPilot.HoldingPosition = false;
                }
                else if (KeyboardManager.ThrustLateralRight.IsBindPressed())
                {
                    if (KeyboardManager.Boost.IsBindPressed() || GamepadManager.Boost.IsBindPressed())
                    {
                        playerShip.Thrust(ThrustTypes.BoostRightLateral);
                    }
                    else
                    {
                        playerShip.Thrust(ThrustTypes.RightLateral);
                    }
                    playerShip.Thrusting        = true;
                    playerPilot.HoldingPosition = false;
                }
                else
                {
                    playerShip.Thrusting = false;
                }

                #endregion

                #region Firing Weapons

                if (KeyboardManager.FireWeapon1.IsBindPressed() || GamepadManager.FirePrimary.IsBindPressed())
                {
                    _weaponPressed(1, gameTime, PlayerShip, (PlayerPilot)PlayerShip.Pilot);
                }
                else
                {
                    _weaponNotPressed(1, gameTime, PlayerShip);
                }

                if (KeyboardManager.FireWeapon2.IsBindPressed() || GamepadManager.FirePrimary.IsBindPressed())
                {
                    _weaponPressed(2, gameTime, PlayerShip, (PlayerPilot)PlayerShip.Pilot);
                }
                else
                {
                    _weaponNotPressed(2, gameTime, PlayerShip);
                }

                if (KeyboardManager.FireWeapon3.IsBindPressed() || GamepadManager.FirePrimary.IsBindPressed())
                {
                    _weaponPressed(3, gameTime, PlayerShip, (PlayerPilot)PlayerShip.Pilot);
                }
                else
                {
                    _weaponNotPressed(3, gameTime, PlayerShip);
                }

                if (KeyboardManager.FireWeapon4.IsBindPressed() || GamepadManager.FirePrimary.IsBindPressed())
                {
                    _weaponPressed(4, gameTime, PlayerShip, (PlayerPilot)PlayerShip.Pilot);
                }
                else
                {
                    _weaponNotPressed(4, gameTime, PlayerShip);
                }

                if (KeyboardManager.FireWeapon5.IsBindPressed() || GamepadManager.FirePrimary.IsBindPressed())
                {
                    _weaponPressed(5, gameTime, PlayerShip, (PlayerPilot)PlayerShip.Pilot);
                }
                else
                {
                    _weaponNotPressed(5, gameTime, PlayerShip);
                }



                if (KeyboardManager.FireMissile.IsBindTapped() || GamepadManager.FireMissile.IsBindTapped())
                {
                    playerShip.TryFireWeapon(gameTime, 0);
                    playerPilot.HoldingPosition = false;
                }

                if (KeyboardManager.SwitchMissile.IsBindTapped())//probably debug
                {
                    playerShip.MissileLauncher.SetMissileType(Debugging.MissileTypes.GetCurrentMoveNext());
                }


                #endregion
            }


            if (KeyboardManager.IsTapped(Keys.K))
            {
                PlayerShip.Kill();
            }


            if (KeyboardManager.IsTapped(Keys.R))
            {
                PlayerShip.Revive(10000, 10000);
            }
        }