ovellas/entidades/pastor.lua
2022-06-27 23:48:45 +02:00

43 lines
1.5 KiB
Lua

Pastor = {}
function Pastor:new(x, y)
self.sprite = love.graphics.newImage("img/pastor.png")
self.width = self.sprite:getWidth()
self.height = self.sprite:getHeight()
self.x = x-self.width/2
self.y = y-self.height/2
self.speed = 2
local width, height, flags = love.window.getMode();
self.body = love.physics.newBody(world, width/2, height/2, "dynamic")
self.shape = love.physics.newCircleShape(self.width/2+5)
self.fixture = love.physics.newFixture(self.body, self.shape, 1)
return self
end
function Pastor:update(dt)
local width, height, flags = love.window.getMode();
width = width - self.width
height = height - self.height
if (love.keyboard.isDown("up") or love.keyboard.isDown("k")) and self.y > 0 then
self.y = self.y - self.speed
end
if (love.keyboard.isDown("down") or love.keyboard.isDown("j")) and self.y < height then
self.y = self.y + self.speed
end
if (love.keyboard.isDown("left") or love.keyboard.isDown("h"))and self.x > 0 then
self.x = self.x - self.speed
end
if (love.keyboard.isDown("right") or love.keyboard.isDown("l")) and self.x < width then
self.x = self.x + self.speed
end
end
function Pastor:draw()
-- love.graphics.circle("fill", self.body:getX(), self.body:getY(), self.shape:getRadius())
love.graphics.circle("fill", self.x+self.width/2, self.y+self.height/2, self.shape:getRadius())
love.graphics.draw(self.sprite, self.x, self.y)
end