Added reset platforms.

This commit is contained in:
J. M. Ellis
2024-06-02 18:17:21 -07:00
parent d7f84ce34a
commit 6fb291dc73
3 changed files with 25 additions and 0 deletions
+15
View File
@@ -108,6 +108,9 @@ namespace LunaLightXMG
// Temporary quit game - eventually handle in a pause menu class // Temporary quit game - eventually handle in a pause menu class
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();
// Check for game reset
if (Keyboard.GetState().IsKeyDown(Keys.R))
ResetGame();
// Test player input and movement with abstracted player class // Test player input and movement with abstracted player class
playerInput.Update(); playerInput.Update();
@@ -236,5 +239,17 @@ namespace LunaLightXMG
{ {
return (float)(1 + 2 * random.NextDouble()); 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);
}
} }
} }
+4
View File
@@ -56,6 +56,7 @@ namespace LunaLightXMG
// Left side wall (static) // Left side wall (static)
List<Platform> leftSidePlatforms = new List<Platform> List<Platform> leftSidePlatforms = new List<Platform>
{ {
new Platform(new Vector2(0, -28), 16, 16),
new Platform(new Vector2(0, -12), 16, 16), new Platform(new Vector2(0, -12), 16, 16),
new Platform(new Vector2(0, 4), 16, 16), new Platform(new Vector2(0, 4), 16, 16),
new Platform(new Vector2(0, 20), 16, 16), new Platform(new Vector2(0, 20), 16, 16),
@@ -72,6 +73,7 @@ namespace LunaLightXMG
// Right side wall (static) // Right side wall (static)
List<Platform> rightSidePlatforms = new List<Platform> List<Platform> rightSidePlatforms = new List<Platform>
{ {
new Platform(new Vector2(304, -28), 16, 16),
new Platform(new Vector2(304, -12), 16, 16), new Platform(new Vector2(304, -12), 16, 16),
new Platform(new Vector2(304, 4), 16, 16), new Platform(new Vector2(304, 4), 16, 16),
new Platform(new Vector2(304, 20), 16, 16), new Platform(new Vector2(304, 20), 16, 16),
@@ -100,6 +102,8 @@ namespace LunaLightXMG
{ {
List<Platform> platforms = new List<Platform>(); List<Platform> platforms = new List<Platform>();
platforms.Add(new Platform(new Vector2(16, 132), 16, 16)); 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)); platforms.Add(new Platform(new Vector2(288, 132), 16, 16));
for (int i = 0; i < numberOfPlatforms; i++) for (int i = 0; i < numberOfPlatforms; i++)
+6
View File
@@ -74,6 +74,12 @@ namespace LunaLightXMG
} }
// Method Implementation ------------------------------------------------------------------------------- // Method Implementation -------------------------------------------------------------------------------
public void Reset(Vector2 initialPosition)
{
position = initialPosition;
// Reset other player-specific states later
}
private void Movement(PlayerInput input) private void Movement(PlayerInput input)
{ {
if (input.KeyJump && grounded) if (input.KeyJump && grounded)