-
Notifications
You must be signed in to change notification settings - Fork 1
/
paddle.lua
61 lines (57 loc) · 1.22 KB
/
paddle.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
Paddle = Object:extend()
function Paddle:new(x,y,w,h,up,down)
self.x = x
self.y = y
self.w = w
self.h = h
self.accel = 100
self.up = up
self.down = down
end
function Paddle:setKeys(up,down)
self.up = up
self.down = down
end
function Paddle:draw()
love.graphics.rectangle("fill",self.x,self.y,self.w,self.h)
end
function Paddle:setSpeed(speed)
self.speed = speed
end
function Paddle:setAccel(a)
self.accel = a
end
function Paddle:setLocation(x,y)
self.x = x
self.y = y
end
function Paddle:update(dt)
-- if love.keyboard.isDown("left") then
-- self.speed = self.speed + self.accel*dt
-- self.x = self.x - self.speed*dt
-- elseif love.keyboard.isDown("right") then
-- self.speed = self.speed + self.accel*dt
-- self.x = self.x + self.speed*dt
-- end
if love.keyboard.isDown(self.up) then
self.speed = self.speed + self.accel*dt
self.y = self.y - self.speed*dt
elseif love.keyboard.isDown(self.down) then
self.speed = self.speed + self.accel*dt
self.y = self.y + self.speed * dt
end
if self.x < 0 then
self.x = 0
end
if self.y < 0 then
self.y = 0
end
if self.x > 550 - self.w then
self.x = 550 - self.w
end
if self.y > 550 - self.h then
self.y = 550 - self.h
end
end
function Paddle:move(x,y,dt)
end