add ship actor
This commit is contained in:
parent
583efe528c
commit
38af0bcaa1
2 changed files with 47 additions and 25 deletions
|
|
@ -71,9 +71,54 @@ function actors.buildActors(game)
|
||||||
love.graphics.pop()
|
love.graphics.pop()
|
||||||
end
|
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 {
|
return {
|
||||||
asteroids = asteroids,
|
asteroids = asteroids,
|
||||||
bullets = bullets,
|
bullets = bullets,
|
||||||
|
ships = ships,
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -65,15 +65,7 @@ local function initState()
|
||||||
return {
|
return {
|
||||||
debug = true,
|
debug = true,
|
||||||
actors = actors,
|
actors = actors,
|
||||||
ship = {
|
ship = actors.ships.new({}),
|
||||||
x = game.width / 2,
|
|
||||||
y = game.height / 2,
|
|
||||||
angle = 0,
|
|
||||||
speed = 0,
|
|
||||||
spin = 0,
|
|
||||||
facing = phys.tau * 3 / 4,
|
|
||||||
radius = game.ship.radius,
|
|
||||||
},
|
|
||||||
bullets = {},
|
bullets = {},
|
||||||
asteroids = asteroids,
|
asteroids = asteroids,
|
||||||
controls = {
|
controls = {
|
||||||
|
|
@ -193,22 +185,7 @@ function love.draw()
|
||||||
for x = -1, 1 do
|
for x = -1, 1 do
|
||||||
love.graphics.origin()
|
love.graphics.origin()
|
||||||
love.graphics.translate(x * game.width, y * game.height)
|
love.graphics.translate(x * game.width, y * game.height)
|
||||||
|
state.ship:draw()
|
||||||
love.graphics.push()
|
|
||||||
love.graphics.translate(state.ship.x, state.ship.y)
|
|
||||||
love.graphics.setColor(1, 1, 1)
|
|
||||||
local scale = 2 * game.ship.radius / math.max(game.ship.sprite:getWidth(), game.ship.sprite:getHeight())
|
|
||||||
love.graphics.draw(game.ship.sprite,
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
(state.ship.facing + phys.tau / 4) % phys.tau,
|
|
||||||
scale,
|
|
||||||
scale,
|
|
||||||
game.ship.sprite:getWidth() / 2,
|
|
||||||
game.ship.sprite:getHeight() / 2
|
|
||||||
)
|
|
||||||
-- TODO rocket exhaust
|
|
||||||
love.graphics.pop()
|
|
||||||
|
|
||||||
for _, bullet in ipairs(state.bullets) do
|
for _, bullet in ipairs(state.bullets) do
|
||||||
bullet:draw()
|
bullet:draw()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue