generated from sage/tiny-ecs-love-template
41 lines
1.2 KiB
Lua
41 lines
1.2 KiB
Lua
local world = require("world")
|
|
local width, height = love.graphics.getWidth(), love.graphics.getHeight()
|
|
local midFont = EtBt7001Z0xa(32)
|
|
|
|
local AddScore = {
|
|
addingScoreTo = {
|
|
score = T.number,
|
|
scoreDisplay = Maybe({ drawAsText = { text = T.str } }),
|
|
},
|
|
scoreToAdd = T.number,
|
|
}
|
|
|
|
local z = 1
|
|
|
|
world:filteredSystem("score", { addScore = AddScore }, function(e, _, system)
|
|
system.world:removeEntity(e)
|
|
local target, scoreToAdd = e.addScore.addingScoreTo, e.addScore.scoreToAdd
|
|
target.score = target.score + scoreToAdd
|
|
|
|
if target.scoreDisplay ~= nil then
|
|
target.scoreDisplay.drawAsText.text = "" .. target.score
|
|
system.world:addEntity({
|
|
z = z,
|
|
drawAsText = {
|
|
text = "+" .. scoreToAdd,
|
|
style = TextStyle.Inverted,
|
|
font = midFont,
|
|
},
|
|
position = {
|
|
x = target.scoreDisplay.position.x,
|
|
y = target.scoreDisplay.position.y,
|
|
},
|
|
velocity = { x = 100 * (math.random() - 0.5), y = -100 },
|
|
mass = 1,
|
|
decayAfterSeconds = 3,
|
|
})
|
|
-- Prevents z-fighting of falling score updates
|
|
z = (z + 1) % 1000
|
|
end
|
|
end)
|