-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplayer.lua
38 lines (33 loc) · 999 Bytes
/
player.lua
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
36
37
38
Player = {}
function Player:load()
self.x = 50
self.y = love.graphics.getHeight() / 2
-- self.img = love.graphics.newImage("Lua/LOVE/Pong/Images/1.png")
-- self.width = self.img:getWidth()
-- self.height = self.img:getHeight()
self.width = 20
self.height = 100
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 + self.height > love.graphics.getHeight() then
self.y = love.graphics.getHeight() - self.height
end
end
function Player:draw()
love.graphics.rectangle("fill", self.x, self.y, self.width, self.height)
-- love.graphics.draw(self.img, self.x, self.y, self.width, self.height)
end