ecstasy
Simple, fast entity component system.
--!strict
local Ecstasy = require("@ecstasy")
type Position = Ecstasy.Component<{x: number, y: number}>
local world = Ecstasy.create()
local position: Position = Ecstasy.component()
local frozen = Ecstasy.tag()
local function spawn(x: number, y: number)
local entity = Ecstasy.spawn(world)
Ecstasy.insert(world, entity, position, { x = x, y = y })
return entity
end
local function update(dt: number)
local falling = Ecstasy.without(Ecstasy.query(world, position), frozen)
for _, pos in Ecstasy.iter(falling) do
pos.y -= 10 * dt
end
end
local player = spawn(0, 0)
local enemy = spawn(10, 10)
Ecstasy.add(world, enemy, frozen)