From bceda94970ee6da1588825e68c046847a3398324 Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Sun, 21 Mar 2021 16:30:46 +0100 Subject: [PATCH] improvement: add charDir check on gizmo collision --- .../scenes/overworld/actors/player.lua | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/sonic-radiance.love/scenes/overworld/actors/player.lua b/sonic-radiance.love/scenes/overworld/actors/player.lua index 18f6edc..e20da85 100644 --- a/sonic-radiance.love/scenes/overworld/actors/player.lua +++ b/sonic-radiance.love/scenes/overworld/actors/player.lua @@ -85,7 +85,7 @@ function Player:collisionResponse(col) end end if (col.other.type == "btnInput" and col.other.owner.needButton) then - if (self.keys["A"].isPressed) then + if (self.keys["A"].isPressed and (self:faceRightDirection(col.other.owner))) then col.other.owner:doAction() self.haveCollided = true self.lastCollision = col.other.owner.creationID @@ -94,6 +94,21 @@ function Player:collisionResponse(col) end end +function Player:faceRightDirection(other) + if (self.charDir == "up") then + return (self.y >= other.y + other.h) + end + if (self.charDir == "down") then + return (self.y + self.h <= other.y) + end + if (self.charDir == "left") then + return (self.x >= other.x + other.w) + end + if (self.charDir == "right") then + return (self.x + self.w <= other.x) + end +end + function Player:timerResponse(response) if (response == "changeCharacter") then self.canChangeActive = true