improvement: add charDir check on gizmo collision

This commit is contained in:
Kazhnuz 2021-03-21 16:30:46 +01:00
parent b48b02d64a
commit bceda94970

View file

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