reduce asteroid init

This commit is contained in:
Donald Ball 2025-11-20 21:07:12 -05:00
parent b2b70ee910
commit c1c774338e
2 changed files with 7 additions and 19 deletions

View file

@ -8,7 +8,8 @@ function actors.buildActors(game)
local asteroids_mt = { __index = asteroids }
function asteroids.new(asteroid)
local stage = game.asteroids.stages[asteroid.stage or #game.asteroids.stages]
local stageIndex = asteroid.stage or #game.asteroids.stages
local stage = game.asteroids.stages[stageIndex]
local instance = {
angle = math.random() * phys.tau,
speed = stage.speed,
@ -20,6 +21,7 @@ function actors.buildActors(game)
for k, v in pairs(asteroid) do
instance[k] = v
end
instance.stage = stageIndex
setmetatable(instance, asteroids_mt)
return instance
end

View file

@ -127,32 +127,18 @@ function love.update(dt)
if asteroid.stage > 1 then
local angle1 = love.math.random() * phys.tau
local angle2 = angle1 - phys.tau / 2
local stage = game.asteroids.stages[asteroid.stage - 1]
local radius = stage.radius
local speed = stage.speed
local sprite = stage.sprite
table.insert(state.asteroids, {
table.insert(state.asteroids, state.actors.asteroids.new({
x = asteroid.x,
y = asteroid.y,
angle = angle1,
stage = asteroid.stage - 1,
radius = radius,
speed = speed,
facing = math.random() * phys.tau,
spin = 0.1 + math.random() * 0.1,
sprite = sprite,
})
table.insert(state.asteroids, {
}))
table.insert(state.asteroids, state.actors.asteroids.new({
x = asteroid.x,
y = asteroid.y,
angle = angle2,
stage = asteroid.stage - 1,
radius = radius,
speed = speed,
facing = math.random() * phys.tau,
spin = 0.1 + math.random() * 0.1,
sprite = sprite,
})
}))
end
table.remove(state.asteroids, asteroidIndex)
break