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(); } } }
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); } } }
public bool Update() { _textOld = Text; if (MouseInput.MouseClickedLeft() == true) { if (CompareF.RectangleVsVector2(_boundary, MouseInput.MouseRealPosMenu()) == true) { IsActive = true; _cursor = (int)Math.Round(MouseInput.MouseRealPosMenu().X - _boundary.Position.X) / 16; if (_cursor > Text.Length) { _cursor = Text.Length; } if (_cursor < 0) { _cursor = 0; } MakeVisible(); } else { IsActive = false; MakeVisible(); } } if (IsActive == true) { keys = KeyboardInput.GetPressedKeys(); _backSpace.Update(); _left.Update(); _right.Update(); _blink.Update(); if (_blink.Ready == true) { _cursorVisible = !_cursorVisible; _blink.Reset(); } foreach (Keys key in keys) { int number = (int)key; if (_type == textBoxType.text || _type == textBoxType.fileName) { if (number >= 65 && number <= 90) { if (_cursor <= Text.Length) { Text = Text.Insert(_cursor + _offset, key.ToString()); CursorAdd(); MakeVisible(); } } if (key == Keys.Space) { if (_cursor <= Text.Length) { Text = Text.Insert(_cursor + _offset, " "); CursorAdd(); MakeVisible(); } } } if (number >= 96 && number <= 105) { if (_cursor <= Text.Length) { Text = Text.Insert(_cursor + _offset, (number - 96).ToString()); CursorAdd(); MakeVisible(); } } if (number >= 48 && number <= 57) { if (_cursor <= Text.Length) { Text = Text.Insert(_cursor + _offset, (number - 48).ToString()); CursorAdd(); MakeVisible(); } } if (key == Keys.OemMinus || key == Keys.Subtract) { if (_cursor <= Text.Length) { Text = Text.Insert(_cursor + _offset, "-"); CursorAdd(); MakeVisible(); } } } if (KeyboardInput.KeyboardStateNew.IsKeyDown(Keys.Back) == true && KeyboardInput.KeyboardStateOld.IsKeyDown(Keys.Back) == true) { if (_backSpace.Ready == true) { if (_cursor > 0 || _offset > 0) { Text = Text.Remove(_cursor - 1 + _offset, 1); MakeVisible(); _backSpace.Reset(); } if (_offset > 0) { _offset--; } else if (_cursor > 0) { _cursor--; } } } if (KeyboardInput.KeyboardStateNew.IsKeyDown(Keys.Left) == true && KeyboardInput.KeyboardStateOld.IsKeyDown(Keys.Left) == true) { if (_left.Ready == true) { if (_cursor > 0) { _cursor--; } else if (_offset > 0) { _offset--; } MakeVisible(); _left.Reset(); } } if (KeyboardInput.KeyboardStateNew.IsKeyDown(Keys.Right) == true && KeyboardInput.KeyboardStateOld.IsKeyDown(Keys.Right) == true) { if (_right.Ready == true) { if (_cursor < Text.Length) { if (_cursor < (int)((_boundary.Size.X - 16) / 16)) { _cursor++; } else if (_offset < Text.Length - (int)((_boundary.Size.X - 16) / 16)) { _offset++; } } MakeVisible(); _right.Reset(); } } } int i = 0; Parsed = int.TryParse(Text, out i); Valid = true; if ((Text.IndexOfAny(Path.GetInvalidFileNameChars()) != -1 && _type == textBoxType.fileName) || Text == "") { Valid = false; } if (_type == textBoxType.number && Parsed == true && (i < _min || i > _max)) { Valid = false; } if (Parsed == false && _type == textBoxType.number) { Valid = false; } if (_changeMehod != null) { _changeMehod?.Invoke(); return(true); } else { return(false); } }