-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.py
More file actions
456 lines (341 loc) · 11.8 KB
/
Copy pathMain.py
File metadata and controls
456 lines (341 loc) · 11.8 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
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
from Scripts.Windows import window
from Scripts.Cursor import cursor, crosshair
from Scripts.CustomCrosshair import custom_crosshair
from Scripts.DefaultCrosshair import default_crosshair
from Scripts.Game import game, sidebar
from Scripts.Menu import menu
from Scripts.Music import music, sound
from Scripts.Options import options
from Scripts.GameOver import gameover
from Scripts.Pause import pause
import pygame
import time
import sys
pygame.init()
# Functions ------------------------------------------------------- #
def init_windows():
global win_size, win, display
win_size, win, display = window.init_window()
def game_reset():
game.init()
sidebar.init()
gameover.init()
def spawn_entities():
global civilians, target
civilians, target = game.spawn_entities()
sidebar.posters.target_update(target)
def none():
pass
# Windows --------------------------------------------------------- #
init_windows()
window.set_icon()
pygame.display.set_caption("Wanted")
clock = pygame.time.Clock()
pygame.mouse.set_visible(False)
# Redraws --------------------------------------------------------- #
def redraw_game():
game.display.fill(window.color)
sidebar.display.fill(window.color)
# Civilians & Target
for civilian in civilians:
civilian.draw(game.display)
target.draw(game.display)
# Game & Sidebar
game.draw(display)
sidebar.draw(display)
# Windows
window.draw_game(display)
# Cursor & Crosshair
crosshair.draw("game", display)
cursor.draw("game", display)
# Blit to Screen ---------------------------------------------- #
win.blit(pygame.transform.scale(display, win_size), (0, 0))
pygame.display.update()
def redraw_menu():
# Menu
menu.draw(display)
# Cursor
cursor.draw("not_game", display)
# Blit to Screen ---------------------------------------------- #
win.blit(pygame.transform.scale(display, win_size), (0, 0))
pygame.display.update()
def redraw_options():
display.fill(window.color)
# Options
options.draw(display)
# Cursor
cursor.draw("not_game", display)
# Blit to Screen ---------------------------------------------- #
win.blit(pygame.transform.scale(display, win_size), (0, 0))
pygame.display.update()
def redraw_defaultcrosshair():
display.fill(window.color)
# Default Crosshair
default_crosshair.draw(display)
# Cursor
cursor.draw("not_game", display)
# Blit to Screen ---------------------------------------------- #
win.blit(pygame.transform.scale(display, win_size), (0, 0))
pygame.display.update()
def redraw_customcrosshair():
display.fill(window.color)
# Custom Crosshair
custom_crosshair.draw(display)
# Cursor
cursor.draw("not_game", display)
# Blit to Screen ---------------------------------------------- #
win.blit(pygame.transform.scale(display, win_size), (0, 0))
pygame.display.update()
def redraw_lost():
game.display.fill(window.color)
sidebar.display.fill(window.color)
# Civilians & Target
for civilian in civilians:
civilian.draw(game.display)
target.draw(game.display)
# Game & Sidebar
game.draw(display)
sidebar.draw(display)
# Windows
window.draw_game(display)
# Game Over
gameover.draw(display)
# Cursor
cursor.draw("not_game", display)
# Blit to Screen ---------------------------------------------- #
win.blit(pygame.transform.scale(display, win_size), (0, 0))
pygame.display.update()
def redraw_pause():
game.display.fill(window.color)
sidebar.display.fill(window.color)
# Game & Sidebar
game.draw(display)
sidebar.draw(display)
# Pause
pause.draw(display)
# Windows
window.draw_game(display)
# Cursor
cursor.draw("not_game", display)
# Blit to Screen ---------------------------------------------- #
win.blit(pygame.transform.scale(display, win_size), (0, 0))
pygame.display.update()
# Loops ----------------------------------------------------------- #
def game_loop():
game.status.time_of_start = time.time()
run = True
while run:
for event in pygame.event.get():
if event.type == pygame.QUIT:
window.update_gameinfo(options.buttons.buttons["windowsize"])
run = False
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_ESCAPE: # pause
sound.play_pause()
pause_loop()
# Game
game.handle_mousedown(event, civilians, target, spawn_entities)
# Sidebar
btn_pressed = sidebar.get_button_pressed(event)
if btn_pressed:
sound.play_pause()
sidebar.button.button[0] = False # is_hovered
pause_loop()
sidebar.handle_mousemotion(event)
# Update
window.update_deltatime()
for civilian in civilians:
civilian.update()
target.update()
cursor.update()
crosshair.update()
game.update()
redraw_game()
clock.tick(window.framerate)
game.reset_rect()
# Check if Lost
if game.status.lost:
gameover.init()
gameover.update_entities(civilians + [target])
sound.play_gameover()
lost_loop()
pygame.quit()
sys.exit()
def menu_loop():
btn_switchcase = {
"play": [spawn_entities, game_loop],
"options": [options_loop]
}
run = True
while run:
for event in pygame.event.get():
if event.type == pygame.QUIT:
window.update_gameinfo(options.buttons.buttons["windowsize"])
run = False
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_SPACE: # play
functions = btn_switchcase["play"]
for function in functions:
function()
# Menu
btn_pressed = menu.get_button_pressed(event)
if btn_pressed != None:
sound.play_button_click()
functions = btn_switchcase[btn_pressed]
for function in functions:
function(menu_loop) if function == options_loop else function()
menu.handle_mousemotion(event)
# Update
cursor.update()
redraw_menu()
clock.tick(window.framerate)
pygame.quit()
sys.exit()
def options_loop(from_loop):
btn_switchcase = {
"back": [from_loop],
"crosshair": [defaultcrosshair_loop],
"animation": [none],
"music": [music.update],
"sound": [none],
"dark_mode": [window.update_color],
"640x360": [pygame.quit, sys.exit],
"1280x720": [pygame.quit, sys.exit],
"1920x1080": [pygame.quit, sys.exit]
}
run = True
while run:
for event in pygame.event.get():
if event.type == pygame.QUIT:
window.update_gameinfo(options.buttons.buttons["windowsize"])
run = False
# Options
btn_pressed = options.get_button_pressed(event)
if btn_pressed != None:
sound.play_button_click()
functions = btn_switchcase[btn_pressed]
for function in functions:
function(from_loop) if function == defaultcrosshair_loop else function()
options.handle_mousemotion(event)
# Update
cursor.update()
redraw_options()
clock.tick(window.framerate)
pygame.quit()
sys.exit()
def defaultcrosshair_loop(options_from_loop):
btn_switchcase = {
"back": [options_loop],
"customize": [customcrosshair_loop]
}
run = True
while run:
for event in pygame.event.get():
if event.type == pygame.QUIT:
window.update_gameinfo(options.buttons.buttons["windowsize"])
run = False
# Default Crosshair
btn_pressed = default_crosshair.get_button_pressed(event)
if btn_pressed != None:
sound.play_button_click()
functions = btn_switchcase[btn_pressed]
for function in functions:
function(options_from_loop)
default_crosshair.handle_mousemotion(event)
# Update
cursor.update()
redraw_defaultcrosshair()
clock.tick(window.framerate)
pygame.quit()
sys.exit()
def customcrosshair_loop(options_from_loop):
btn_switchcase = {
"back": [defaultcrosshair_loop],
"save": [custom_crosshair.save_crosshair]
}
run = True
while run:
for event in pygame.event.get():
if event.type == pygame.QUIT:
window.update_gameinfo(options.buttons.buttons["windowsize"])
run = False
# Custom Crosshair
btn_pressed = custom_crosshair.get_button_pressed(event)
if btn_pressed != None:
sound.play_button_click()
functions = btn_switchcase[btn_pressed]
for function in functions:
function(options_from_loop) if function == defaultcrosshair_loop else function()
custom_crosshair.handle_mousemotion(event)
# Update
cursor.update()
custom_crosshair.preview.update()
redraw_customcrosshair()
clock.tick(window.framerate)
pygame.quit()
sys.exit()
def lost_loop():
btn_switchcase = {
"play": [game_reset, spawn_entities, game_loop],
"options": [options_loop],
"menu": [game_reset, menu_loop]
}
run = True
while run:
for event in pygame.event.get():
if event.type == pygame.QUIT:
window.update_gameinfo(options.buttons.buttons["windowsize"])
run = False
# GameOver
if not gameover.animation.update:
btn_pressed = gameover.get_button_pressed(event)
if btn_pressed != None:
sound.play_button_click()
functions = btn_switchcase[btn_pressed]
for function in functions:
function(lost_loop) if function == options_loop else function()
gameover.handle_mousemotion(event)
# Update
game.update()
cursor.update()
redraw_lost()
clock.tick(window.framerate)
game.reset_rect()
pygame.quit()
sys.exit()
def pause_loop():
pause.stats.update()
btn_switchcase = {
"play": [game_loop],
"restart": [game_reset, spawn_entities, game_loop],
"options": [options_loop],
"menu": [game_reset, menu_loop]
}
run = True
while run:
for event in pygame.event.get():
if event.type == pygame.QUIT:
window.update_gameinfo(options.buttons.buttons["windowsize"])
run = False
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_ESCAPE: # play
functions = btn_switchcase["play"]
for function in functions:
function()
# Pause
btn_pressed = pause.get_button_pressed(event)
if btn_pressed != None:
sound.play_button_click()
functions = btn_switchcase[btn_pressed]
for function in functions:
function(pause_loop) if function == options_loop else function()
pause.handle_mousemotion(event)
# Update
cursor.update()
redraw_pause()
clock.tick(window.framerate)
game.reset_rect()
pygame.quit()
sys.exit()
# Execute --------------------------------------------------------- #
menu_loop()