78 lines
2.0 KiB
Lua
78 lines
2.0 KiB
Lua
Cart = {}
|
|
|
|
local sizeX, sizeY = CartSprite:getSize()
|
|
local size = { x = sizeX, y = sizeY * 0.75 }
|
|
local secOver90 = 0
|
|
|
|
filteredSystem("launchedByCrank", { launchedByCrank = T.marker, crankState = T.CrankState, baseVelocity = T.XyPair }, function(e, dt, system)
|
|
local change = math.abs(e.crankState.changeInLastHalfSecond)
|
|
if change > 90 then
|
|
secOver90 = secOver90 + dt
|
|
end
|
|
|
|
if secOver90 > 0.05 then
|
|
secOver90 = 0
|
|
local launchPower = change - 40
|
|
print("Launch power: " .. launchPower)
|
|
e.launchedByCrank = nil
|
|
e.crankState = nil
|
|
e.velocity = { x = launchPower * e.baseVelocity.x, y = launchPower * e.baseVelocity.y }
|
|
system.world:addEntity(e)
|
|
end
|
|
end)
|
|
|
|
cartSystem = filteredSystem("cart", { isCart = T.marker })
|
|
|
|
function Cart.reset(o)
|
|
o.launchedByCrank = T.marker
|
|
o.isCart = T.marker
|
|
o.position = {
|
|
x = 20,
|
|
y = 50,
|
|
}
|
|
o.velocity = nil
|
|
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)
|
|
-- it'd be funny if the cart fully just exploded instead
|
|
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({
|
|
baseVelocity = {
|
|
x = 2,
|
|
y = -1,
|
|
},
|
|
}),
|
|
{ __index = Cart }
|
|
)
|
|
end
|