luncher/src/cart.lua

53 lines
1.2 KiB
Lua

Cart = {}
local sizeX, sizeY = CartSprite:getSize()
local size = { x = sizeX, y = sizeY * 0.75 }
cartSystem = filteredSystem("cart", { isCart = T.marker })
function Cart.reset(o)
o.isCart = T.marker
o.position = {
x = 20,
y = 50,
}
o.velocity = {
x = 300 + (100 * math.random()),
y = 175 * (math.random() - 1),
}
o.size = size
o.canBeBounced = {
flat = { x = 0, y = 0 },
mult = { x = 1, y = 1 },
}
o.canCollideWith = 1 | 4
o.mass = 1
o.drawAsSprite = CartSprite
o.focusPriority = 0
---@param world World
function o:spawnEntitiesWhenStopped(world)
self.velocity = { x = 300, y = 0 }
self.canCollideWith = 4
world:addEntity({
roundAction = "end",
position = {
x = self.position.x,
y = self.position.y,
},
})
-- Focus on the center, where the cart stopped
world:addEntity({
position = { x = self.position.x, y = self.position.y },
focusPriority = 1,
removeAtRoundStart = true,
})
end
return o
end
function Cart.new()
return setmetatable(Cart.reset({}), { __index = Cart })
end