-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.lua
More file actions
366 lines (333 loc) · 11.4 KB
/
Copy pathmain.lua
File metadata and controls
366 lines (333 loc) · 11.4 KB
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
local Player = require("player")
local Enemy = require("src/enemy")
local Boss = require("src/boss")
local Intro = require("intro")
local Item = require("src/items")
local Checkpoint = require("checkpoint")
local Map = require("map")
local Camera = require("camera")
local Tree = require("tree")
local player
local enemies = {}
local boss
local map
local camera
local items = {}
local checkpointBoots
local checkpointFrogHat
local checkpointBackpack
local checkpointPlush
local checkpointsData = { count = 0, total = 4 }
local game = {
difficulty = 1,
state = {
menu = false,
paused = false,
running = false,
ended = false,
},
anubis = false
}
local buttons = {
{ label = "Accept", x = 300, y = 400, w = 120, h = 40 },
{ label = "Refuse", x = 500, y = 400, w = 120, h = 40 },
}
local choiceMade = false
local imgAnubis1 = nil
local imgAnubis2 = nil
local imgRefuse1 = nil
local imgRefuse2 = nil
local imgRefuse3 = nil
local imgBeforeChoice = nil
local slideIndex = 1
local slideTimer = 0
local slideDuration = 3
local selectedBtn = 1
local function isHovered(btn)
local mx, my = love.mouse.getPosition()
return mx > btn.x and mx < btn.x + btn.w and
my > btn.y and my < btn.y + btn.h
end
local function startGame()
game.state["running"] = true
local image = love.graphics.newImage("player.png")
player = Player.new(100, 100, image)
local imageMap = love.graphics.newImage("map.png")
map = Map.new(imageMap)
camera = Camera.new(imageMap:getWidth() * 2, imageMap:getHeight() * 2)
local imageTree = love.graphics.newImage("tree.png")
Tree.load(imageTree, imageMap)
local imageBoots = love.graphics.newImage("boots.png")
local imageFrogHat = love.graphics.newImage("froghat.png")
local imageBackpack = love.graphics.newImage("backpack.png")
local imagePlush = love.graphics.newImage("plush.png")
checkpointBoots = Checkpoint.new(2800, 800, imageBoots)
checkpointFrogHat = Checkpoint.new(1200, 1820, imageFrogHat)
checkpointBackpack = Checkpoint.new(2800, 2850, imageBackpack)
checkpointPlush = Checkpoint.new(1200, 3300, imagePlush)
boss = Boss
enemies = {}
local spawnPoints = {
{500, 500}, {800, 500}, {1200, 500}, {1600, 500},
{2000, 500}, {2400, 500}, {3000, 500}, {3400, 500},
{1500, 1400}, {2500, 1400}, {1000, 2500}, {2000, 2500},
}
for _, pos in ipairs(spawnPoints) do
table.insert(enemies, Enemy(pos[1], pos[2]))
end
table.insert(enemies, 1, Enemy())
table.insert(items, Item("alcohol", 300, 300))
table.insert(items, Item("pill", 500, 400))
imgBeforeChoice = love.graphics.newImage("anubis.png")
imgAnubis1 = love.graphics.newImage("perdu1.png")
imgAnubis2 = love.graphics.newImage("perdu2.png")
imgRefuse1 = love.graphics.newImage("gagne1.png")
imgRefuse2 = love.graphics.newImage("gagne2.png")
imgRefuse3 = love.graphics.newImage("gagne3.png")
end
function love.load()
love.graphics.setDefaultFilter("linear", "linear")
Intro.load()
end
function love.update(dt)
if Intro.isActive() then
Intro.update(dt)
end
if Intro.isDone() and not game.state["running"] and not game.state["ended"] then
startGame()
end
if game.state["ended"] and choiceMade then
slideTimer = slideTimer + dt
if slideTimer >= slideDuration then
slideTimer = 0
slideIndex = slideIndex + 1
end
end
if not game.state["running"] then return end
Player.update(player, dt)
Player.updateBullets(dt)
Tree.checkCollision(player)
local bullets = Player.getBullets()
for i = #items, 1, -1 do
local item = items[i]
if not item.collected and item:checkPickup(player.x, player.y) then
if item.type == "alcohol" then
player.alcohol = math.min(100, player.alcohol + 20)
elseif item.type == "pill" then
player.alcohol = math.max(0, player.alcohol - 20)
end
item.collected = true
table.remove(items, i)
end
end
if player.alcohol < 30 then
player.flashTimer = player.flashTimer + dt
if player.flashTimer >= player.flashInterval then
player.flashAlpha = 1
player.flashInterval = 4 + (player.alcohol / 30) * 5
player.flashTimer = 0
end
end
if player.flashAlpha > 0 then
player.flashAlpha = player.flashAlpha - dt * 3
if player.flashAlpha < 0 then player.flashAlpha = 0 end
end
for i = #enemies, 1, -1 do
enemies[i]:move(player.x, player.y, dt)
Player.touchingEnemy(player, enemies[i], dt)
for j = #bullets, 1, -1 do
if enemies[i]:hit(bullets[j].x, bullets[j].y) then
table.remove(bullets, j)
break
end
end
if enemies[i].life <= 0 then
table.remove(enemies, i)
end
end
if #enemies == 0 then
boss.active = true
Player.setBossFight(player, true)
Player.update(player, dt)
local left = love.graphics.getWidth() / 2 - 200
local right = love.graphics.getWidth() / 2 + 200 - 50
local top = love.graphics.getHeight() / 2 - 100
local bottom = love.graphics.getHeight() / 2 + 300 - 50
player.x = math.max(left, math.min(right, player.x))
player.y = math.max(top, math.min(bottom, player.y))
end
if boss and boss.active then
boss:updateBones(dt, player)
end
if player.life <= 0 then
if boss and boss.active then
game.state["running"] = false
game.state["ended"] = true
else
local checkpoints = {checkpointBoots, checkpointFrogHat, checkpointBackpack, checkpointPlush}
local respawn = {x = 100, y = 100}
for i = 1, checkpointsData.count do
local cp = checkpoints[i]
if cp then
respawn.x = cp.x
respawn.y = cp.y
end
end
player.x = respawn.x
player.y = respawn.y
player.life = 50
player.damageCooldown = 0
end
end
-- if player.life <= 0 then
-- local checkpoints = {checkpointBoots, checkpointFrogHat, checkpointBackpack, checkpointPlush}
-- local respawn = {x = 100, y = 100}
-- for i = 1, checkpointsData.count do
-- local cp = checkpoints[i]
-- if cp then
-- respawn.x = cp.x
-- respawn.y = cp.y
-- end
-- end
-- player.x = respawn.x
-- player.y = respawn.y
-- player.life = 50
-- player.damageCooldown = 0
-- end
Camera.update(camera, player.x, player.y)
end
function love.draw()
if Intro.isActive() then
Intro.draw()
return
end
if game.state["running"] then
Player.draw(player)
Player.drawBullets()
if not boss.active then
if checkpointBackpack.show then Checkpoint.draw(checkpointBackpack) end
if checkpointPlush.show then Checkpoint.draw(checkpointPlush) end
if checkpointBoots.show then Checkpoint.draw(checkpointBoots) end
if checkpointFrogHat.show then Checkpoint.draw(checkpointFrogHat) end
love.graphics.print("Balles: " .. player.bulletsLeft .. " / " .. player.bulletsMax, 10, 10)
for i = 1, #enemies do
enemies[i]:draw()
end
end
if boss and boss.active then
boss:draw()
boss:drawBones()
end
for _, item in ipairs(items) do
item:draw()
end
Camera.attach(camera)
Map.draw(map)
Tree.draw()
Player.draw(player)
Player.drawBullets()
if checkpointBackpack.show then
Checkpoint.draw(checkpointBackpack)
end
if checkpointPlush.show then
Checkpoint.draw(checkpointPlush)
end
if checkpointBoots.show then
Checkpoint.draw(checkpointBoots)
end
if checkpointFrogHat.show then
Checkpoint.draw(checkpointFrogHat)
end
for i = 1, #enemies do
enemies[i]:draw()
end
if boss and boss.active then
boss:draw()
boss:drawBones()
end
for _, item in ipairs(items) do
item:draw()
end
Camera.detach()
-- flash overlay plein écran
if player.flashAlpha > 0 then
love.graphics.setColor(1, 1, 1, player.flashAlpha)
love.graphics.rectangle("fill", 0, 0, love.graphics.getWidth(), love.graphics.getHeight())
love.graphics.setColor(1, 1, 1, 1)
end
-- UI fixe hors caméra
love.graphics.print("Balles: " .. player.bulletsLeft .. " / " .. player.bulletsMax, 10, 10)
love.graphics.print("Alcoolémie: " .. player.alcohol .. "%", 10, 30)
end
if game.state["ended"] then
local W = love.graphics.getWidth()
local H = love.graphics.getHeight()
if not choiceMade then
local img = imgBeforeChoice
local scaleX = W / img:getWidth()
local scaleY = H / img:getHeight()
love.graphics.setColor(1, 1, 1)
love.graphics.draw(img, 0, 0, 0, scaleX, scaleY)
for _, btn in ipairs(buttons) do
if isHovered(btn) then
love.graphics.setColor(0.8, 0.8, 0.8)
else
love.graphics.setColor(0.5, 0.5, 0.5)
end
love.graphics.rectangle("fill", btn.x, btn.y, btn.w, btn.h)
love.graphics.setColor(1, 1, 1)
love.graphics.print(btn.label, btn.x + 10, btn.y + 10)
end
else
local slides
if game.anubis then
slides = { imgAnubis1, imgAnubis2 }
else
slides = { imgRefuse1, imgRefuse2, imgRefuse3 }
end
if slideIndex <= #slides then
local img = slides[slideIndex]
local scaleX = W / img:getWidth()
local scaleY = H / img:getHeight()
love.graphics.setColor(1, 1, 1)
love.graphics.draw(img, 0, 0, 0, scaleX, scaleY)
end
end
end
end
function love.keypressed(key)
if Intro.isActive() then
Intro.keypressed(key)
return
end
if key == "e" then
Player.interaction(player, checkpointBackpack, checkpointBoots, checkpointFrogHat, checkpointPlush, checkpointsData)
end
if key == "space" then
Player.shoot(player)
end
if key == "r" then
Player.reload(player)
end
if key == "left" or key == "right" then
if game.state["ended"] and not choiceMade then
if selectedBtn == 1 then
selectedBtn = 2
else
selectedBtn = 1
end
end
end
if key == "return" then
if game.state["ended"] and not choiceMade then
local btn = buttons[selectedBtn]
if btn.label == "Accept" then
game.anubis = true
choiceMade = true
elseif btn.label == "Refuse" then
game.anubis = false
choiceMade = true
end
end
end
end