add bullet actor

This commit is contained in:
Donald Ball 2025-11-20 21:26:44 -05:00
parent c1c774338e
commit 583efe528c
2 changed files with 51 additions and 20 deletions

View file

@ -1,3 +1,4 @@
local love = require("love")
local phys = require("phys")
local inspect = require("inspect")
@ -26,8 +27,53 @@ function actors.buildActors(game)
return instance
end
function asteroids:draw()
local width = self.sprite:getWidth()
local height = self.sprite:getHeight()
love.graphics.push()
love.graphics.setColor(1, 1, 1)
local scale = 2 * self.radius / math.max(width, height)
love.graphics.draw(self.sprite,
self.x,
self.y,
self.facing,
scale,
scale,
width / 2,
height / 2
)
love.graphics.pop()
end
local bullets = {}
local bullets_mt = { __index = bullets }
function bullets.new(bullet)
local instance = {
spin = 0,
}
for k, v in pairs(game.ship.bullet) do
instance[k] = v
end
for k, v in pairs(bullet) do
instance[k] = v
end
instance.sound = love.audio.newSource(game.ship.bullet.sound)
instance.timeLeft = instance.time
setmetatable(instance, bullets_mt)
return instance
end
function bullets:draw()
love.graphics.push()
love.graphics.setColor(0, 1, 0)
love.graphics.circle('fill', self.x, self.y, self.radius)
love.graphics.pop()
end
return {
asteroids = asteroids,
bullets = bullets,
}
end