From 9c5252fe3b307c288c96db29760b971ce0aaefcc Mon Sep 17 00:00:00 2001 From: Sander Schobers Date: Mon, 5 Jun 2023 02:09:13 +0200 Subject: [PATCH] Added collision check to the right side (only implemented to the left side intially). Bounce of the ceiling is abit less aggressive. --- src/game/game.zig | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/game/game.zig b/src/game/game.zig index fc759b0..0c5150d 100644 --- a/src/game/game.zig +++ b/src/game/game.zig @@ -89,7 +89,7 @@ pub const Game = struct { self.playerVelocity.y = 0; } else if (self.playerVelocity.y < 0 and self.playerIsUnderTile()) { self.playerPosition.y = std.math.ceil(self.playerPosition.y); - self.playerVelocity.y = -self.playerVelocity.y; + self.playerVelocity.y = 0.1; } if (self.playerVelocity.x != 0) { const playerTileTop = @floatToInt(i64, std.math.floor(self.playerPosition.y)); @@ -101,7 +101,13 @@ pub const Game = struct { self.playerVelocity.x = 0; } } - // const playerTileRight = @floatToInt(i64, std.math.floor(self.playerPosition.x)) + 1; + if (self.playerVelocity.x > 0) { + const playerTileRight = @floatToInt(i64, std.math.floor(self.playerPosition.x)) + 1; + if (self.level.tiles.get(playerTileRight, playerTileTop) != null or self.level.tiles.get(playerTileRight, playerTileBottom) != null) { + self.playerPosition.x = std.math.floor(self.playerPosition.x); + self.playerVelocity.x = 0; + } + } } self.playerDirection = if (self.playerVelocity.x == 0) self.playerDirection else if (self.playerVelocity.x > 0) Direction.Right else Direction.Left;