54 lines
1.4 KiB
Lua
54 lines
1.4 KiB
Lua
local PlayerInteractions = Object:extend()
|
|
|
|
function PlayerInteractions:initInteractions()
|
|
self.lastCollision = -1
|
|
self.haveCollided = false
|
|
end
|
|
|
|
function PlayerInteractions:updateInteraction()
|
|
if (self.haveCollided == false) then
|
|
self.lastCollision = nil
|
|
end
|
|
self.haveCollided = false
|
|
end
|
|
|
|
function PlayerInteractions:collideWithGizmo(other)
|
|
if (other.needButton) then
|
|
if (self.keys["A"].isPressed) then
|
|
other:doAction()
|
|
self.haveCollided = true
|
|
self.lastCollision = other.creationID
|
|
end
|
|
else
|
|
if (self.lastCollision ~= other.creationID) then
|
|
other:doAction()
|
|
end
|
|
self.haveCollided = true
|
|
self.lastCollision = other.creationID
|
|
end
|
|
end
|
|
|
|
function PlayerInteractions:talkToGizmo(other)
|
|
if (self.keys["A"].isPressed and (self:faceRightDirection(other))) then
|
|
other:doAction()
|
|
self.haveCollided = true
|
|
self.lastCollision = other.creationID
|
|
end
|
|
end
|
|
|
|
function PlayerInteractions: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
|
|
|
|
return PlayerInteractions
|