From 91c7a03dc239121369edf3b439c744757f0aec29 Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Sun, 21 Mar 2021 16:32:29 +0100 Subject: [PATCH] chore: simplify gizmo collision check --- .../scenes/overworld/actors/player.lua | 26 ++++++++++--------- 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/sonic-radiance.love/scenes/overworld/actors/player.lua b/sonic-radiance.love/scenes/overworld/actors/player.lua index e20da85..16c1de1 100644 --- a/sonic-radiance.love/scenes/overworld/actors/player.lua +++ b/sonic-radiance.love/scenes/overworld/actors/player.lua @@ -68,27 +68,29 @@ function Player:updateCurrentCharset() end function Player:collisionResponse(col) - if (not col.other.owner.isDestroyed) then - if (col.other.type == "gizmo") then - if (col.other.owner.needButton) then + local hitbox = col.other + local other = col.other.owner + if (not other.isDestroyed) then + if (hitbox.type == "gizmo") then + if (other.needButton) then if (self.keys["A"].isPressed) then - col.other.owner:doAction() + other:doAction() self.haveCollided = true - self.lastCollision = col.other.owner.creationID + self.lastCollision = other.creationID end else - if (self.lastCollision ~= col.other.owner.creationID) then - col.other.owner:doAction() + if (self.lastCollision ~= other.creationID) then + other:doAction() end self.haveCollided = true - self.lastCollision = col.other.owner.creationID + self.lastCollision = other.creationID end end - if (col.other.type == "btnInput" and col.other.owner.needButton) then - if (self.keys["A"].isPressed and (self:faceRightDirection(col.other.owner))) then - col.other.owner:doAction() + if (hitbox.type == "btnInput" and other.needButton) then + if (self.keys["A"].isPressed and (self:faceRightDirection(other))) then + other:doAction() self.haveCollided = true - self.lastCollision = col.other.owner.creationID + self.lastCollision = other.creationID end end end