restarting added

This commit is contained in:
maxwes08
2025-11-04 09:05:25 +01:00
parent f4deaadb57
commit 9d8b31f0f0

View File

@@ -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<Pillar> pillars = new List<Pillar>();
@@ -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;
}
}
// Scroll background
backgroundOffset += (long)(scrollSpeed * deltaTime * backgroundSpeed);
@@ -209,3 +227,4 @@ internal class Program
}
}
}