generated from sage/tiny-ecs-love-template
86 lines
2.7 KiB
Lua
86 lines
2.7 KiB
Lua
local gridElements = filteredSystem("gridElements", { gridPosition = T.XyPair, effectsToApply = T.AnyComponent })
|
|
|
|
local roundRunning = false
|
|
|
|
filteredSystem("timers", { timerSec = T.number, callback = T.SelfFunction }, function(e, dt, system)
|
|
e.timerSec = e.timerSec - dt
|
|
if e.timerSec < 0 then
|
|
e:callback()
|
|
system.world:removeEntity(e)
|
|
end
|
|
end)
|
|
|
|
local function sign(n)
|
|
return n > 0 and 1 or n < 0 and -1 or 0
|
|
end
|
|
|
|
local roundSystem = filteredSystem("rounds", { round = T.str })
|
|
|
|
local activeBallEffects = filteredSystem("activeBallEffects", { ballEffects = T.AnyComponent, gridPosition = T.XyPair }, function(e, dt, system)
|
|
local roundActive = false
|
|
for _, state in pairs(roundSystem.entities) do
|
|
if state.round == "start" then
|
|
roundActive = true
|
|
end
|
|
end
|
|
if not roundActive then
|
|
return
|
|
end
|
|
local gridPosition, effects = e.gridPosition, e.ballEffects
|
|
|
|
-- Search for new effects from the current tile
|
|
for _, gridElement in pairs(gridElements.entities) do
|
|
if
|
|
gridPosition.x == gridElement.gridPosition.x
|
|
and gridPosition.y == gridElement.gridPosition.y
|
|
then
|
|
-- More direct-mutation-y than I'd like,
|
|
-- but offers a simple way to overwrite existing effects.
|
|
-- We're "setting InRelations" :D
|
|
for key, value in pairs(gridElement.effectsToApply) do
|
|
effects[key] = value
|
|
end
|
|
if gridElement.spriteAfterEffect then
|
|
gridElement.drawAsSprite = gridElement.spriteAfterEffect
|
|
gridElement.spriteAfterEffect = nil
|
|
end
|
|
gridElement.effectsToApply = nil
|
|
system.world:addEntity(gridElement)
|
|
end
|
|
end
|
|
|
|
-- Apply any effects currently connected to this ball
|
|
if effects.movement ~= nil then
|
|
gridPosition.x = gridPosition.x + sign(effects.movement.x)
|
|
gridPosition.y = gridPosition.y + sign(effects.movement.y)
|
|
|
|
effects.movement.x = effects.movement.x - sign(effects.movement.x)
|
|
effects.movement.y = effects.movement.y - sign(effects.movement.y)
|
|
|
|
if effects.movement.x == 0 and effects.movement.y == 0 then
|
|
effects.movement = nil
|
|
end
|
|
end
|
|
|
|
-- TODO: Trigger the round end
|
|
-- for _, _ in pairs(effects) do
|
|
-- -- Return if there are any effects left
|
|
-- return
|
|
-- end
|
|
|
|
-- system.world:addEntity({ round = "end" })
|
|
end)
|
|
|
|
local stepTimeSec = 0.3
|
|
local stepTimer = stepTimeSec
|
|
|
|
function activeBallEffects:preProcess(dt)
|
|
stepTimer = stepTimer - dt
|
|
if stepTimer <= 0 then
|
|
stepTimer = stepTimeSec
|
|
return
|
|
end
|
|
return tiny.SKIP_PROCESS
|
|
end
|
|
|