/* * * * * * * * * * * PARTIE CONTROLS * * * * * * * * * * */ void PlayerControls() { int HorizontalMovement = 0; int VerticalMovement = 0; PlayerInstance.Velocity = new Vector3(0, 0, 0); bool HoveringUI = false; foreach (var v in GameScreenGum.ContainedElements) { if (v.HasCursorOver(FlatRedBall.Gui.GuiManager.Cursor)) { HoveringUI = true; break; } } if (InputManager.Keyboard.KeyPushed(Keys.Tab)) { ToggleInventory(); } if (InputManager.Mouse.ButtonPushed(FlatRedBall.Input.Mouse.MouseButtons.LeftButton)) { if (!HoveringUI) { //Vector between the Cursor position, relative to world, and the player. Vector2 PlayerToMouse = new Vector2( InputManager.Mouse.WorldXAt(0), InputManager.Mouse.WorldYAt(0)) - new Vector2(PlayerInstance.Position.X, PlayerInstance.Position.Y); //We then normalize (reduce the length to 1 but keeping the direction) PlayerToMouse.Normalize(); //Tell the player to attack. Player class will determine wether it's ok or not PlayerInstance.Attack(PlayerToMouse); } } if (InputManager.Keyboard.KeyDown(Keys.Z)) { PlayerInstance.MoveUp(); } else if (InputManager.Keyboard.KeyDown(Keys.S)) { PlayerInstance.MoveDown(); } if (InputManager.Keyboard.KeyDown(Keys.Q)) { PlayerInstance.MoveLeft(); } else if (InputManager.Keyboard.KeyDown(Keys.D)) { PlayerInstance.MoveRight(); } if (InputManager.Keyboard.KeyPushed(Keys.E)) { if (Vector3.Distance(PlayerInstance.Position, PlayerBoat.Position) < 32) { PlayerInstance.Visible = false; DezoomCamera(); ControlMethod = BoatControls; EntityToFollowByCam = PlayerBoat; } } InventoryBarControls(); }