-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmain.lua
374 lines (332 loc) · 8.82 KB
/
main.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
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
367
368
369
370
371
372
373
#!/usr/bin/env -S love ./
-- Permet de l'exécuter avec ./main.lua
-- vim: fdm=marker
--METTEZ OU IL FAUT LE METTRE SVP
require "scripts/menus"
require "scripts/player"
require "scripts/enemy"
require "scripts/block"
require "scripts/constants"
--CM = require "lib.CameraMgr".newManager()
-- EVENTS{{{1
function love.load() -- LOAD {{{2
-- UI
menus = {'menu', 'game_over', 'pause', 'credits', 'tuto'}
buttons = {}
ww = love.graphics.getWidth()
wh = love.graphics.getHeight()
CameraY = 0
--CM.setCoords(ww/2, wh/2)
button_width = ww * (1/3)
margin = 16
flashalpha = 0
flashalpha_speed = 2
-- Window
love.window.setTitle("Ludum Dare 49") --TODO: PLEASE CHANGE
-- Proper font scaling
font = love.graphics.newFont(15, "none", 3)
love.graphics.setFont(font)
font = love.graphics.newFont(32)
font = game_font_small_light
-- Menu {{{3
sprite_btn = love.graphics.newImage("assets/button2.png"),
start_menu('menu') -- valeurs possibles menu,in_game, pause, game_over
in_game_timer = 0
global_timer = 0
load_credits()
-- Particles
particles = {}
coll_check = false
gas_puffs = {}
for i=0, screenw ,30 do
table.insert(gas_puffs, {
x = i,
y = 0,
s = (love.math.random() + 1) * 0.2,
r = love.math.random() * 2*math.pi,
dr= (love.math.random() - 0.5) * 0.2
})
end
-- Debug
enemy_wont_move = true
-- Smoke
smoke_dt = 1
end
function love.update(dt) -- UPDATE {{{2
--CM.update(dt)
global_timer = global_timer + dt
if menu == 'in_game' then
smoke_dt = smoke_dt - dt
down_screen_dt = down_screen_dt + dt*20
in_game_timer = in_game_timer + dt
player_update()
enemy_update(dt)
-- Evit bomb quit map
if b.y < 0-blockh-1 or b.x < 0-blockw-1 or b.x > 800+blockw+1 then
p.hasBomb = true
end
while down_screen_dt >= 0 do
down_screen_dt = down_screen_dt - 0.3
CameraY = CameraY + 1
CameraYAdd = CameraYAdd + 1
p.y = p.y - 1
b.y = b.y - 1
for i,enemy in ipairs(total_enemy) do --vacciné
enemy.y = enemy.y - 1
end
end
while CameraYAdd > blockh+10 do
CameraYAdd = CameraYAdd - blockh
-- Creer un element dans map
-- Supprimer le premier element de la map
table.remove(map, 1)
table.insert(map, {})
for _ = 1, nb_block_x do
rd = love.math.random(9)
if rd == 1 then
table.insert(map[#map], 1)
elseif rd == 2 or rd == 3 or rd == 4 then
table.insert(map[#map], 2)
elseif rd == 5 or rd == 6 or rd == 7 then
table.insert(map[#map], 3)
else
table.insert(map[#map], 0)
end
end
DeletedMapBlock = DeletedMapBlock + 1
-- Spawn enemies
if love.math.random(10) < DeletedMapBlock*0.05+1 then
spawn_enemy(love.math.random(800),1000)
end
end
-- Music
if b.active then
music_calm:setVolume(0)
music_tense:setVolume(0.2)
else
music_calm:setVolume(0.2)
music_tense:setVolume(0)
end
-- Gas puffs
for i,v in ipairs(gas_puffs) do
v.r = v.r + v.dr
end
else
music_calm:setVolume(0)
music_tense:setVolume(0)
end
for i, pt in ipairs(particles) do
update_particle(pt, dt)
if pt.mustdestroy then
table.remove(particles, i)
end
end
end
function love.mousepressed( x, y, button, istouch, presses )
if has_value(menus,menu) then
update_buttons(button, x, y)
end
end
function love.mousemoved(x, y, dx, dy, istouch)
if has_value(menus,menu) then
update_buttons(0, x, y)
end
end
function love.keypressed(key, scancode, isrepeat) -- KEYPRESSED {{{2
-- always {{{3
if (love.keyboard.isDown("lctrl") and key == "c") then
love.event.quit()
end
if key == "f5" then love.event.quit("restart") end
if key == "f3" then debug = not debug end
if menu == "in_game" then -- in_game {{{3
if key == "escape" then
start_menu("pause")
end
elseif menu == "pause" then -- in_game {{{3
if key == "escape" then
continue_game("pause")
end
elseif menu == "credits" or menu == "tuto" then
if key == "escape" then
start_menu("menu")
end
end
end
function love.draw() -- DRAWING {{{2
--CM.attach() -- CE QUI EST RELATIF A LA CAMERA
love.graphics.setColor(255, 255, 255, 1.0)
if menu == 'in_game' then -- {{{3
--love.graphics.rectangle("fill",600, 100,100,20,40,1)
block_draw()
draw_player()
draw_bomb()
for _,enemy in ipairs(total_enemy) do --vacciné
draw_enemy(enemy)
end
player_cursor()
for _,pt in ipairs(particles) do
draw_particle(pt)
end
-- Draw toxic gas
if smoke_dt < 0 or true then
smoke_dt = 1
for i,v in ipairs(gas_puffs) do
love.graphics.draw(toxic_gas, v.x, v.y, v.r, v.s, v.s,
toxic_gas:getWidth()*v.s, toxic_gas:getHeight()*v.s)
--spawn_smoke(i, 10, "green")
end
end
--all_hit
for i,hit in ipairs(all_hit) do
love.graphics.print(hit.txt, hit.x, hit.y)
hit.dt = hit.dt - 0.16
if hit.dt < 0 then
table.remove(all_hit, i)
end
end
--zombie life bar
for i,enemy in ipairs(total_enemy) do --vacciné
love.graphics.setColor(0,0,0,1)
love.graphics.setLineWidth(5)
love.graphics.line(enemy.x,enemy.y-10, enemy.x+80, enemy.y-10)
love.graphics.setColor(1,0,0,1)
love.graphics.setLineWidth(2)
love.graphics.line(enemy.x+2,enemy.y-10, enemy.x+(26*enemy.hp), enemy.y-10)
love.graphics.setColor(1,1,1,1)
end
-- life bar
draw_gui()
-- vv KEEP AS THE LAST vv
draw_cursor()
end
if debug then -- {{{3
draw_debug_unfix()
end
--CM.detach() -- CE QUI EST FIX DANS L ÉCRAN
if debug then -- {{{3
draw_debug()
end
if has_value(menus,menu) then -- menu {{{3
draw_menu()
end
end
function draw_gui()
for i=1, p.max_life do
local w = img_heart:getWidth()*0.2 + 10
if i <= p.life then
love.graphics.draw(img_heart, screenw-i*w, 20, 0, 0.2)
else
love.graphics.draw(img_heart_empty, screenw-i*w, 20, 0, 0.2)
end
end
love.graphics.setFont(game_font_medium)
love.graphics.print(p.score, screenw + 50, 20)
love.graphics.setFont(game_font_medium)
-- afficher lescore
love.graphics.print("Score : "..p.score, 10,0)
end
-- Function {{{1
function newButton(text, fn) -- {{{2
return {
text=text,
fn=fn,
now= false,
last = false,
color = {0.4, 0.4, 0.5, 1.0}
}
end
function start_game()
color = 1
total_enemy = {}
-- flou a la fin
alcohol_level = 0
--hit
all_hit = {
--x: b.x + random
--y: b.y + random
--dt: 3
}
--map
down_screen_dt = 0.3
spawn_enemy(100,100)
spawn_enemy(200,100)
--spawn_enemy(100,1000)
CameraY = 0
DeletedMapBlock = 0
CameraYAdd = 0
love.mouse.setVisible(false)
player_create()
bomb_create()
block_create()
in_game_timer = 0
map = make_blank_map(nb_block_y, nb_block_x)
set_map(map, 1, 0, 1)
set_map(map, 1, 1, 1)
set_map(map, 1, 4, 1)
menu = 'in_game'
--CM.update(0)
dead_way = nil
-- Music
music_calm:play()
music_tense:play()
end
function continue_game()
love.mouse.setVisible(false)
menu = 'in_game'
--CM.update(0)
end
-- USELESS FUNCTIONS {{{2
function debug_print(ps, txt)
love.graphics.print(txt, default_font,10, ps*20+100)
end
function draw_debug()
love.graphics.setColor(255, 255, 255, 1.0)
if menu == 'in_game' then
--love.graphics.print(math.floor(b.x).."/"..math.floor(b.y), b.x+50, b.y) -- coordonnées bomb
--love.graphics.print(b.catch_cooldown, b.x+50, b.y-20) -- coordonnées bomb
--love.graphics.print(coll,16,16)
love.graphics.setColor(0, 0, 0, 1.0)
debug_print(1, "player x:"..math.floor(p.x).." y:"..math.floor(p.y))
debug_print(2, "player dx:"..math.floor(p.dx).." dy:"..math.floor(p.dy))
debug_print(3, "player lx:"..(math.floor((p.x+p.w)/bl.w)+1).." ly:"..math.floor((p.y+p.h+CameraY)/bl.h)+1)
debug_print(4, "FPS: "..love.timer.getFPS())
debug_print(5, "bomb x:"..math.floor(b.x).." y:"..math.floor(b.y))
debug_print(6, "bomb timer:"..math.floor(b.timer * 1000)/1000)
debug_print(7, "bomb active:"..tostring(b.active))
debug_print(8, "has bomb: "..tostring(p.hasBomb))
debug_print(9, "CameraY: "..tostring(CameraY))
debug_print(10, "CameraYAdd: "..tostring(CameraYAdd))
debug_print(11, "DeletedMapBlock: "..tostring(DeletedMapBlock))
debug_print(12, "Vie: "..tostring(p.life))
debug_print(13, "p.iframe: "..tostring(p.iframes))
love.graphics.setColor(255, 255, 255, 1.0)
for i,v in ipairs(map) do
--lllig= ""
for j,u in ipairs(v) do
love.graphics.print(tostring(u),default_font,(j-1)* blockw, (i-1)*blockw-CameraYAdd)
--lllig = lllig..tostring(u)
end
--print(lllig)
end
--print("-----")
love.graphics.setColor(1,0,0)
love.graphics.line(screenw2, screenh2, screenw2 + 64, screenh2)
love.graphics.setColor(0,1,0)
love.graphics.line(screenw2, screenh2, screenw2, screenh2 + 64)
love.graphics.setColor(0,0,0)
end
-- debug_print(0, "debug: is_on ; menu: "..menu)
end
function draw_debug_unfix()
love.graphics.setColor(255, 255, 255, 1.0)
if menu == 'in_game' then
draw_collision(b.x,b.y,b.w,b.h)
draw_collision(p.x,p.y,p.w,p.h)
for i,enemy in ipairs(total_enemy) do --vacciné
if enemy.hp > 0 then
draw_collision(enemy.x,enemy.y,enemy.w,enemy.h)
end
end
end
end