extract asteroids ctor
This commit is contained in:
parent
21c432f583
commit
b2b70ee910
2 changed files with 38 additions and 9 deletions
32
asteroids/actors.lua
Normal file
32
asteroids/actors.lua
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
local phys = require("phys")
|
||||
local inspect = require("inspect")
|
||||
|
||||
local actors = {}
|
||||
|
||||
function actors.buildActors(game)
|
||||
local asteroids = {}
|
||||
local asteroids_mt = { __index = asteroids }
|
||||
|
||||
function asteroids.new(asteroid)
|
||||
local stage = game.asteroids.stages[asteroid.stage or #game.asteroids.stages]
|
||||
local instance = {
|
||||
angle = math.random() * phys.tau,
|
||||
speed = stage.speed,
|
||||
facing = math.random() * phys.tau,
|
||||
spin = (math.random() - 0.5),
|
||||
radius = stage.radius,
|
||||
sprite = stage.sprite,
|
||||
}
|
||||
for k, v in pairs(asteroid) do
|
||||
instance[k] = v
|
||||
end
|
||||
setmetatable(instance, asteroids_mt)
|
||||
return instance
|
||||
end
|
||||
|
||||
return {
|
||||
asteroids = asteroids,
|
||||
}
|
||||
end
|
||||
|
||||
return actors
|
||||
Loading…
Add table
Add a link
Reference in a new issue