Added a simple player input class to test abstraction.

This commit is contained in:
J. M. Ellis
2024-05-24 16:40:43 -07:00
parent ff0e593bbc
commit 6142263150
+24 -3
View File
@@ -21,6 +21,11 @@ namespace LunaLightXMG
Texture2D sprCave1_foreground; Texture2D sprCave1_foreground;
Texture2D sprCave1_walls; Texture2D sprCave1_walls;
// Test player input and movement with abstracted player input class
private PlayerInput playerInput;
private Vector2 objectPosition;
private float movementSpeed = 100f; // Movement speed in pixels per second
// Native retro scale // Native retro scale
private int retroWidth = 320; private int retroWidth = 320;
private int retroHeight = 180; private int retroHeight = 180;
@@ -31,9 +36,12 @@ namespace LunaLightXMG
Content.RootDirectory = "Content"; Content.RootDirectory = "Content";
IsMouseVisible = true; IsMouseVisible = true;
Window.ClientSizeChanged += OnClientSizeChanged; // Jensen can implement Window.ClientSizeChanged += OnClientSizeChanged;
Window.AllowUserResizing = true; Window.AllowUserResizing = true;
IsMouseVisible = true; IsMouseVisible = true;
// Test player input and movement with abstracted player input class
playerInput = new PlayerInput();
} }
private void OnClientSizeChanged(object sender, EventArgs eventArgs) private void OnClientSizeChanged(object sender, EventArgs eventArgs)
@@ -53,6 +61,9 @@ namespace LunaLightXMG
graphics.PreferredBackBufferHeight = 1080; graphics.PreferredBackBufferHeight = 1080;
graphics.ApplyChanges(); graphics.ApplyChanges();
// Test player input and movement with abstracted player input class
objectPosition = new Vector2(163, 63); // Initial position
base.Initialize(); base.Initialize();
CalculateRenderDestination(); // Jensen can implement CalculateRenderDestination(); // Jensen can implement
} }
@@ -89,7 +100,14 @@ namespace LunaLightXMG
if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape)) if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape))
Exit(); Exit();
// TODO: Add your update logic here playerInput.Update();
// Test player input and movement with abstracted player input class
// Update the object's position based on input
float deltaTime = (float)gameTime.ElapsedGameTime.TotalSeconds;
objectPosition = playerInput.MoveWithWASD(objectPosition, movementSpeed * deltaTime);
base.Update(gameTime); base.Update(gameTime);
} }
@@ -105,7 +123,10 @@ namespace LunaLightXMG
spriteBatch.Begin(samplerState: SamplerState.PointClamp); spriteBatch.Begin(samplerState: SamplerState.PointClamp);
// Draw sprites here // Draw sprites here
spriteBatch.Draw(sprCave1_background,new Vector2(0,0),Color.White); spriteBatch.Draw(sprCave1_background,new Vector2(0,0),Color.White);
spriteBatch.Draw(sprRo, new Vector2(163, 63), Color.White);
// Test player input and movement with abstracted player input class
spriteBatch.Draw(sprRo, objectPosition, Color.White);
spriteBatch.Draw(sprCave1_walls, new Vector2(0, 0), Color.White); spriteBatch.Draw(sprCave1_walls, new Vector2(0, 0), Color.White);
spriteBatch.Draw(sprCave1_foreground, new Vector2(0, 0), Color.White); spriteBatch.Draw(sprCave1_foreground, new Vector2(0, 0), Color.White);
spriteBatch.End(); spriteBatch.End();