39 lines
911 B
Lua
39 lines
911 B
Lua
Player = Object:extend()
|
|
|
|
function Player:new(x, y, p, health, image, speed)
|
|
self.image = love.graphics.newImage(image)
|
|
self.x = x
|
|
self.y = y
|
|
self.p = p
|
|
self.health = health
|
|
self.speed = speed
|
|
self.width = self.image:getWidth()
|
|
self.height = self.image:getHeight()
|
|
end
|
|
|
|
function Player:update(dt)
|
|
if self.p == 1 then
|
|
if love.keyboard.isDown("d") then
|
|
self.x = self.x + (self.speed * dt)
|
|
elseif love.keyboard.isDown("a") then
|
|
self.x = self.x - (self.speed * dt)
|
|
end
|
|
elseif self.p == 2 then
|
|
if love.keyboard.isDown("right") then
|
|
self.x = self.x + (self.speed * dt)
|
|
elseif love.keyboard.isDown("left") then
|
|
self.x = self.x - (self.speed * dt)
|
|
end
|
|
end
|
|
|
|
if self.x < 0 then
|
|
self.x = love.graphics.getWidth() - self.width
|
|
elseif self.x + self.width > love.graphics.getWidth() then
|
|
self.x = 0
|
|
end
|
|
end
|
|
|
|
function Player:draw()
|
|
love.graphics.draw(self.image, self.x, self.y)
|
|
end
|