From 78ae9005bfc32beb66d9762cbfa48fe2c9d299b5 Mon Sep 17 00:00:00 2001 From: Jonathan Marler Date: Wed, 3 Mar 2021 11:53:46 -0700 Subject: [PATCH] scale the camera to keep the banana in view --- src/game.zig | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/game.zig b/src/game.zig index 4ded522..c81d587 100644 --- a/src/game.zig +++ b/src/game.zig @@ -512,8 +512,19 @@ fn drawGameplay(self: Game) void { nvg.save(); defer nvg.restore(); - const s = self.width / world_width; - nvg.translate(0, self.height - s * world_height); + var s = self.width / world_width; + + // the y location where the camera starts scaling to follow the banana + const banana_threshold_y: f32 = 100; + var translate_x: f32 = 0; + if (self.banana_flying and self.banana_y < banana_threshold_y) { + const past_threshold = banana_threshold_y - self.banana_y; + const scale_ratio = 1 + (past_threshold / world_height); + s = s / scale_ratio; + translate_x = (self.width - s * world_width) / 2; + } + + nvg.translate(translate_x, self.height - s * world_height); nvg.scale(s, s); const screenshake = @sin(self.screenshake_frequency * @intToFloat(f32, self.frame)) * self.screenshake_amplitude; nvg.translate(screenshake, 0);