alunizaje/assets/scripts/spaceship.lua
2016-11-14 00:35:14 +01:00

37 lines
1.2 KiB
Lua

local anim8 = require 'assets/scripts/vendor/anim8'
local spaceship = {}
function spaceship.load(game)
-- power origin 1000
spaceship = { x = game.canvas.width / 2, y = 0 , power = 400 , size_collition = 28, polygons_collition = 8 }
spaceship.img = love.graphics.newImage('assets/sprites/spaceship/body.png')
spaceship.body = love.physics.newBody(game.world, (game.canvas.width / 2) - (spaceship.img:getWidth() / 2) , spaceship.y, 'dynamic')
spaceship.shape = love.physics.newCircleShape(20)
spaceship.fixture = love.physics.newFixture(spaceship.body, spaceship.shape, 1)
spaceship.fixture:setRestitution(0.9)
local g = anim8.newGrid(110, 103, spaceship.img:getWidth(), spaceship.img:getHeight())
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