feat: add the gizmo system
This commit is contained in:
parent
f7f1a772f7
commit
91fee0a856
4 changed files with 92 additions and 0 deletions
4
sonic-radiance.love/game/utils/gizmo/properties.lua
Normal file
4
sonic-radiance.love/game/utils/gizmo/properties.lua
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
return {
|
||||||
|
isSolid = false,
|
||||||
|
needButton = true, -- "useButton" or "onContact"
|
||||||
|
}
|
51
sonic-radiance.love/scenes/overworld/actors/gizmo.lua
Normal file
51
sonic-radiance.love/scenes/overworld/actors/gizmo.lua
Normal file
|
@ -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;
|
|
@ -3,11 +3,14 @@ local Obj = {}
|
||||||
-- On charge toutes les différentes types d'acteurs
|
-- On charge toutes les différentes types d'acteurs
|
||||||
local cwd = (...):gsub('%.init$', '') .. "."
|
local cwd = (...):gsub('%.init$', '') .. "."
|
||||||
Obj.Player = require(cwd .. "player")
|
Obj.Player = require(cwd .. "player")
|
||||||
|
Obj.Gizmo = require(cwd .. "gizmo")
|
||||||
|
|
||||||
Obj.index = {}
|
Obj.index = {}
|
||||||
Obj.index["player"] = Obj.Player
|
Obj.index["player"] = Obj.Player
|
||||||
|
Obj.index["gizmo"] = Obj.Gizmo
|
||||||
|
|
||||||
Obj.collisions = {}
|
Obj.collisions = {}
|
||||||
Obj.collisions["wall"] = require(cwd .. "wall")
|
Obj.collisions["wall"] = require(cwd .. "wall")
|
||||||
|
Obj.collisions["gizmo-collision"] = Obj.Gizmo
|
||||||
|
|
||||||
return Obj
|
return Obj
|
||||||
|
|
|
@ -21,6 +21,8 @@ function Player:new(world, x, y, id)
|
||||||
self.canChangeActive = true
|
self.canChangeActive = true
|
||||||
|
|
||||||
self.tweens = TweenManager(self)
|
self.tweens = TweenManager(self)
|
||||||
|
self.lastCollision = -1
|
||||||
|
self.haveCollided = false
|
||||||
end
|
end
|
||||||
|
|
||||||
function Player:isMoving()
|
function Player:isMoving()
|
||||||
|
@ -57,6 +59,38 @@ function Player:updateStart(dt)
|
||||||
self.tweens:update(dt)
|
self.tweens:update(dt)
|
||||||
|
|
||||||
self.world:getTileTypeAtPoint(self.x, self.y)
|
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
|
end
|
||||||
|
|
||||||
function Player:timerResponse(response)
|
function Player:timerResponse(response)
|
||||||
|
|
Loading…
Reference in a new issue