add ship actor

This commit is contained in:
Donald Ball 2025-11-20 21:37:04 -05:00
parent 583efe528c
commit 38af0bcaa1
2 changed files with 47 additions and 25 deletions

View file

@ -71,9 +71,54 @@ function actors.buildActors(game)
love.graphics.pop()
end
local ships = {}
local ships_mt = { __index = ships }
function ships.new(ship)
local instance = {
x = game.width / 2,
y = game.height / 2,
angle = 0,
speed = 0,
spin = 0,
facing = phys.tau * 3 / 4,
radius = game.ship.radius,
}
for k, v in pairs(game.ship) do
instance[k] = v
end
for k, v in pairs(ship) do
instance[k] = v
end
setmetatable(instance, ships_mt)
return instance
end
function ships:draw()
love.graphics.push()
love.graphics.translate(self.x, self.y)
love.graphics.setColor(1, 1, 1)
local width = self.sprite:getWidth()
local height = self.sprite:getHeight()
local scale = 2 * game.ship.radius / math.max(width, height)
love.graphics.draw(game.ship.sprite,
0,
0,
(self.facing + phys.tau / 4) % phys.tau,
scale,
scale,
width / 2,
height / 2
)
-- TODO rocket exhaust
love.graphics.pop()
end
return {
asteroids = asteroids,
bullets = bullets,
ships = ships,
}
end