From c592e32bb37accfe83c36a68f7d4e674f6f9ae25 Mon Sep 17 00:00:00 2001 From: Tim Wundenberg Date: Fri, 27 Feb 2026 21:51:05 +0100 Subject: [PATCH] refine gameplay --- src/main.zig | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/src/main.zig b/src/main.zig index 9762425..af6f09b 100644 --- a/src/main.zig +++ b/src/main.zig @@ -21,7 +21,8 @@ pub fn main() !void { const tickInterval: f32 = 0.5; const fastTickInterval: f32 = tickInterval / 3.0; - var tickTimer: f32 = 0; + var timer: f32 = 0; + var isFast = false; const fontSize = 50; const gameOverText = "Game Over!"; @@ -31,7 +32,7 @@ pub fn main() !void { while (!rl.windowShouldClose()) { const deltaTime = rl.getFrameTime(); - tickTimer += deltaTime; + timer += deltaTime; if (rl.isKeyPressed(.up)) { game.setDirection(g.Direction.up); @@ -45,10 +46,17 @@ pub fn main() !void { if (rl.isKeyPressed(.left)) { game.setDirection(g.Direction.left); } - - const currentInterval = if (rl.isKeyDown(.s)) fastTickInterval else tickInterval; - if (tickTimer >= currentInterval) { - tickTimer -= currentInterval; + if (rl.isKeyDown(.s)) { + if (!isFast) { + isFast = true; + timer = 0; + } + } else { + isFast = false; + } + const interval = if (isFast) fastTickInterval else tickInterval; + if (timer >= interval) { + timer -= interval; try game.tick(); }