-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.py
770 lines (686 loc) · 24.3 KB
/
config.py
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
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
import pygame as pg
import random # For generating random values
from math import * # Importing math functions
import os # Importing os for centering the game window
# A clock for timers and running loops at constant fps
clock = pg.time.Clock()
# Variable that game is running
running_game = True
# Centering the game window
os.environ['SDL_VIDEO_CENTERED'] = '1'
# Setting dimensions of the game window
screen_height = 1080
screen_width = 1920
# print(screen_width / 3 + 80)
# Parameters for Player1
pl1_X = screen_width / 3 + 100 # Initial horizontal position
pl1_Y = screen_height - 50 # Initial vertical position
p1_play = True # Whether it is player 1's turn or not
score_p1 = 0 # Storing the score
pl1_changeX = 0 # Change in horizontal position in each frame
pl1_changeY = 0 # Change in vertical position in each frame
ship_change1 = 1 # The speed of moving obstacles for player 1
time_p1 = 0 # The time taken by player to complete the round
died_p1 = False # Storing whether the player died or completed the round
idle_time_p1 = 0 # Idle time for player 1
# Parameters for Player2
pl2_X = screen_width / 3 + 100 # Initial horizontal position
pl2_Y = -20 # Initial vertical position
p2_play = False # Whether it is player 2's turn or not
score_p2 = 0 # Storing the score
pl2_changeX = 0 # Change in horizontal position in each frame
pl2_changeY = 0 # Change in vertical position in each frame
ship_change2 = 1 # The speed of moving obstacles for player 2
time_p2 = 0 # The time taken by player to complete the round
died_p2 = False # Storing whether the player died or completed the round
idle_time_p2 = 0 # Idle time for player 2
# RGB value for colors of slab
brown_color = (156, 91, 91)
# Loading the icons for all the players, obstacles, coins
pl1_img = pg.image.load("icons/pl1.png") # Player 1
pl2_img = pg.image.load("icons/pl2.png") # Player 2
icon = pg.image.load("icons/icon.png") # Icon for game window
rock_img = pg.image.load("icons/rock.png") # Fixed Obstacle 1
stone_img = pg.image.load("icons/stone.png") # Fixed Obstacle 2
ship_img = pg.image.load("icons/ship.png") # Moving Obstacle 1
shark_img = pg.image.load('icons/shark.png') # Moving Obstacle 2
coin_img = pg.image.load('icons/coin.png') # Bonus Coin
loot_img = pg.image.load('icons/coinloot.png') # Bonus Coins
# Making list of Fixed and Moving Obstacles' Images respectively
fixed_obstacle_img = [rock_img, stone_img]
moving_obstacles_img = [ship_img, shark_img]
# Initializing the game window
screen = pg.display.set_mode((screen_width, screen_height)) # Width and Height
pg.display.set_caption("Captain Crooks") # Window Caption
pg.display.set_icon(icon) # Window Icon
# List to store the position of all the slabs
slab_height = []
# Adding the slab positions
for i in range(5):
slab_height.append(screen_height // 5 * i + 10)
slab_height.append(screen_height - 10)
# List for span of each partition made by slabs
partitions = []
for i in range(5):
partitions.append([slab_height[i], slab_height[i + 1]])
pg.init()
# Font for Score and Time
font = pg.font.SysFont(None, 28)
# Generating the parameters for Fixed Obstacles
fixed_obstacles = []
for i in range(1, len(slab_height) - 1):
count = 0
third = screen_width / 3
for j in range(random.randint(1, 3)):
fixed_obstacles.append([
fixed_obstacle_img[random.randint(0, 1)],
random.randint(third * count + 10, third * (count + 1) - 60),
slab_height[i] - 50,
False
])
count += 1
fixed_obstacles.append([
fixed_obstacle_img[random.randint(0, 1)],
random.randint((screen_width / 3) * 2 + 10, (screen_width / 3) * 3 - 60),
slab_height[0] - 50,
False
])
fixed_obstacles.append([
fixed_obstacle_img[random.randint(0, 1)],
random.randint(10, (screen_width / 3) - 60),
slab_height[5] - 50,
False
])
fixed_obstacles.append([
fixed_obstacle_img[random.randint(0, 1)],
random.randint((screen_width / 3) * 2 + 10, (screen_width / 3) * 3 - 60),
slab_height[5] - 50,
False
])
# Generating parameters for Moving Obstacles for Both the players
# These differ only in the speed of the obstacles
moving_obstacles1 = []
moving_obstacles2 = []
for part in partitions:
count = 0
third = screen_width / 2
for i in range(random.randint(1, 2)):
moving_obstacles1.append([
random.randint(third * count + 10, third * (count + 1) - 60),
random.randint(part[0] + 10, part[1] - 70),
ship_change1 + random.randint(-1, 1) / 2,
False,
moving_obstacles_img[random.randint(0, 1)]
])
count += 1
for i in moving_obstacles1:
moving_obstacles2.append(
[i[0], i[1], ship_change2 + random.randint(-1, 1) / 2, i[3], i[4]])
# Storing the bonus object images
coins = [coin_img, loot_img]
# Generating the parameters for bonus objects
coin = []
for part in partitions:
for i in range(random.randint(0, 1)):
coin.append([
coins[random.randint(0, 1)],
random.randint(50, screen_width - 50),
random.randint(part[0] + 10, part[1] - 70),
True
])
# Function to calculate distance between two points
def distance(x1, y1, x2, y2):
return sqrt(pow(x1 - x2, 2) + pow(y1 - y2, 2))
# Function to check collision
def is_collision(x1, y1, x2, y2):
if distance(x1, y1, x2, y2) < 64:
return True
return False
# Function to add Player1 according to turn
def player1(x, y, z):
if z:
screen.blit(pl1_img, (x, y))
# Function to add Player2 according to turn
def player2(x, y, z):
if z:
screen.blit(pl2_img, (x, y))
# Function to display the score of the current player
def disp_score(a, b, c, d):
if b:
score1 = font.render('Score: ' + str(a), True, (255, 255, 255))
elif d:
score1 = font.render('Score: ' + str(c), True, (255, 255, 255))
screen.blit(score1, (0, 0))
# Function to display the time of the current player
def disp_time(a, b, c, d):
if b:
time1 = font.render('Time: ' + str(round(a, 3)), True, (255, 255, 255))
elif d:
time1 = font.render('Time: ' + str(round(c, 3)), True, (255, 255, 255))
screen.blit(time1, (screen_width - 150, 0))
# Function to display the starting point of the current player
def start_point(x, y):
start_mssg = font.render('START', True, (255, 255, 255))
if x:
screen.blit(start_mssg, (screen_width / 3 + 80, screen_height - 30))
elif y:
screen.blit(start_mssg, (screen_width / 3 + 80, 7))
# Function to display the end point of the current player
def end_point(x, y):
end_mssg = font.render('END', True, (255, 255, 255))
if x:
screen.blit(end_mssg, (screen_width / 3 + 80, 7))
elif y:
screen.blit(end_mssg, (screen_width / 3 + 80, screen_height - 30))
# Generate text surface
def text_objects(font_x, text, clr):
text_surface = font_x.render(text, True, clr)
return text_surface, text_surface.get_rect()
# Displaying Screen - centered text messages
def draw_text(surf, text, size, y, clr):
font1 = pg.font.SysFont(None, size)
text_surf, text_rect = text_objects(font1, text, clr)
text_rect.center = (screen_width // 2), y
surf.blit(text_surf, text_rect)
# Function to reset the game
def reset_game():
global pl1_X
global pl1_Y
global p1_play
global score_p1
global pl1_changeX
global pl1_changeY
global ship_change1
global time_p1
global died_p1
pl1_X = screen_width / 3 + 100
pl1_Y = screen_height - 50
p1_play = True
score_p1 = 0
pl1_changeX = 0
pl1_changeY = 0
ship_change1 = 1
time_p1 = 0
died_p1 = False
global pl2_X
global pl2_Y
global p2_play
global score_p2
global pl2_changeX
global pl2_changeY
global ship_change2
global time_p2
global died_p2
pl2_X = screen_width / 3 + 100
pl2_Y = -20
p2_play = False
score_p2 = 0
pl2_changeX = 0
pl2_changeY = 0
ship_change2 = 1
time_p2 = 0
died_p2 = False
globals()['idle_time_p1'] = 0
globals()['idle_time_p2'] = 0
global moving_obstacles1
global moving_obstacles2
global fixed_obstacles
global coin
moving_obstacles2 = []
moving_obstacles1 = []
fixed_obstacles = []
coin = []
for i in range(1, len(slab_height) - 1):
count = 0
third = screen_width / 3
for j in range(random.randint(1, 3)):
fixed_obstacles.append([
fixed_obstacle_img[random.randint(0, 1)],
random.randint(third * count + 10, third * (count + 1) - 60),
slab_height[i] - 50,
False
])
count += 1
fixed_obstacles.append([
fixed_obstacle_img[random.randint(0, 1)],
random.randint(
(screen_width / 3) * 2 + 10,
(screen_width / 3) * 3 - 60),
slab_height[0] - 50,
False
])
fixed_obstacles.append([
fixed_obstacle_img[random.randint(0, 1)],
random.randint(10, (screen_width / 3) - 60),
slab_height[5] - 50,
False
])
fixed_obstacles.append([
fixed_obstacle_img[random.randint(0, 1)],
random.randint(
(screen_width / 3) * 2 + 10,
(screen_width / 3) * 3 - 60),
slab_height[5] - 50,
False
])
for part in partitions:
count = 0
third = screen_width / 2
for i in range(random.randint(1, 2)):
moving_obstacles1.append([
random.randint(third * count + 10, third * (count + 1) - 60),
random.randint(part[0] + 10, part[1] - 70),
ship_change1 + random.randint(-1, 1) / 2,
False,
moving_obstacles_img[random.randint(0, 1)]
])
count += 1
for i in moving_obstacles1:
moving_obstacles2.append(
[i[0], i[1], ship_change2 + random.randint(-1, 1) / 2, i[3], i[4]])
for part in partitions:
for i in range(random.randint(0, 1)):
coin.append([
coins[random.randint(0, 1)],
random.randint(50, screen_width - 50),
random.randint(part[0] + 10, part[1] - 70),
True
])
# Function to confirm reset in pause menu
def confirm():
text_color = (37, 225, 181)
screen.fill((255, 255, 255))
menu_confirm = True
while menu_confirm:
clock.tick(144)
draw_text(
screen,
'Press Enter to continue',
80,
screen_height // 4,
text_color)
draw_text(
screen,
'Press Escape to cancel',
80,
3 * screen_height // 4,
text_color)
keys = pg.key.get_pressed()
for event in pg.event.get():
if keys[pg.K_LALT] or keys[pg.K_RALT]:
if keys[pg.K_F4]:
menu_confirm = False
globals()['running_game'] = False
if event.type == pg.QUIT:
menu_confirm = False
globals()['running_game'] = False
if event.type == pg.KEYUP:
if event.key == pg.K_RETURN:
reset_game()
menu_confirm = False
if event.type == pg.KEYUP:
if event.key == pg.K_ESCAPE:
menu_confirm = False
pg.display.update()
return False
# Function for the case if player 1 collides with an obstacle
def trans_died():
for obst in fixed_obstacles:
obst[3] = False
screen.fill((30, 30, 30))
global coin
globals()['p1_play'] = False
globals()['p2_play'] = True
globals()['died_p1'] = True
globals()['idle_time_p1'] = 0
globals()['idle_time_p2'] = 0
for i in coin:
i[3] = True
wait = True
while wait:
clock.tick(144)
draw_text(screen, 'Player1 Died', 80, screen_height // 4, (200, 0, 0))
draw_text(screen,
'Score: ' + str(globals()['score_p1']), 50,
2 * screen_height // 4 - 30, (200, 0, 0)
)
draw_text(screen,
'Time: ' + str(round(globals()['time_p1'], 3)), 50,
2 * screen_height // 4 + 30, (200, 0, 0)
)
draw_text(screen, 'Press Enter to continue', 30,
3 * screen_height // 4, (200, 0, 0))
pg.display.flip()
keys = pg.key.get_pressed()
for event in pg.event.get():
if keys[pg.K_LALT] or keys[pg.K_RALT]:
if keys[pg.K_F4]:
wait = False
globals()['running_game'] = False
if event.type == pg.QUIT:
wait = False
globals()['running_game'] = False
if event.type == pg.KEYUP:
if event.key == pg.K_RETURN:
wait = False
pg.display.update()
globals()['score_p1'] = 0
globals()['time_p1'] = 0
# Function for the case if Player 1 reaches the end
def trans_win():
for obst in fixed_obstacles:
obst[3] = False
screen.fill((30, 30, 30))
globals()['p1_play'] = False
globals()['p2_play'] = True
globals()['died_p1'] = False
globals()['idle_time_p1'] = 0
globals()['idle_time_p2'] = 0
global coin
for i in coin:
i[3] = True
wait = True
while wait:
clock.tick(144)
draw_text(screen, 'Hurray!!! Player1 reached the end',
80, screen_height // 4, (200, 0, 0))
draw_text(screen,
'Score: ' + str(globals()['score_p1']), 50,
2 * screen_height // 4 - 30, (200, 0, 0)
)
draw_text(screen,
'Time: ' + str(round(globals()['time_p1'], 3)), 50,
2 * screen_height // 4 + 30, (200, 0, 0)
)
draw_text(screen, 'Press Enter to continue', 30,
3 * screen_height // 4, (200, 0, 0))
pg.display.flip()
keys = pg.key.get_pressed()
for event in pg.event.get():
if keys[pg.K_LALT] or keys[pg.K_RALT]:
if keys[pg.K_F4]:
wait = False
globals()['running_game'] = False
if event.type == pg.QUIT:
wait = False
globals()['running_game'] = False
if event.type == pg.KEYUP:
if event.key == pg.K_RETURN:
wait = False
pg.display.update()
globals()['score_p1'] = 0
globals()['time_p1'] = 0
# Function for the case if Player 2 dies in the game
def new_round():
screen.fill((30, 30, 30))
globals()['p2_play'] = False
globals()['p1_play'] = True
globals()['idle_time_p1'] = 0
globals()['idle_time_p2'] = 0
for obst in fixed_obstacles:
obst[3] = False
global moving_obstacles2
global moving_obstacles1
global coin
moving_obstacles2 = []
moving_obstacles1 = []
coin = []
globals()['died_p2'] = True
winner = 0
if globals()['died_p2'] == globals()['died_p1']:
if globals()['score_p1'] > globals()['score_p2']:
winner = 1
globals()['ship_change1'] += 0.5
elif globals()['score_p1'] < globals()['score_p2']:
winner = 2
globals()['ship_change2'] += 0.5
elif globals()['score_p1'] == globals()['score_p2']:
if globals()['time_p1'] > globals()['time_p2']:
winner = 2
globals()['ship_change2'] += 0.5
elif globals()['time_p1'] < globals()['time_p2']:
winner = 1
globals()['ship_change1'] += 0.5
else:
winner = 0
globals()['ship_change1'] += 0.5
globals()['ship_change2'] += 0.5
elif globals()['died_p1']:
winner = 1
elif globals()['died_p2']:
winner = 2
wait = True
while wait:
clock.tick(144)
draw_text(screen, 'Player2 Died', 80, screen_height // 5, (200, 0, 0))
draw_text(screen,
'Score: ' + str(globals()['score_p2']), 50,
2 * screen_height // 5 - 30, (200, 0, 0)
)
draw_text(screen,
'Time: ' + str(round(globals()['time_p2'], 3)), 50,
2 * screen_height // 5 + 30, (200, 0, 0)
)
if winner != 0:
draw_text(screen, 'Player' +
str(winner) +
' won this round!!', 40, 3 *
screen_height //
5, (200, 0, 0))
else:
draw_text(
screen,
'The round was tied, increasing speeds for both',
40,
3 *
screen_height //
5,
(200,
0,
0))
draw_text(screen,
"Press Enter for the next round", 30,
4 * screen_height // 5 + 30, (200, 0, 0)
)
pg.display.flip()
keys = pg.key.get_pressed()
for events in pg.event.get():
if keys[pg.K_LALT] or keys[pg.K_RALT]:
if keys[pg.K_F4]:
wait = False
globals()['running_game'] = False
if events.type == pg.QUIT:
wait = False
globals()['running_game'] = False
if events.type == pg.KEYUP:
if events.key == pg.K_RETURN:
wait = False
pg.display.update()
for part in partitions:
for i in range(random.randint(0, 1)):
coin.append([
coins[random.randint(0, 1)],
random.randint(50, screen_width - 50),
random.randint(part[0] + 10, part[1] - 70),
True
])
for part in partitions:
count = 0
third = screen_width / 2
for i in range(random.randint(1, 2)):
moving_obstacles1.append([
random.randint(third * count + 10, third * (count + 1) - 60),
random.randint(part[0] + 10, part[1] - 70),
ship_change1 + random.randint(-1, 1) / 2,
False,
moving_obstacles_img[random.randint(0, 1)]
])
count += 1
for i in moving_obstacles1:
moving_obstacles2.append(
[i[0], i[1], ship_change2 + random.randint(-1, 1) / 2, i[3], i[4]])
globals()['score_p1'] = 0
globals()['time_p1'] = 0
globals()['score_p2'] = 0
globals()['time_p2'] = 0
globals()['pl1_X'] = screen_width / 3 + 100
globals()['pl1_Y'] = screen_height - 50
globals()['pl2_X'] = screen_width / 3 + 100
globals()['pl2_Y'] = -20
globals()['pl2_changeX'] = 0
globals()['pl2_changeY'] = 0
globals()['pl1_changeX'] = 0
globals()['pl1_changeY'] = 0
# Function for the case if Player 2 reaches the end
def new_round_win():
screen.fill((30, 30, 30))
globals()['p2_play'] = False
globals()['p1_play'] = True
globals()['idle_time_p1'] = 0
globals()['idle_time_p2'] = 0
for obst in fixed_obstacles:
obst[3] = False
global moving_obstacles2
global moving_obstacles1
moving_obstacles2 = []
moving_obstacles1 = []
global coin
coin = []
globals()['died_p2'] = False
winner = 0
if globals()['died_p2'] == globals()['died_p1']:
if globals()['score_p1'] > globals()['score_p2']:
winner = 1
globals()['ship_change1'] += 0.5
elif globals()['score_p1'] < globals()['score_p2']:
winner = 2
globals()['ship_change2'] += 0.5
elif globals()['score_p1'] == globals()['score_p2']:
if globals()['time_p1'] > globals()['time_p2']:
winner = 2
globals()['ship_change2'] += 0.5
elif globals()['time_p1'] < globals()['time_p2']:
winner = 1
globals()['ship_change1'] += 0.5
else:
winner = 0
globals()['ship_change1'] += 0.5
globals()['ship_change2'] += 0.5
elif globals()['died_p1']:
winner = 1
elif globals()['died_p2']:
winner = 2
wait = True
while wait:
clock.tick(144)
draw_text(screen, 'Hurray!!! Player2 reached the end',
80, screen_height // 5, (200, 0, 0))
draw_text(screen,
'Score: ' + str(globals()['score_p2']), 50,
2 * screen_height // 5 - 30, (200, 0, 0)
)
draw_text(screen,
'Time: ' + str(round(globals()['time_p2'], 3)), 50,
2 * screen_height // 5 + 30, (200, 0, 0)
)
if winner != 0:
draw_text(screen, 'Player' +
str(winner) +
' won this round!!', 40, 3 *
screen_height //
5, (200, 0, 0))
else:
draw_text(
screen,
'The round was tied, increasing speeds for both',
40,
3 *
screen_height //
5,
(200,
0,
0))
draw_text(screen,
"Press Enter for the next round", 30,
4 * screen_height // 5 + 30, (200, 0, 0)
)
pg.display.flip()
keys = pg.key.get_pressed()
for events in pg.event.get():
if keys[pg.K_LALT] or keys[pg.K_RALT]:
if keys[pg.K_F4]:
wait = False
globals()['running_game'] = False
if events.type == pg.QUIT:
wait = False
globals()['running_game'] = False
if events.type == pg.KEYUP:
if events.key == pg.K_RETURN:
wait = False
pg.display.update()
for part in partitions:
for i in range(random.randint(0, 1)):
coin.append([
coins[random.randint(0, 1)],
random.randint(50, screen_width - 50),
random.randint(part[0] + 10, part[1] - 70),
True
])
for part in partitions:
count = 0
third = screen_width / 2
for i in range(random.randint(1, 2)):
moving_obstacles1.append([
random.randint(third * count + 10, third * (count + 1) - 60),
random.randint(part[0] + 10, part[1] - 70),
ship_change1 + random.randint(-1, 1) / 2,
False,
moving_obstacles_img[random.randint(0, 1)]
])
count += 1
for i in moving_obstacles1:
moving_obstacles2.append(
[i[0], i[1], ship_change2 + random.randint(-1, 1) / 2, i[3], i[4]])
globals()['score_p1'] = 0
globals()['time_p1'] = 0
globals()['score_p2'] = 0
globals()['time_p2'] = 0
globals()['pl1_X'] = screen_width / 3 + 100
globals()['pl1_Y'] = screen_height - 50
globals()['pl2_X'] = screen_width / 3 + 100
globals()['pl2_Y'] = -20
globals()['pl2_changeX'] = 0
globals()['pl2_changeY'] = 0
globals()['pl1_changeX'] = 0
globals()['pl1_changeY'] = 0
# Function for pause menu
def pause_game():
text_color = (37, 225, 181)
game_paused = True
screen.fill((255, 255, 255))
while game_paused:
clock.tick(144)
draw_text(screen, 'Game Paused', 80, screen_height // 4, text_color)
draw_text(
screen,
'Press Enter to Continue',
50,
2 * screen_height // 4,
text_color)
draw_text(screen, 'Press Backspace to Reset Whole Game',
50, 3 * screen_height // 4, text_color)
keys = pg.key.get_pressed()
for event in pg.event.get():
if keys[pg.K_LALT] or keys[pg.K_RALT]:
if keys[pg.K_F4]:
game_paused = False
globals()['running_game'] = False
if event.type == pg.QUIT:
game_paused = False
globals()['running_game'] = False
if event.type == pg.KEYUP:
if event.key in [pg.K_ESCAPE, pg.K_RETURN]:
game_paused = False
if event.key == pg.K_BACKSPACE:
game_paused = confirm()
pg.display.update()