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;