mirror of
https://github.com/TheRavenwoodArts/LunaLightXMG.git
synced 2026-07-30 22:55:03 -07:00
Adding player input class.
This commit is contained in:
@@ -0,0 +1,41 @@
|
|||||||
|
using Microsoft.Xna.Framework;
|
||||||
|
using Microsoft.Xna.Framework.Input;
|
||||||
|
|
||||||
|
namespace LunaLightXMG
|
||||||
|
{
|
||||||
|
internal class PlayerInput
|
||||||
|
{
|
||||||
|
// Field to store the current keyboard state
|
||||||
|
private KeyboardState currentKeyboardState;
|
||||||
|
|
||||||
|
// Method to update the input state
|
||||||
|
public void Update()
|
||||||
|
{
|
||||||
|
currentKeyboardState = Keyboard.GetState();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Method to check if a key is currently held down
|
||||||
|
public bool IsKeyDown(Keys key)
|
||||||
|
{
|
||||||
|
return currentKeyboardState.IsKeyDown(key);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Method to check WASD movement keys
|
||||||
|
public Vector2 MoveWithWASD(Vector2 currentPosition, float speed)
|
||||||
|
{
|
||||||
|
Vector2 movement = Vector2.Zero;
|
||||||
|
|
||||||
|
if (IsKeyDown(Keys.W))
|
||||||
|
movement.Y -= speed;
|
||||||
|
if (IsKeyDown(Keys.A))
|
||||||
|
movement.X -= speed;
|
||||||
|
if (IsKeyDown(Keys.S))
|
||||||
|
movement.Y += speed;
|
||||||
|
if (IsKeyDown(Keys.D))
|
||||||
|
movement.X += speed;
|
||||||
|
|
||||||
|
return currentPosition + movement;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user