diff --git a/sonic-radiance.love/game/utils/gizmo/properties.lua b/sonic-radiance.love/game/utils/gizmo/properties.lua new file mode 100644 index 0000000..f57b46e --- /dev/null +++ b/sonic-radiance.love/game/utils/gizmo/properties.lua @@ -0,0 +1,4 @@ +return { + isSolid = false, + needButton = true, -- "useButton" or "onContact" +} \ No newline at end of file diff --git a/sonic-radiance.love/scenes/overworld/actors/gizmo.lua b/sonic-radiance.love/scenes/overworld/actors/gizmo.lua new file mode 100644 index 0000000..de39abf --- /dev/null +++ b/sonic-radiance.love/scenes/overworld/actors/gizmo.lua @@ -0,0 +1,51 @@ +local cwd = (...):gsub('%.gizmo$', '') .. "." +local Parent = require(cwd .. "parent") +local Gizmo = Parent:extend() + +function Gizmo:new(world, x, y, w, h, overrides) + local w = w or 16; + local h = h or 16; + Gizmo.super.new(self, world, "gizmo", x, y, w, h, false) + self.overrides = overrides +end + +function Gizmo:setProperties(properties) + self:setDefaultProperties() + self:replaceProperties(properties) + if (self.overrides ~= nil) then + self:replaceProperties(self.overrides) + end + self:applyProperties() +end + +function Gizmo:applyProperties() + -- Apply properties to the internal item system + self.isSolid = self.properties.isSolid + self.mainHitbox.isSolid = self.properties.isSolid + if (self.isSolid) then + self:addHitbox("btnInput", "btnInput", -1, -1, self.w + 2, self.h + 2, false) + end + self.needButton = self.properties.needButton +end + +function Gizmo:setDefaultProperties() + local default = require "game.utils.gizmo.properties" + self.properties = {} + for key, value in pairs(default) do + self.properties[key] = value + end +end + +function Gizmo:replaceProperties(properties) + for key, _ in pairs(properties) do + if (properties[key] ~= nil) then + self.properties[key] = properties[key] + end + end +end + +function Gizmo:doAction() + self.scene:showMessage("I AM ERROR " .. self.creationID) +end + +return Gizmo; \ No newline at end of file diff --git a/sonic-radiance.love/scenes/overworld/actors/init.lua b/sonic-radiance.love/scenes/overworld/actors/init.lua index 9d67a55..015525b 100644 --- a/sonic-radiance.love/scenes/overworld/actors/init.lua +++ b/sonic-radiance.love/scenes/overworld/actors/init.lua @@ -3,11 +3,14 @@ local Obj = {} -- On charge toutes les différentes types d'acteurs local cwd = (...):gsub('%.init$', '') .. "." Obj.Player = require(cwd .. "player") +Obj.Gizmo = require(cwd .. "gizmo") Obj.index = {} Obj.index["player"] = Obj.Player +Obj.index["gizmo"] = Obj.Gizmo Obj.collisions = {} Obj.collisions["wall"] = require(cwd .. "wall") +Obj.collisions["gizmo-collision"] = Obj.Gizmo return Obj diff --git a/sonic-radiance.love/scenes/overworld/actors/player.lua b/sonic-radiance.love/scenes/overworld/actors/player.lua index b64736b..51535ce 100644 --- a/sonic-radiance.love/scenes/overworld/actors/player.lua +++ b/sonic-radiance.love/scenes/overworld/actors/player.lua @@ -21,6 +21,8 @@ function Player:new(world, x, y, id) self.canChangeActive = true self.tweens = TweenManager(self) + self.lastCollision = -1 + self.haveCollided = false end function Player:isMoving() @@ -57,6 +59,38 @@ function Player:updateStart(dt) self.tweens:update(dt) self.world:getTileTypeAtPoint(self.x, self.y) + + if (self.haveCollided == false) then + self.lastCollision = nil + end + self.haveCollided = false +end + +function Player:collisionResponse(col) + if (not col.other.owner.isDestroyed) then + if (col.other.type == "gizmo") then + if (col.other.owner.needButton) then + if (self.keys["A"].isPressed) then + col.other.owner:doAction() + self.haveCollided = true + self.lastCollision = col.other.owner.creationID + end + else + if (self.lastCollision ~= col.other.owner.creationID) then + col.other.owner:doAction() + end + self.haveCollided = true + self.lastCollision = col.other.owner.creationID + end + end + if (col.other.type == "btnInput" and col.other.owner.needButton) then + if (self.keys["A"].isPressed) then + col.other.owner:doAction() + self.haveCollided = true + self.lastCollision = col.other.owner.creationID + end + end + end end function Player:timerResponse(response)