2016-11-12 13:49:24 +01:00
|
|
|
local anim8 = require 'assets/scripts/vendor/anim8'
|
|
|
|
|
|
|
|
local spaceship = {}
|
|
|
|
|
2016-11-14 00:35:14 +01:00
|
|
|
function spaceship.load(game)
|
2016-11-12 13:49:24 +01:00
|
|
|
-- power origin 1000
|
2016-11-14 00:35:14 +01:00
|
|
|
spaceship = { x = game.canvas.width / 2, y = 0 , power = 400 , size_collition = 28, polygons_collition = 8 }
|
2016-11-12 13:49:24 +01:00
|
|
|
spaceship.img = love.graphics.newImage('assets/sprites/spaceship/body.png')
|
2016-11-14 00:35:14 +01:00
|
|
|
spaceship.body = love.physics.newBody(game.world, (game.canvas.width / 2) - (spaceship.img:getWidth() / 2) , spaceship.y, 'dynamic')
|
2016-11-12 13:49:24 +01:00
|
|
|
spaceship.shape = love.physics.newCircleShape(20)
|
|
|
|
spaceship.fixture = love.physics.newFixture(spaceship.body, spaceship.shape, 1)
|
|
|
|
spaceship.fixture:setRestitution(0.9)
|
2016-11-12 20:39:10 +01:00
|
|
|
local g = anim8.newGrid(110, 103, spaceship.img:getWidth(), spaceship.img:getHeight())
|
2016-11-12 13:49:24 +01:00
|
|
|
spaceship.animation = anim8.newAnimation(g('1-1', 1), 0.1)
|
|
|
|
end
|
|
|
|
|
|
|
|
function spaceship.update(dt)
|
|
|
|
spaceship.animation:update(dt)
|
|
|
|
-- Controls
|
|
|
|
if control_up then
|
|
|
|
spaceship.body:applyForce(0, -spaceship.power)
|
|
|
|
end
|
|
|
|
if control_right then
|
|
|
|
spaceship.body:applyForce(spaceship.power, 0)
|
|
|
|
elseif control_left then
|
|
|
|
spaceship.body:applyForce(-spaceship.power, 0)
|
|
|
|
end
|
|
|
|
if control_quit then
|
|
|
|
love.event.push('quit')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function spaceship.draw()
|
|
|
|
spaceship.animation:draw(spaceship.img, spaceship.body:getX(), spaceship.body:getY())
|
|
|
|
end
|
|
|
|
|
|
|
|
return spaceship
|