Brought over our player input code from GML into a PlayerInput.cs class.

This commit is contained in:
J. M. Ellis
2024-05-24 20:21:01 -07:00
parent b92de57435
commit 9ccb35f2ad
3 changed files with 126 additions and 20 deletions
+4 -18
View File
@@ -1,7 +1,6 @@
using System;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
namespace LunaLightXMG
{
@@ -26,10 +25,6 @@ namespace LunaLightXMG
// Player position
public Vector2 Position;
// Placeholder for key input states
private bool keyLeft;
private bool keyRight;
// Constructor to initialize variables
public Player()
{
@@ -54,24 +49,23 @@ namespace LunaLightXMG
}
// Update method to handle movement logic
public void Update(GameTime gameTime)
public void Update(GameTime gameTime, PlayerInput input)
{
HandleInput();
Movement();
Movement(input);
// Update player position based on speed
Position.X += hsp;
Position.Y += vsp;
}
private void Movement()
private void Movement(PlayerInput input)
{
// Horizontal movement with acceleration + wall jump delay
wallJumpDelay = Math.Max(wallJumpDelay - 1, 0); // counts down every frame
if (wallJumpDelay == 0) // no left-right control until delay is 0, prevents rapid wall climb
{
float moveH = (keyRight ? 1 : 0) - (keyLeft ? 1 : 0);
float moveH = input.KeyRight - input.KeyLeft;
hsp += moveH * hspAcc;
if (moveH == 0)
@@ -115,14 +109,6 @@ namespace LunaLightXMG
return start;
}
// Placeholder for key input handling (to be connected to actual input handling logic)
private void HandleInput()
{
KeyboardState keyboardState = Keyboard.GetState();
keyLeft = keyboardState.IsKeyDown(Keys.A);
keyRight = keyboardState.IsKeyDown(Keys.D);
}
public void Draw(SpriteBatch spriteBatch, Texture2D texture)
{
spriteBatch.Draw(texture, Position, Color.White);