Code: Select all
local Class = require 'lib.hump.class'
local Player = Class{
init = function(self, x, y)
self.body = love.physics.newBody(world, x, y, "dynamic")
-- self.shape = love.physics.newRectangleShape(50, 50)
-- self.fixture = love.physics.newFixture(self.body, self.shape, 1)
self.image = love.graphics.newImage("assets/helo.png")
end,
update = function(self, dt)
if love.keyboard.isDown('d') then
self.body:setAngle(.4)
self.body:applyForce(200, 0)
elseif love.keyboard.isDown('a') then
self.body:setAngle(-.4)
self.body:applyForce(-200, 0)
else
self.body:setAngle(0)
end
end,
draw = function(self)
local x, y = self.body:getPosition()
local width, height = self.image:getDimensions()
love.graphics.draw(self.image, x, y, self.body:getAngle(), .5, .5, width/2, height/2)
end
}
return Player;