Started work on Player.cs class, converted our OG movement script to C# and implemented as a method in Player class.

This commit is contained in:
J. M. Ellis
2024-05-24 17:48:52 -07:00
parent 7dc1f166ab
commit 34e2d6e6d6
3 changed files with 141 additions and 61 deletions
-41
View File
@@ -1,41 +0,0 @@
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;
}
}
}