-
Notifications
You must be signed in to change notification settings - Fork 0
/
Player.lua
35 lines (29 loc) · 818 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
Player = Class{}
function Player:init(paddle, score)
self.paddle = paddle
self.score = score or 0
end
--[[
Controlla se la palla sta avendo una collisione con il
riquadro del giocatore
@return true se c'è una collisione, altrimenti false
]]
function Player:isColliding(ball)
-- Controlla che la palla sia prima o dopo il riquadro
if ball.x > self.paddle.x + self.paddle.width or
ball.x + ball.width < self.paddle.x then
return false
end
-- Controllo che la palla sia sopra o sotto il riquadro
if ball.y > self.paddle.y + self.paddle.height or
ball.y + ball.height < self.paddle.y then
return false
end
return true
end
function Player:update(dt)
self.paddle:update(dt)
end
function Player:render()
self.paddle:render()
end