/
game.lua
120 lines (101 loc) · 3.16 KB
/
game.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
Game = Object:extend()
smallFont = love.graphics.newFont('fonts/pong.ttf', 8)
largeFont = love.graphics.newFont('fonts/pong.ttf', 16)
scoreFont = love.graphics.newFont('fonts/pong.ttf', 32)
function Game:new()
self.padGauche = Pad('left')
self.padDroite = Pad('right')
self.padDroite.x = 740
-- self.padDroite.keyUp = 'z'
-- self.padDroite.keyDown = 's'
self.ball = Ball()
self.scoreGauche = 0
self.scoreDroite = 0
end
function Game.load()
self.padDroit.speed = 300
gameMode = "solo"
gameModeChoice(gameMode)
end
function Game:update(dt)
-- mouse.x, mouse.y = love.mouse.getPosition()
if self.padDroite.y < self.ball.y then
self.padDroite.y = self.padDroite.y + (self.padDroite.y * 2.5 * dt)
end
if self.padDroite.y > self.ball.y then
self.padDroite.y = self.padDroite.y - (self.padDroite.y * 2.5 * dt)
end
self.padDroite:update(dt)
self.padGauche:update(dt)
self.ball:update(dt)
self.ball:bounce(self.padDroite)
self.ball:bounce(self.padGauche)
local ball_stat = self.ball:checkScreen()
if ball_stat == 'left' then
self.scoreDroite = self.scoreDroite + 1
self.ball = Ball()
elseif ball_stat == 'right' then
self.scoreGauche = self.scoreGauche + 1
self.ball = Ball()
end
end
function followBall()
end
function Game:draw()
-- drawMenu()
-- soloGame()
self.padGauche:draw()
self.padDroite:draw()
self.ball:draw()
love.graphics.setFont(scoreFont)
love.graphics.print(tostring(self.scoreDroite), 350, 10 / 3)
love.graphics.print(tostring(self.scoreGauche), 450, 10 / 3)
end
function drawScores()
love.graphics.setFont(scoreFont)
love.graphics.print(self.scoreDroite, 'center')
love.graphics.print(self.scoreGauche, 'center')
end
function drawMenu()
love.graphics.printf('Welcome to Pong Game', 100, 100, 300, 'center')
if gameMode == 'solo' then
love.graphics.setColor(1, 0, 0, 1)
end
love.graphics.printf('Solo', 350, 400, 200, 'center')
love.graphics.setColor(1, 1, 1, 1)
if gameMode == 'versus' then
love.graphics.setColor(1, 0, 0, 1)
end
love.graphics.printf('Versus', 350, 200, 200, 'center')
love.graphics.setColor(1, 1, 1, 1)
end
function love.keypressed(key)
if key == 'down' then
gameMode = 'versus'
elseif key == 'up' then
gameMode = 'solo'
end
if gameMode == 'solo' then
if key == 'space' then
-- gameModeChoice(tostring(gameMode))
-- print(gameModeChoice(gameMode))
self.padGauche:draw()
self.padDroite:draw()
self.ball:draw()
love.graphics.setFont(scoreFont)
love.graphics.print(tostring(self.scoreDroite), 350, 10 / 3)
love.graphics.print(tostring(self.scoreGauche), 450, 10 / 3)
end
end
end
function gameModeChoice(gameMode)
if gameMode == 'solo' then
love.graphics.print('Hello World!', 400, 300)
soloGame()
else
love.graphics.printf('TESTIIIING', 350, 200, 200, 'center')
love.graphics.setColor(1, 1, 1, 1)
end
end
function soloGame()
end