forked from bchipman/cs113_game
-
Notifications
You must be signed in to change notification settings - Fork 1
/
pages.py
857 lines (687 loc) · 32.7 KB
/
pages.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
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
# python standard library modules
import os
import sys
import textwrap
import pygbutton
# pygame
import pygame
from pygame.locals import *
# our modules
import globals as GL
from globals import *
from pygbutton import *
from classes import *
selection_box_width = 4
class StartMenu:
def __init__(self):
self.bg_image = pygame.image.load('data/background2.png')
self.start_button = PygButton((325, 395, 140, 40), 'Start')
self.help_button = PygButton((485, 395, 110, 40), 'Help')
self.options_button = PygButton((615, 395, 175, 40), 'Options')
self.exit_button = PygButton((810, 395, 105, 40), 'Exit')
AUDIO.turn_on_music()
title_font = pygame.font.Font('data/Kremlin.ttf', 50)
self.title_font1 = title_font.render('Famished', True, DKRED)
self.title_font2 = title_font.render('Tournament', True, DKRED)
self.selection_box_properties = [(325, 395, 140, 40), (485, 395, 110, 40), (615, 395, 175, 40), (810, 395, 105, 40)]
self.selection_box_i = 0
def __call__(self):
self.return_now = False
while not self.return_now:
self.draw()
self.input()
self.events()
GL.CLOCK.tick(GL.FPS)
def draw(self):
GL.SCREEN.blit(self.bg_image, (0, 0))
self.start_button.draw(GL.SCREEN)
self.help_button.draw(GL.SCREEN)
self.options_button.draw(GL.SCREEN)
self.exit_button.draw(GL.SCREEN)
GL.SCREEN.blit(self.title_font1, (495, 120))
GL.SCREEN.blit(self.title_font2, (450, 175))
self.selection_box = Rect2(self.selection_box_properties[self.selection_box_i], color=BLUE)
pygame.draw.rect(GL.SCREEN, self.selection_box.color, self.selection_box, selection_box_width)
pygame.display.update()
def input(self):
GL.INPUT1.refresh()
if GL.INPUT1.SELECT_PRESS_EVENT:
GL.INPUT1.SELECT_PRESS_EVENT = False
if GL.INPUT1.B_PRESS_EVENT:
GL.INPUT1.B_PRESS_EVENT = False
if GL.INPUT1.START_PRESS_EVENT or GL.INPUT1.A_PRESS_EVENT:
if GL.INPUT1.START_PRESS_EVENT:
GL.INPUT1.START_PRESS_EVENT = False
if GL.INPUT1.A_PRESS_EVENT:
GL.INPUT1.A_PRESS_EVENT = False
if self.selection_box_i == 0:
self.return_now = True
GL.NEXT_PAGE = 'PlayerSelectPage()'
elif self.selection_box_i == 1:
self.return_now = True
GL.NEXT_PAGE = 'help'
elif self.selection_box_i == 2:
self.return_now = True
GL.NEXT_PAGE = 'options'
elif self.selection_box_i == 3:
self.return_now = True
EXIT_GAME()
if GL.INPUT1.RIGHT_PRESS_EVENT:
GL.INPUT1.RIGHT_PRESS_EVENT = False
self.selection_box_i += 1
if self.selection_box_i > 3:
self.selection_box_i = 0
if GL.INPUT1.LEFT_PRESS_EVENT:
GL.INPUT1.LEFT_PRESS_EVENT = False
self.selection_box_i -= 1
if self.selection_box_i < 0:
self.selection_box_i = 3
def events(self):
for event in pygame.event.get():
if 'click' in self.start_button.handleEvent(event):
self.selection_box_i = 0
self.return_now = True
GL.NEXT_PAGE = 'PlayerSelectPage()'
if 'click' in self.help_button.handleEvent(event):
self.selection_box_i = 1
self.return_now = True
GL.NEXT_PAGE = 'help'
if 'click' in self.options_button.handleEvent(event):
self.selection_box_i = 2
self.return_now = True
GL.NEXT_PAGE = 'options'
if 'click' in self.exit_button.handleEvent(event):
self.selection_box_i = 3
EXIT_GAME()
if event.type == pygame.QUIT:
EXIT_GAME()
class HelpPage:
def __init__(self):
self.return_button = pygbutton.PygButton((0, 550, 300, 50), 'Main Menu')
self.section_font = pygame.font.Font('data/Kremlin.ttf', 40)
self.font = pygame.font.Font('data/arial_narrow_7.ttf', 20)
self.bg_image = pygame.image.load('data/Evil_Eyes.png')
self.bg_title = self.section_font.render('Background', True, WHITE)
self.bg_text = textwrap.wrap('Under the tyranny of the dark overlord, the world' +
'is in chaos and all the resources are nearly depleted. ' +
'Entire populations have been subjugated to life in labor ' +
'camps, brutally policed by the overlord\'s military forces. ' +
'As your people\'s champion, you must fight to the death in the ' +
'battle arena to win much needed resources.', width=50)
self.goals_title = self.section_font.render('Goals', True, WHITE)
self.goals_text = textwrap.wrap('Ultimately, you want to slay your opponent. ' +
'To become a better fighter, kill the monsters, gain ' +
'experience, and pick up skills. The player to land ' +
'the last hit on the monster will receives the experience ' +
'points. An ultimate boss will spawn every few ' +
'minutes. These bosses drop ultimate skills which ' +
'will help you humiliate and destroy your opponent.', width=50)
self.selection_box_properties = [(0, 550, 300, 50)]
self.selection_box_i = 0
def __call__(self):
self.return_now = False
while not self.return_now:
self.draw()
self.input()
self.events()
GL.CLOCK.tick(GL.FPS)
def draw(self):
GL.SCREEN.fill(BLACK)
GL.SCREEN.blit(self.bg_image, (0, 245))
GL.SCREEN.blit(self.bg_title, (800, 40))
for num, text in enumerate(self.bg_text):
line = self.font.render(text, True, DKRED)
GL.SCREEN.blit(line, (800, 90 + (num * 20)))
GL.SCREEN.blit(self.goals_title, (800, 250))
for num, text in enumerate(self.goals_text):
line = self.font.render(text, True, DKRED)
GL.SCREEN.blit(line, (800, 300 + (num * 20)))
self.return_button.draw(GL.SCREEN)
self.selection_box = Rect2(self.selection_box_properties[self.selection_box_i], color=BLUE)
pygame.draw.rect(GL.SCREEN, self.selection_box.color, self.selection_box, selection_box_width)
pygame.display.update()
def input(self):
GL.INPUT1.refresh()
if GL.INPUT1.START_PRESS_EVENT:
GL.INPUT1.START_PRESS_EVENT = False
self.return_now = True
GL.NEXT_PAGE = 'start'
if GL.INPUT1.SELECT_PRESS_EVENT:
GL.INPUT1.SELECT_PRESS_EVENT = False
self.return_now = True
GL.NEXT_PAGE = 'start'
if GL.INPUT1.B_PRESS_EVENT:
GL.INPUT1.B_PRESS_EVENT = False
self.return_now = True
GL.NEXT_PAGE = 'start'
if GL.INPUT1.A_PRESS_EVENT:
GL.INPUT1.A_PRESS_EVENT = False
self.return_now = True
GL.NEXT_PAGE = 'start'
#----------------------------------------------------------------------------------------
class PlayerSelectPage:
def __init__(self):
def _setup_display():
pygame.display.set_mode((1280, 600))
pygame.display.set_caption('Famished Tournament')
self.screen = pygame.display.get_surface()
self.return_button = pygbutton.PygButton((0, 550, 300, 50), 'Main Menu')
self.player1_spritesheet = None
self.player2_spritesheet = None
def _load_images():
self.humanPortrait = pygame.image.load('data/portrait_human.png')
self.elfPortrait = pygame.image.load('data/portrait_elf.png')
self.portraits = [self.humanPortrait, self.elfPortrait]
self.portraits2 = [self.humanPortrait, self.elfPortrait]
#show human portrait by default
self.index = 0
self.index2 = 0
def _setup_fonts():
self.start_font = pygame.font.Font('data/Kremlin.ttf', 50)
self.start_font_xy = font_position_center(GL.SCREEN.get_rect(), self.start_font, '---------------Press Start when ready---------------')
def _setup_flags():
self.ready1 = False
self.ready2 = False
self.start = False
#if there is a second gamepad, there is a second player
#set ready to false if second player exists
#if no second player, set ready to true
if not GL.INPUT2.get_gamepad():
self.ready2 = True
_setup_display()
_setup_fonts()
_setup_flags()
_load_images()
def __call__(self):
self.return_now = False
while not self.return_now:
self.draw()
self.input()
self.events()
GL.CLOCK.tick(GL.FPS)
def draw(self):
self.image = pygame.image.load('data/player_select_bkg.png')
GL.SCREEN.blit(self.image, (0,0))
self.return_button.draw(GL.SCREEN)
GL.SCREEN.blit(self.portraits[self.index], (167, 106))
GL.SCREEN.blit(self.portraits2[self.index2], (810, 106))
pygame.display.update()
def input(self):
def refresh_inputs():
GL.INPUT1.refresh()
GL.INPUT2.refresh()
if GL.INPUT1.SELECT_PRESS_EVENT:
GL.INPUT1.SELECT_PRESS_EVENT = False
GL.NEXT_PAGE = 'start'
if GL.INPUT2.SELECT_PRESS_EVENT:
GL.INPUT2.SELECT_PRESS_EVENT = False
GL.NEXT_PAGE = 'start'
def player_select_inputs():
def check_other_player(player):
if player == 'player1':
if self.index == self.index2 and self.ready2: #player 2 is using character, skip index
self.index = self.index + 1
if self.index >= len(self.portraits):
self.index = 0
else:
if self.index == self.index2 and self.ready1: #player 2 is using character, skip index
self.index2 = self.index2 + 1
if self.index2 >= len(self.portraits2):
self.index2 = 0
def check_left_right(player):
if player == 'player1':
if GL.INPUT1.LEFT_PRESS_EVENT:
GL.INPUT1.LEFT_PRESS_EVENT = False
self.index = self.index - 1
if self.index < 0:
self.index = len(self.portraits) - 1
check_other_player('player1')
elif GL.INPUT1.RIGHT_PRESS_EVENT:
GL.INPUT1.RIGHT_PRESS_EVENT = False
self.index = self.index + 1
if self.index >= len(self.portraits):
self.index = 0
check_other_player('player1')
elif player == 'player2':
if GL.INPUT2.LEFT_PRESS_EVENT:
GL.INPUT2.LEFT_PRESS_EVENT = False
self.index2 = self.index2 - 1
if self.index2 < 0:
self.index2 = len(self.portraits2)- 1
check_other_player('player2')
elif GL.INPUT2.RIGHT_PRESS_EVENT:
GL.INPUT2.RIGHT_PRESS_EVENT = False
self.index2 = self.index2 + 1
if self.index2 >= len(self.portraits2):
self.index2 = 0
check_other_player('player2')
#if player 1/2 is not ready, let them select character
if not self.ready1:
check_left_right('player1')
if not self.ready2:
check_left_right('player2')
def player_done_selecting():
#if player presses A
#they selected sprite
#set sprite to player
#if they pressed select
#they want to select a different sprite or return to start screen
if GL.INPUT1.A_PRESS_EVENT or GL.INPUT1.kb_input['K_SPACE']:
GL.INPUT1.A_PRESS_EVENT = False
GL.INPUT1.kb_input['K_SPACE'] = False #press space on keyboard to select
if self.ready2 and self.index2 == self.index:
print('Player 2 is using this character. Select a different one.')
else:
print('player 1 ready')
self.ready1 = True
elif GL.INPUT2.A_PRESS_EVENT:
GL.INPUT2.A_PRESS_EVENT = False
if self.ready1 and self.index2 == self.index:
print('Player 1 is using this character. Select a different one.')
else:
print('player 2 ready')
self.ready2 = True
#if player presses back when previously stated they were ready
#allow them to reselect player
#keyboard equivalent of select is 's' key
elif GL.INPUT1.SELECT_PRESS_EVENT or GL.INPUT1.kb_input['K_s']:
GL.INPUT1.SELECT_PRESS_EVENT = False
GL.INPUT1.kb_input['K_s'] = False
self.ready1 = False
elif GL.INPUT2.SELECT_PRESS_EVENT:
GL.INPUT2.SELECT_PRESS_EVENT = False
self.ready2 = False
#if player presses back when they were not ready
#go back to start screen
elif (GL.INPUT1.SELECT_PRESS_EVENT and not self.ready1 or GL.INPUT1.kb_input['K_s']):
GL.INPUT1.SELECT_PRESS_EVENT = False
GL.INPUT1.kb_input['K_s'] = False
GL.NEXT_PAGE = 'start'
elif (GL.INPUT2.SELECT_PRESS_EVENT and not self.ready2):
GL.INPUT2.SELECT_PRESS_EVENT = False
GL.NEXT_PAGE = 'start'
def ready_for_start():
if self.ready1 and self.ready2:
start_font = self.start_font.render('---------------Press Start when ready---------------', True, YELLOW)
GL.SCREEN.blit(start_font, self.start_font_xy)
pygame.display.update()
#if player 1 or player 2 presses start when both players are ready
#enter game loop
#if using a keyboard - only one player
#if keyboard user presses 'A' when he is ready
#enter game loop
if (GL.INPUT1.START_PRESS_EVENT or GL.INPUT2.START_PRESS_EVENT) or (GL.INPUT1.kb_input['K_a']):
if GL.INPUT1.START_PRESS_EVENT:
GL.INPUT1.START_PRESS_EVENT = False
if GL.INPUT2.START_PRESS_EVENT:
GL.INPUT2.START_PRESS_EVENT = False
if GL.INPUT1.kb_input['K_a']:
GL.INPUT1.kb_input['K_a'] = False
self.start = True
print('setting sprites')
set_sprites()
print('set sprites')
print('going to level select screen')
GL.NEXT_PAGE = 'LevelSelectPage()'
self.return_now = True
def set_sprites():
#set spritesheet for player1
if self.index == 0: #human
self.player1_spritesheet = 'data/p1_human.png'
#elif self.index == 1: #elf
else:
self.player1_spritesheet = 'data/p1_elf.png'
if self.index2 == 0: #human
self.player2_spritesheet = 'data/p1_human.png'
elif self.index2 == 1: #elf
self.player2_spritesheet = 'data/p2_human.png' #Elf spritesheet 2 if available
GL.set_player1_spritesheet(self.player1_spritesheet)
GL.set_player2_spritesheet(self.player2_spritesheet)
refresh_inputs()
player_select_inputs()
player_done_selecting()
ready_for_start()
def events(self):
for event in pygame.event.get():
if event.type == pygame.QUIT:
EXIT_GAME()
if 'click' in self.return_button.handleEvent(event):
self.return_now = True
GL.NEXT_PAGE = 'start'
#----------------------------------------------------------------------------------------
class LevelSelectPage:
def __init__(self):
def _setup_display():
pygame.display.set_mode((1280, 600))
pygame.display.set_caption('Famished Tournament')
self.screen = pygame.display.get_surface()
self.return_button = pygbutton.PygButton((0, 550, 300, 50), 'Main Menu')
self.ready = False
def _load_images():
self.humanLevel = pygame.image.load('data/humanLevel.png')
self.elfLevel = pygame.image.load('data/vinesLevel.png')
self.androidLevel = pygame.image.load('data/androidLevel.png')
self.levels = [self.humanLevel, self.elfLevel, self.androidLevel]
self.outerX = [19, 444, 874]
self.innerX = [24, 450, 878]
self.index = 0
_setup_display()
_load_images()
def __call__(self):
self.return_now = False
while not self.return_now:
self.input()
self.draw()
self.events()
GL.CLOCK.tick(GL.FPS)
def draw(self):
self.image = pygame.image.load('data/level_select_bkg.png')
GL.SCREEN.blit(self.image, (0,0))
outer_highlight = Rect2(topleft=(self.outerX[self.index], 184), size = (389, 173), color=(20, 118, 128))
inner_highlight = Rect2(topleft=(self.innerX[self.index], 190), size=(379, 162), color=(80, 191, 201))
pygame.draw.rect(GL.SCREEN, outer_highlight.color, outer_highlight)
pygame.draw.rect(GL.SCREEN, inner_highlight.color, inner_highlight)
self.image2 = pygame.image.load('data/level_select_bkg2.png')
GL.SCREEN.blit(self.image2, (0,0))
self.return_button.draw(GL.SCREEN)
pygame.display.update()
#only player 1 can select level
def input(self):
GL.INPUT1.refresh()
if GL.INPUT1.LEFT_PRESS_EVENT:
GL.INPUT1.LEFT_PRESS_EVENT = False
self.index = self.index - 1
if self.index < 0:
self.index = len(self.levels) - 1
elif GL.INPUT1.RIGHT_PRESS_EVENT:
GL.INPUT1.RIGHT_PRESS_EVENT = False
self.index = self.index + 1
if self.index >= len(self.levels):
self.index = 0
elif GL.INPUT1.SELECT_PRESS_EVENT or GL.INPUT1.kb_input['K_s']:
GL.INPUT1.SELECT_PRESS_EVENT = False
GL.INPUT1.kb_input['K_s'] = False
GL.NEXT_PAGE = 'PlayerSelectPage()'
self.return_now = True
def ready_check():
if GL.INPUT1.START_PRESS_EVENT or GL.INPUT1.kb_input['K_a']:
GL.INPUT1.START_PRESS_EVENT = False
GL.INPUT1.kb_input['K_a'] = False
print('ready to load')
self.ready = True
set_level()
GL.NEXT_PAGE = 'GameLoop()'
self.return_now = True
def set_level():
print ('setting level')
if self.index == 0:
arena = arena4
elif self.index == 1:
arena = arena3
elif self.index == 2:
arena = arena5
GL.set_level(arena)
print ('set level')
ready_check()
def events(self):
for event in pygame.event.get():
if event.type == pygame.QUIT:
EXIT_GAME()
if 'click' in self.return_button.handleEvent(event):
self.return_now = True
GL.NEXT_PAGE = 'start'
#----------------------------------------------------------------------------------------
class HelpPage:
def __init__(self):
self.return_button = pygbutton.PygButton((0, 550, 300, 50), 'Main Menu')
self.section_font = pygame.font.Font('data/Kremlin.ttf', 40)
self.font = pygame.font.Font('data/arial_narrow_7.ttf', 20)
self.bg_image = pygame.image.load('data/help.png')
self.bg_title = self.section_font.render('Background', True, WHITE)
self.bg_text = textwrap.wrap('Under the tyranny of the dark overlord, the world' +
'is in chaos and all the resources are nearly depleted. ' +
'Entire populations have been subjugated to life in labor ' +
'camps, brutally policed by the overlord\'s military forces. ' +
'As your people\'s champion, you must fight to the death in the ' +
'battle arena to win much needed resources.', width=50)
self.goals_title = self.section_font.render('Goals', True, WHITE)
self.goals_text = textwrap.wrap('Ultimately, you want to slay your opponent. ' +
'To become a better fighter, kill the monsters, gain ' +
'experience, and pick up skills. The player to land ' +
'the last hit on the monster will receives the experience ' +
'points. An ultimate boss will spawn every few ' +
'minutes. These bosses drop ultimate skills which ' +
'will help you humiliate and destroy your opponent.', width=50)
def __call__(self):
self.return_now = False
while not self.return_now:
self.draw()
self.input()
self.events()
GL.CLOCK.tick(GL.FPS)
def draw(self):
GL.SCREEN.fill(BLACK)
GL.SCREEN.blit(self.bg_image, (0, 0))
GL.SCREEN.blit(self.bg_title, (800, 40))
for num, text in enumerate(self.bg_text):
line = self.font.render(text, True, DKRED)
GL.SCREEN.blit(line, (800, 90 + (num * 20)))
GL.SCREEN.blit(self.goals_title, (800, 250))
for num, text in enumerate(self.goals_text):
line = self.font.render(text, True, DKRED)
GL.SCREEN.blit(line, (800, 300 + (num * 20)))
self.return_button.draw(GL.SCREEN)
pygame.display.update()
def input(self):
GL.INPUT1.refresh()
if GL.INPUT1.SELECT_PRESS_EVENT:
GL.INPUT1.SELECT_PRESS_EVENT = False
self.return_now = True
GL.NEXT_PAGE = 'start'
def events(self):
for event in pygame.event.get():
if event.type == pygame.QUIT:
EXIT_GAME()
if 'click' in self.return_button.handleEvent(event):
self.return_now = True
GL.NEXT_PAGE = 'start'
class OptionsPage:
def __init__(self):
self.bg_image = pygame.image.load('data/background2.png')
self.active_colors = BLACK, DKRED
self.inactive_colors = DKRED, BLACK
self.music_on_button = pygbutton.PygButton((650, 200, 60, 50), 'ON')
self.music_off_button = pygbutton.PygButton((730, 200, 80, 50), 'OFF')
self.effects_on_button = pygbutton.PygButton((650, 260, 60, 50), 'ON')
self.effects_off_button = pygbutton.PygButton((730, 260, 80, 50), 'OFF')
self.return_button = pygbutton.PygButton((0, 550, 300, 50), 'Main Menu')
font = pygame.font.Font('data/Kremlin.ttf', 40)
self.bg_font = font.render('Music:', True, DKRED)
self.se_font = font.render('Sound:', True, DKRED)
main_menu = (0, 550, 300, 50)
sound_on = (650, 260, 60, 50)
music_on = (650, 200, 60, 50)
music_off = (730, 200, 80, 50)
sound_off = (730, 260, 80, 50)
self.selection_box_row_properties = [[main_menu, sound_on, music_on], [main_menu, sound_off, music_off]]
row1_initial = 0 if AUDIO.sound_on else 1
row2_initial = 0 if AUDIO.music_on else 1
self.selection_box_col_indices = [0, row1_initial, row2_initial]
self.selection_box_row = 0
def __call__(self):
self.return_now = False
while not self.return_now:
self.draw()
self.input()
self.events()
GL.CLOCK.tick(GL.FPS)
def draw(self):
if AUDIO.music_on:
self.music_on_button.fgcolor, self.music_on_button.bgcolor = self.active_colors
self.music_off_button.fgcolor, self.music_off_button.bgcolor = self.inactive_colors
else:
self.music_on_button.fgcolor, self.music_on_button.bgcolor = self.inactive_colors
self.music_off_button.fgcolor, self.music_off_button.bgcolor = self.active_colors
if AUDIO.sound_on:
self.effects_on_button.fgcolor, self.effects_on_button.bgcolor = self.active_colors
self.effects_off_button.fgcolor, self.effects_off_button.bgcolor = self.inactive_colors
else:
self.effects_on_button.fgcolor, self.effects_on_button.bgcolor = self.inactive_colors
self.effects_off_button.fgcolor, self.effects_off_button.bgcolor = self.active_colors
GL.SCREEN.blit(self.bg_image, (0, 0))
GL.SCREEN.blit(self.bg_font, (450, 200))
GL.SCREEN.blit(self.se_font, (450, 260))
# GL.SCREEN.blit(self.bg_font, (500, 200))
# GL.SCREEN.blit(self.se_font, (400, 260))
self.music_on_button.draw(GL.SCREEN)
self.music_off_button.draw(GL.SCREEN)
self.effects_on_button.draw(GL.SCREEN)
self.effects_off_button.draw(GL.SCREEN)
self.return_button.draw(GL.SCREEN)
row = self.selection_box_row
col = self.selection_box_col_indices[row]
self.selection_box = Rect2(self.selection_box_row_properties[col][row], color=BLUE)
pygame.draw.rect(GL.SCREEN, self.selection_box.color, self.selection_box, selection_box_width)
pygame.display.update()
def input(self):
GL.INPUT1.refresh()
if GL.INPUT1.START_PRESS_EVENT:
GL.INPUT1.START_PRESS_EVENT = False
if self.selection_box_row == 0:
self.return_now = True
GL.NEXT_PAGE = 'start'
if GL.INPUT1.SELECT_PRESS_EVENT:
GL.INPUT1.SELECT_PRESS_EVENT = False
self.return_now = True
GL.NEXT_PAGE = 'start'
if GL.INPUT1.B_PRESS_EVENT:
GL.INPUT1.B_PRESS_EVENT = False
self.return_now = True
GL.NEXT_PAGE = 'start'
if GL.INPUT1.A_PRESS_EVENT:
GL.INPUT1.A_PRESS_EVENT = False
if self.selection_box_row == 0:
self.return_now = True
GL.NEXT_PAGE = 'start'
if GL.INPUT1.UP_PRESS_EVENT:
GL.INPUT1.UP_PRESS_EVENT = False
self.selection_box_row += 1
if self.selection_box_row > 2:
self.selection_box_row = 0
if GL.INPUT1.DOWN_PRESS_EVENT:
GL.INPUT1.DOWN_PRESS_EVENT = False
self.selection_box_row -= 1
if self.selection_box_row < 0:
self.selection_box_row = 2
if GL.INPUT1.LEFT_PRESS_EVENT or GL.INPUT1.RIGHT_PRESS_EVENT:
if GL.INPUT1.LEFT_PRESS_EVENT:
GL.INPUT1.LEFT_PRESS_EVENT = False
if GL.INPUT1.RIGHT_PRESS_EVENT:
GL.INPUT1.RIGHT_PRESS_EVENT = False
curr_col = self.selection_box_col_indices[self.selection_box_row]
new_col = 1 if curr_col == 0 else 0
self.selection_box_col_indices[self.selection_box_row] = new_col
if self.selection_box_row == 1:
if new_col == 0:
AUDIO.turn_on_effects()
elif new_col == 1:
AUDIO.turn_off_effects()
elif self.selection_box_row == 2:
if new_col == 0:
AUDIO.turn_on_music()
elif new_col == 1:
AUDIO.turn_off_music()
def events(self):
for event in pygame.event.get():
if event.type == pygame.QUIT:
EXIT_GAME()
if 'click' in self.music_on_button.handleEvent(event):
self.selection_box_row = 2
self.selection_box_col_indices[self.selection_box_row] = 0
AUDIO.turn_on_music()
if 'click' in self.music_off_button.handleEvent(event):
self.selection_box_row = 2
self.selection_box_col_indices[self.selection_box_row] = 1
AUDIO.turn_off_music()
if 'click' in self.effects_on_button.handleEvent(event):
self.selection_box_row = 1
self.selection_box_col_indices[self.selection_box_row] = 0
AUDIO.turn_on_effects()
if 'click' in self.effects_off_button.handleEvent(event):
self.selection_box_row = 1
self.selection_box_col_indices[self.selection_box_row] = 1
AUDIO.turn_off_effects()
if 'click' in self.return_button.handleEvent(event):
self.selection_box_row = 0
self.return_now = True
GL.NEXT_PAGE = 'start'
class PauseMenu:
def __init__(self):
self.menu_box = Rect2(topleft=(320, 120), size=(640, 240), color=BLACK)
main_font = 'data/Kremlin.ttf'
pause_font = pygame.font.Font(main_font, 100)
self.pause_font_xy = font_position_center(self.menu_box, pause_font, '-PAUSE-')
self.pause_font_rendered = pause_font.render('-PAUSE-', True, RED)
self.continue_button_properties = (395, 270, 200, 50)
self.quit_button_properties = (730, 270, 100, 50)
self.continue_button = pygbutton.PygButton(self.continue_button_properties, 'Continue')
self.quit_button = pygbutton.PygButton(self.quit_button_properties, 'Quit')
self.selection_box_properties = [self.continue_button_properties, self.quit_button_properties]
self.selection_box_i = 0
def __call__(self):
self.return_now = False
while not self.return_now:
self.draw()
self.input()
self.events()
GL.CLOCK.tick(GL.FPS)
def draw(self):
pygame.draw.rect(GL.SCREEN, WHITE, self.menu_box)
pygame.draw.rect(GL.SCREEN, self.menu_box.color, self.menu_box, 4)
GL.SCREEN.blit(self.pause_font_rendered, (self.pause_font_xy[0], self.menu_box.top))
self.continue_button.draw(GL.SCREEN)
self.quit_button.draw(GL.SCREEN)
self.selection_box = Rect2(self.selection_box_properties[self.selection_box_i], color=BLUE)
pygame.draw.rect(GL.SCREEN, self.selection_box.color, self.selection_box, selection_box_width)
pygame.display.update()
def input(self):
GL.INPUT1.refresh_during_pause()
# if GL.INPUT1.START_PRESS_EVENT:
# GL.INPUT1.START_PRESS_EVENT = False
# self.return_now = True
# GL.NEXT_PAGE = 'GL.CURR_GAME'
if GL.INPUT1.SELECT_PRESS_EVENT:
GL.INPUT1.SELECT_PRESS_EVENT = False
self.return_now = True
GL.NEXT_PAGE = 'GL.CURR_GAME'
if GL.INPUT1.START_PRESS_EVENT or GL.INPUT1.A_PRESS_EVENT:
if GL.INPUT1.START_PRESS_EVENT:
GL.INPUT1.START_PRESS_EVENT = False
if GL.INPUT1.A_PRESS_EVENT:
GL.INPUT1.A_PRESS_EVENT = False
if self.selection_box_i == 0:
self.return_now = True
GL.NEXT_PAGE = 'GL.CURR_GAME'
if self.selection_box_i == 1:
self.return_now = True
GL.NEXT_PAGE = 'start'
if GL.INPUT1.RIGHT_PRESS_EVENT:
GL.INPUT1.RIGHT_PRESS_EVENT = False
self.selection_box_i += 1
if self.selection_box_i > 1:
self.selection_box_i = 0
if GL.INPUT1.LEFT_PRESS_EVENT:
GL.INPUT1.LEFT_PRESS_EVENT = False
self.selection_box_i -= 1
if self.selection_box_i < 0:
self.selection_box_i = 1
def events(self):
for event in pygame.event.get():
if event.type == pygame.QUIT:
EXIT_GAME()
if 'click' in self.continue_button.handleEvent(event):
self.return_now = True
GL.NEXT_PAGE = 'GL.CURR_GAME'
if 'click' in self.quit_button.handleEvent(event):
self.return_now = True
GL.NEXT_PAGE = 'start'