From 6fb291dc73ceb3b86c5cda9ce7418e3e9683be1b Mon Sep 17 00:00:00 2001 From: "J. M. Ellis" Date: Sun, 2 Jun 2024 18:17:21 -0700 Subject: [PATCH] Added reset platforms. --- Game1.cs | 15 +++++++++++++++ Platform.cs | 4 ++++ Player.cs | 6 ++++++ 3 files changed, 25 insertions(+) diff --git a/Game1.cs b/Game1.cs index 5bb15ff..9df03a5 100644 --- a/Game1.cs +++ b/Game1.cs @@ -108,6 +108,9 @@ namespace LunaLightXMG // Temporary quit game - eventually handle in a pause menu class if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape)) Exit(); + // Check for game reset + if (Keyboard.GetState().IsKeyDown(Keys.R)) + ResetGame(); // Test player input and movement with abstracted player class playerInput.Update(); @@ -236,5 +239,17 @@ namespace LunaLightXMG { return (float)(1 + 2 * random.NextDouble()); } + private void ResetGame() + { + // Reset player position + player.Reset(new Vector2(163, 0)); + + // Clear and respawn enemies + enemies.Clear(); + enemies = SpawnEnemies(10); + + // Regenerate platforms + platforms = PlatformGenerator.CreatePlatforms(6); + } } } diff --git a/Platform.cs b/Platform.cs index 6c6972c..baa2155 100644 --- a/Platform.cs +++ b/Platform.cs @@ -56,6 +56,7 @@ namespace LunaLightXMG // Left side wall (static) List leftSidePlatforms = new List { + new Platform(new Vector2(0, -28), 16, 16), new Platform(new Vector2(0, -12), 16, 16), new Platform(new Vector2(0, 4), 16, 16), new Platform(new Vector2(0, 20), 16, 16), @@ -72,6 +73,7 @@ namespace LunaLightXMG // Right side wall (static) List rightSidePlatforms = new List { + new Platform(new Vector2(304, -28), 16, 16), new Platform(new Vector2(304, -12), 16, 16), new Platform(new Vector2(304, 4), 16, 16), new Platform(new Vector2(304, 20), 16, 16), @@ -100,6 +102,8 @@ namespace LunaLightXMG { List platforms = new List(); platforms.Add(new Platform(new Vector2(16, 132), 16, 16)); + platforms.Add(new Platform(new Vector2(144, 132), 16, 16)); + platforms.Add(new Platform(new Vector2(160, 132), 16, 16)); platforms.Add(new Platform(new Vector2(288, 132), 16, 16)); for (int i = 0; i < numberOfPlatforms; i++) diff --git a/Player.cs b/Player.cs index 8a6ced2..c01fd4c 100644 --- a/Player.cs +++ b/Player.cs @@ -74,6 +74,12 @@ namespace LunaLightXMG } // Method Implementation ------------------------------------------------------------------------------- + public void Reset(Vector2 initialPosition) + { + position = initialPosition; + // Reset other player-specific states later + } + private void Movement(PlayerInput input) { if (input.KeyJump && grounded)