示例#1
0
 public static void Update()
 {
     if (Item != null)
     {
         if (KeyboardInput.KeyPressed(Keys.A))
         {
             Item.Rotation  -= (float)Math.PI / 2;
             Item.ItemBounds = Item.ItemBounds.RotateCounterClockwise();
         }
         if (KeyboardInput.KeyPressed(Keys.D))
         {
             Item.Rotation  += (float)Math.PI / 2;
             Item.ItemBounds = Item.ItemBounds.RotateClockwise();
         }
     }
 }
示例#2
0
        public void ControlPlayer(Player player)
        {
            player.Walking = false;

            if (KeyboardInput.KeyboardStateNew.IsKeyDown(Game1.STP.ControlKeys["Jump"]))
            {
                if (player.Resolver.InWater == true)
                {
                    player.Velocity = new Vector2(player.Velocity.X, -0.2f);
                }
            }

            if (KeyboardInput.KeyboardStateNew.IsKeyDown(Game1.STP.ControlKeys["Walk left"]) && KeyboardInput.KeyboardStateNew.IsKeyUp(Game1.STP.ControlKeys["Walk right"]))
            {
                player.Velocity -= new Vector2(player.Speed.X, 0);
                if (player.Velocity.X < -player.MaxSpeed.X)
                {
                    player.Velocity = new Vector2(-player.MaxSpeed.X, player.Velocity.Y);
                }

                if (player.Resolver.InWater == true)
                {
                    if (player.Resolver.TouchLeft == true)
                    {
                        player.Velocity = new Vector2(player.Velocity.X, -player.MaxSpeed.Y * 2);
                    }
                }

                player.Walking = true;
            }

            if (KeyboardInput.KeyboardStateNew.IsKeyDown(Game1.STP.ControlKeys["Walk right"]) && KeyboardInput.KeyboardStateNew.IsKeyUp(Game1.STP.ControlKeys["Walk left"]))
            {
                player.Velocity += new Vector2(player.Speed.X, 0);

                if (player.Velocity.X > player.MaxSpeed.X)
                {
                    player.Velocity = new Vector2(player.MaxSpeed.X, player.Velocity.Y);
                }

                if (player.Resolver.InWater == true)
                {
                    if (player.Resolver.TouchRight == true)
                    {
                        player.Velocity = new Vector2(player.Velocity.X, -player.MaxSpeed.Y * 2);
                    }
                }

                player.Walking = true;
            }

            if (KeyboardInput.KeyPressed(Game1.STP.ControlKeys["Jump"]))
            {
                if (player.Resolver.InWater == false)
                {
                    if (player.Resolver.TouchTop == true || player.Resolver.TouchTopMovable == true)
                    {
                        Game1.soundjump.Play();
                        player.Velocity = new Vector2(player.Velocity.X, -player.MaxSpeed.Y * 2);
                    }
                }
            }

            if (player.WeaponsAvailable == true)
            {
                if (MouseInput.ScrolledDown())
                {
                    player.PreviousWeapon();
                }

                if (MouseInput.ScrolledUp())
                {
                    player.NextWeapon();
                }
            }

            if (KeyboardInput.KeyPressed(Game1.STP.ControlKeys["Throw grenade"]))
            {
                if (player.WeaponsAvailable == true)
                {
                    ThrowGrenade(player);
                }
            }
        }