-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBall.lua
More file actions
executable file
·37 lines (31 loc) · 850 Bytes
/
Ball.lua
File metadata and controls
executable file
·37 lines (31 loc) · 850 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
36
37
Ball = Class {}
function Ball:init(x, y, width, height)
self.x = x
self.y = y
self.width = width
self.height = height
self.dx = 0
self.dy = 0
end
function Ball:collides(object)
if self.x > object.x + object.width or object.x > self.x + self.width then
return false
end
if self.y > object.y + object.height or object.y > self.y + self.height then
return false
end
return true
end
function Ball:reset()
self.x = VIRTUAL_WIDTH / 2 - BALL_SIZE / 2
self.y = VIRTUAL_HEIGHT - PADDLE_HEIGHT - BALL_SIZE - 6
self.dx = 0
self.dy = 0
end
function Ball:update(dt)
self.x = self.x + self.dx * dt
self.y = self.y + self.dy * dt
end
function Ball:render()
love.graphics.rectangle('fill', self.x, self.y, self.width, self.height)
end