-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplayer.lua
More file actions
35 lines (30 loc) · 824 Bytes
/
player.lua
File metadata and controls
35 lines (30 loc) · 824 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
Player = {}
function Player:load()
self.x = 50
self.y = love.graphics.getHeight() / 2
self.img = love.graphics.newImage("assets/images/1.png")
self.width = self.img:getWidth()
self.height = self.img:getHeight()
self.speed = 500
end
function Player:update(dt)
self:move(dt)
self:checkBoundaries()
end
function Player:move(dt)
if love.keyboard.isDown("w") then
self.y = self.y - self.speed * dt
elseif love.keyboard.isDown("s") then
self.y = self.y + self.speed * dt
end
end
function Player:checkBoundaries()
if self.y < 0 then
self.y = 0
elseif self.y > love.graphics.getHeight() - self.height then
self.y = love.graphics.getHeight() - self.height
end
end
function Player:draw()
love.graphics.draw(self.img, self.x, self.y)
end