From 1842253f85333b99d43c279fbab05d4c7241e1a3 Mon Sep 17 00:00:00 2001 From: Simon Cambier Date: Mon, 7 Apr 2025 13:37:19 +0200 Subject: [PATCH] replaced ternaries with ifs --- aabb2.p8 | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/aabb2.p8 b/aabb2.p8 index f814b05..5e5c9e7 100644 --- a/aabb2.p8 +++ b/aabb2.p8 @@ -18,26 +18,34 @@ local player = { -- collision left if self.dx < 0 and (isColliding(self.x + self.dx, self.y) or isColliding(self.x + self.dx, self.y + 7)) then - -- move the player against the left wall - self.x = self.x % 8 == 0 and self.x or flr(self.x / 8) * 8 + -- move the player against the left wall, if our x coord isn't already a multiple of 8 + if self.x % 8 ~= 8 then + self.x = flr(self.x / 8) * 8 + end self.dx = 0 end -- collision right if self.dx > 0 and (isColliding(self.x + self.dx + 7, self.y) or isColliding(self.x + self.dx + 7, self.y + 7)) then -- move the player against the right wall - self.x = self.x % 8 == 0 and self.x or flr((self.x + 8) / 8) * 8 + if self.x % 8 ~= 0 then + self.x = flr((self.x + 8) / 8) * 8 + end self.dx = 0 end -- collision up if self.dy < 0 and (isColliding(self.x, self.y + self.dy) or isColliding(self.x + 7, self.y + self.dy)) then -- move the player right under the block - self.y = self.y % 8 == 0 and self.y or flr(self.y / 8) * 8 + if self.y % 8 ~= 0 then + self.y = flr(self.y / 8) * 8 + end self.dy = 0 end -- collision down if self.dy > 0 and (isColliding(self.x, self.y + self.dy + 7) or isColliding(self.x + 7, self.y + self.dy + 7)) then -- align the player with the nearest block down - self.y = self.y % 8 == 0 and self.y or flr((self.y + 8) / 8) * 8 + if self.y % 8 ~= 0 then + self.y = flr((self.y + 8) / 8) * 8 + end self.dy = 0 end