From 9d8b31f0f0f8c595723e6020c85bf0057e3f2919 Mon Sep 17 00:00:00 2001 From: maxwes08 Date: Tue, 4 Nov 2025 09:05:25 +0100 Subject: [PATCH] restarting added --- Program.cs | 33 ++++++++++++++++++++++++++------- 1 file changed, 26 insertions(+), 7 deletions(-) diff --git a/Program.cs b/Program.cs index a1db4c8..504d08b 100644 --- a/Program.cs +++ b/Program.cs @@ -10,13 +10,15 @@ internal class Program uint gameWidth = 900; uint gameHeight = 504; float gravity = 800f; // px/sec^2 - float jumpForce = -300f; // px/sec - float scrollSpeed = 150f; // px/sec + float jumpForce = -300f; + float scrollSpeedInitial = 150f;// px/sec + float scrollSpeed = scrollSpeedInitial; // px/sec float scrollDecay = 500f; // px/sec^2 float maxUpAngle = -30f; // tilt up max float maxDownAngle = 60f; // tilt down max float maxVelocity = 500f; // velocity that corresponds to max tilt float backgroundSpeed = 0.75f; + int points = 0; // Pillars List pillars = new List(); @@ -99,6 +101,17 @@ internal class Program // Clock for deltaTime Clock clock = new Clock(); + void Restart() + { + birdVelocity = 0; + pillars.Clear(); + bird.Position = new Vector2f(100, gameHeight / 2f); + backgroundOffset = 0; + alive = true; + scrollSpeed = scrollSpeedInitial; + points = 0; + } + while (window.IsOpen) { float deltaTime = clock.Restart().AsSeconds(); @@ -140,6 +153,11 @@ internal class Program birdVelocity = jumpForce; } + if (!alive && Keyboard.IsKeyPressed(Keyboard.Key.Space)) + { + Restart(); + } + // Update pillars pillarTimer += deltaTime; if (pillarTimer > spawnInterval) @@ -177,11 +195,11 @@ internal class Program } if (!alive) -{ - // Gradually reduce speed towards 0 - scrollSpeed -= scrollDecay * deltaTime; - if (scrollSpeed < 0) scrollSpeed = 0; -} + { + // Gradually reduce speed towards 0 + scrollSpeed -= scrollDecay * deltaTime; + if (scrollSpeed < 0) scrollSpeed = 0; + } // Scroll background backgroundOffset += (long)(scrollSpeed * deltaTime * backgroundSpeed); @@ -209,3 +227,4 @@ internal class Program } } } + \ No newline at end of file