diff --git a/src/main.zig b/src/main.zig index 67995ed..e5e7484 100644 --- a/src/main.zig +++ b/src/main.zig @@ -6,9 +6,9 @@ test { _ = g; } -pub fn main() anyerror!void { +pub fn main() !void { const allocator = std.heap.page_allocator; - const scaleFactor = 40; + const scaleFactor = 30; var game = try g.Game.create(allocator); defer game.deinit(); @@ -23,6 +23,12 @@ pub fn main() anyerror!void { const fastTickInterval: f32 = tickInterval / 3.0; var tickTimer: f32 = 0; + const fontSize = 50; + const gameOverText = "Game Over!"; + const gameOverTextWidth = rl.measureText(gameOverText, fontSize); + const youWinText = "You Win!"; + const youWinTextWidth = rl.measureText(youWinText, fontSize); + while (!rl.windowShouldClose()) { const deltaTime = rl.getFrameTime(); tickTimer += deltaTime; @@ -63,15 +69,16 @@ pub fn main() anyerror!void { rl.drawRectangle(game.food[0] * scaleFactor, game.food[1] * scaleFactor, scaleFactor, scaleFactor, .red); // Snake - for (game.body.items) |part| { - rl.drawRectangle(part[0] * scaleFactor, part[1] * scaleFactor, scaleFactor, scaleFactor, .green); + for (game.body.items, 0..) |part, i| { + const color: rl.Color = if (i == 0) .green else .dark_green; + rl.drawRectangle(part[0] * scaleFactor, part[1] * scaleFactor, scaleFactor, scaleFactor, color); } if (game.state == g.State.lost) { - rl.drawText("Game Over!", 150, 200, 20, .light_gray); + rl.drawText(gameOverText, @divTrunc(screenWidth - gameOverTextWidth, 2), @divTrunc(screenHeight - fontSize, 2), fontSize, .dark_gray); } if (game.state == g.State.won) { - rl.drawText("You Win!", 150, 200, 20, .light_gray); + rl.drawText(youWinText, @divTrunc(screenWidth - youWinTextWidth, 2), @divTrunc(screenHeight - fontSize, 2), fontSize, .dark_gray); } } }