replaced ternaries with ifs

This commit is contained in:
Simon Cambier 2025-04-07 13:37:19 +02:00
parent ff81acd40c
commit 1842253f85

View File

@ -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