extract asteroids ctor
This commit is contained in:
parent
21c432f583
commit
b2b70ee910
2 changed files with 38 additions and 9 deletions
|
|
@ -1,6 +1,7 @@
|
|||
local love = require("love")
|
||||
local phys = require("phys")
|
||||
local inspect = require("inspect")
|
||||
local actors = require("actors")
|
||||
|
||||
local function initGame()
|
||||
return {
|
||||
|
|
@ -38,6 +39,8 @@ end
|
|||
local game = initGame()
|
||||
|
||||
local function initState()
|
||||
---@diagnostic disable-next-line: redefined-local
|
||||
local actors = actors.buildActors(game)
|
||||
local asteroids = {
|
||||
{
|
||||
x = 100,
|
||||
|
|
@ -52,15 +55,8 @@ local function initState()
|
|||
y = game.height - 100,
|
||||
}
|
||||
}
|
||||
for _, asteroid in ipairs(asteroids) do
|
||||
asteroid.angle = love.math.random() * phys.tau
|
||||
asteroid.stage = #game.asteroids.stages
|
||||
local stage = game.asteroids.stages[asteroid.stage]
|
||||
asteroid.speed = stage.speed
|
||||
asteroid.facing = math.random() * phys.tau
|
||||
asteroid.spin = 0.1 + math.random() * 0.1
|
||||
asteroid.radius = stage.radius
|
||||
asteroid.sprite = stage.sprite
|
||||
for i, template in ipairs(asteroids) do
|
||||
asteroids[i] = actors.asteroids.new(template)
|
||||
end
|
||||
local joystick = nil
|
||||
if love.joystick.getJoystickCount() == 1 then
|
||||
|
|
@ -68,6 +64,7 @@ local function initState()
|
|||
end
|
||||
return {
|
||||
debug = true,
|
||||
actors = actors,
|
||||
ship = {
|
||||
x = game.width / 2,
|
||||
y = game.height / 2,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue