From 614226315057d0f25eebd7e006037ddf40e07e26 Mon Sep 17 00:00:00 2001 From: "J. M. Ellis" Date: Fri, 24 May 2024 16:40:43 -0700 Subject: [PATCH] Added a simple player input class to test abstraction. --- Game1.cs | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/Game1.cs b/Game1.cs index b378f3e..9a21ddf 100644 --- a/Game1.cs +++ b/Game1.cs @@ -21,6 +21,11 @@ namespace LunaLightXMG Texture2D sprCave1_foreground; 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 private int retroWidth = 320; private int retroHeight = 180; @@ -31,9 +36,12 @@ namespace LunaLightXMG Content.RootDirectory = "Content"; IsMouseVisible = true; - Window.ClientSizeChanged += OnClientSizeChanged; // Jensen can implement + Window.ClientSizeChanged += OnClientSizeChanged; Window.AllowUserResizing = true; IsMouseVisible = true; + + // Test player input and movement with abstracted player input class + playerInput = new PlayerInput(); } private void OnClientSizeChanged(object sender, EventArgs eventArgs) @@ -53,6 +61,9 @@ namespace LunaLightXMG graphics.PreferredBackBufferHeight = 1080; graphics.ApplyChanges(); + // Test player input and movement with abstracted player input class + objectPosition = new Vector2(163, 63); // Initial position + base.Initialize(); CalculateRenderDestination(); // Jensen can implement } @@ -89,7 +100,14 @@ namespace LunaLightXMG if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape)) 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); } @@ -105,7 +123,10 @@ namespace LunaLightXMG spriteBatch.Begin(samplerState: SamplerState.PointClamp); // Draw sprites here 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_foreground, new Vector2(0, 0), Color.White); spriteBatch.End();