summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKyren223 <Kyren223@proton.me>2025-07-26 23:24:52 +0300
committerKyren223 <Kyren223@proton.me>2025-07-26 23:24:52 +0300
commit869eb06a6d37b3ea63cca4ed984b2ecd9cfe554f (patch)
tree65a1396d62a804f8ae71fb235820629b6b7e56e3
parent29fdb44b02bc8e65a16817ef372e220ab6b8cd13 (diff)
Fixed game over menu being uncentered
-rw-r--r--src/main.zig24
1 files changed, 24 insertions, 0 deletions
diff --git a/src/main.zig b/src/main.zig
index 11b690a..7849b1c 100644
--- a/src/main.zig
+++ b/src/main.zig
@@ -798,6 +798,30 @@ const ScreenGameOver = struct {
if (self.pressed_menu) {
game.screen_state = .{ .main = .init() };
}
+
+ self.updateCamera();
+ }
+
+ fn updateCamera(self: *ScreenGameOver) void {
+ screen_width = rl.getScreenWidth();
+ screen_height = rl.getScreenHeight();
+
+ self.camera.offset = .{
+ .x = @as(f32, @floatFromInt(screen_width)) / 2,
+ .y = @as(f32, @floatFromInt(screen_height)) / 2,
+ };
+
+ self.camera.target = .{
+ .x = world_width / 2.0,
+ .y = world_height / 2.0,
+ };
+
+ // Take the average between the ratios
+ // This avoids "cheating" by changing the ratio to an extreme value
+ // in order to see more terrain in a certain axis
+ const width_ratio = @as(f32, @floatFromInt(screen_width)) / world_width;
+ const height_ratio = @as(f32, @floatFromInt(screen_height)) / world_height;
+ self.camera.zoom = (width_ratio + height_ratio) / 2;
}
fn render(self: *ScreenGameOver, game: *Game) void {