-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathOldGallivanter
1232 lines (914 loc) · 43.2 KB
/
OldGallivanter
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
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import pygame, sys
from pygame.constants import K_ESCAPE, RESIZABLE
from Enemies import *
from Character import *
pygame.init()
timer = pygame.time.Clock()
screen = pygame.display.set_mode((800, 600), RESIZABLE)
pygame.display.set_caption("Gallivanter")
fontOne = pygame.font.Font("freesansbold.ttf", 60)
fontTwo = pygame.font.Font("freesansbold.ttf", 30)
right = False
left = False
steps = 0
#Animated pictures
moveRight = [pygame.image.load('C:/Users/Lam/Documents/Gallivanter/R1.png'), pygame.image.load('C:/Users/Lam/Documents/Gallivanter/R2.PNG'), pygame.image.load('C:/Users/Lam/Documents/Gallivanter/R3.PNG'), pygame.image.load('C:/Users/Lam/Documents/Gallivanter/R4.PNG'), pygame.image.load('C:/Users/Lam/Documents/Gallivanter/R5.PNG'), pygame.image.load('C:/Users/Lam/Documents/Gallivanter/R6.PNG'), pygame.image.load('C:/Users/Lam/Documents/Gallivanter/R7.PNG'), pygame.image.load('C:/Users/Lam/Documents/Gallivanter/R8.PNG'), pygame.image.load('C:/Users/Lam/Documents/Gallivanter/R9.PNG')]
standing = pygame.image.load('C:/Users/Lam/Documents/Gallivanter/R10.PNG')
transparent = (0,0,0,0)
enemy_health = 100
user_health = 100
#hit sound effect
hit_sound = pygame.mixer.Sound('C:/Users/Lam/Documents/Gallivanter/Hit.wav')
#music
music = pygame.mixer.music.load('C:/Users/Lam/Documents/Gallivanter/Music.mp3')
#play the music on loop
pygame.mixer.music.play(-1)
#making the music quieter.
pygame.mixer.music.set_volume(0.7)
#to draw text
def draw_text(text, font, colour, surface, x, y):
textobject = font.render(text, 1, colour)
textrect = textobject.get_rect()
textrect.topleft = (x,y)
surface.blit(textobject, textrect)
#main display screen
def main_menu():
click = False
while True:
background = pygame.image.load('C:/Users/Lam/Documents/Gallivanter/Title ground.png').convert()
background = pygame.transform.scale(background, (800,600))
screen.blit(background,(0,0))
title = pygame.image.load('C:/Users/Lam/Documents/Gallivanter/Gallivanter Title.png')
screen.blit(title,(65,50))
logo = pygame.image.load('C:/Users/Lam/Documents/Gallivanter/Logo.png')
screen.blit(logo, (335,160))
mx, my = pygame.mouse.get_pos()
#main menu buttons
button_game = pygame.image.load('C:/Users/Lam/Documents/Gallivanter/Start.png')
button_settings = pygame.image.load('C:/Users/Lam/Documents/Gallivanter/Settings.png')
button_exit = pygame.image.load('C:/Users/Lam/Documents/Gallivanter/Exit.png')
screen.blit(button_game,(275,285))
screen.blit(button_settings,(275,385))
screen.blit(button_exit,(275,485))
#interactive buttons
button_gameHover = pygame.image.load('C:/Users/Lam/Documents/Gallivanter/StartHover.png')
button_settingHover = pygame.image.load('C:/Users/Lam/Documents/Gallivanter/SettingsHover.png')
button_exitHover = pygame.image.load('C:/Users/Lam/Documents/Gallivanter/ExitHover.png')
#lights up when hovered and starts game
if button_game.get_rect(center=(400,330)).collidepoint((mx, my)):
screen.blit(button_gameHover,(275,285))
if click:
game()
#lights up when hovered and brings to the settings menu
if button_settings.get_rect(center=(400,430)).collidepoint((mx, my)):
screen.blit(button_settingHover,(275,385))
if click:
settingsMain()
#to exit game
if button_exit.get_rect(center=(400,530)).collidepoint((mx, my)):
screen.blit(button_exitHover,(275,485))
if click:
pygame.quit()
sys.exit()
#
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
sys.exit()
if event.type == pygame.KEYDOWN:
if event.key == K_ESCAPE:
pygame.quit()
sys.exit()
#
if event.type == pygame.MOUSEBUTTONDOWN:
if event.button == 1:
click = True
else:
click = False
pygame.display.update()
timer.tick(60)
def game():
running = True
while running:
run()
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
sys.exit()
if event.type == pygame.KEYDOWN:
if event.key == K_ESCAPE:
running = False
pygame.display.update()
timer.tick(60)
def settingsMain():
running = True
click = False
while running:
mx, my = pygame.mouse.get_pos()
settings_menu = pygame.image.load('C:/Users/Lam/Documents/Gallivanter/SettingsMenu.png')
settings_menu = pygame.transform.scale(settings_menu, (700,500))
screen.blit(settings_menu, (60,95))
button_sound = pygame.image.load('C:/Users/Lam/Documents/Gallivanter/Sound.png')
button_video = pygame.image.load('C:/Users/Lam/Documents/Gallivanter/Video.png')
button_back = pygame.image.load('C:/Users/Lam/Documents/Gallivanter/Back.png')
screen.blit(button_sound,(120,295))
screen.blit(button_video,(440,295))
screen.blit(button_back,(280,430))
button_soundHover = pygame.image.load('C:/Users/Lam/Documents/Gallivanter/SoundHover.png')
button_videoHover = pygame.image.load('C:/Users/Lam/Documents/Gallivanter/VideoHover.png')
button_backHover = pygame.image.load('C:/Users/Lam/Documents/Gallivanter/BackHover.png')
#lights up when hovered and brings to the sound menu
if button_sound.get_rect(center=(225,328)).collidepoint((mx, my)):
screen.blit(button_soundHover,(120,295))
if click:
sound()
#lights up when hovered and brings to the video menu
if button_video.get_rect(center=(565,336)).collidepoint((mx, my)):
screen.blit(button_videoHover,(440,295))
if click:
video()
#to exit game
if button_back.get_rect(center=(405,473)).collidepoint((mx, my)):
screen.blit(button_backHover,(280,430))
if click:
running = False
#to go back
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
sys.exit()
if event.type == pygame.KEYDOWN:
if event.key == K_ESCAPE:
running = False
if event.type == pygame.MOUSEBUTTONDOWN:
if event.button == 1:
click = True
else:
click = False
pygame.display.update()
timer.tick(60)
def settingsPause():
running = True
click = False
while running:
mx, my = pygame.mouse.get_pos()
settings_menu = pygame.image.load('C:/Users/Lam/Documents/Gallivanter/SettingsMenu.png')
settings_menu = pygame.transform.scale(settings_menu, (700,500))
screen.blit(settings_menu, (60,95))
button_sound = pygame.image.load('C:/Users/Lam/Documents/Gallivanter/Sound.png')
button_video = pygame.image.load('C:/Users/Lam/Documents/Gallivanter/Video.png')
button_back = pygame.image.load('C:/Users/Lam/Documents/Gallivanter/Back.png')
screen.blit(button_sound,(120,295))
screen.blit(button_video,(440,295))
screen.blit(button_back,(280,430))
button_soundHover = pygame.image.load('C:/Users/Lam/Documents/Gallivanter/SoundHover.png')
button_videoHover = pygame.image.load('C:/Users/Lam/Documents/Gallivanter/VideoHover.png')
button_backHover = pygame.image.load('C:/Users/Lam/Documents/Gallivanter/BackHover.png')
#lights up when hovered and brings to the sound menu
if button_sound.get_rect(center=(225,328)).collidepoint((mx, my)):
screen.blit(button_soundHover,(120,295))
if click:
sound()
#lights up when hovered and brings to the video menu
if button_video.get_rect(center=(565,336)).collidepoint((mx, my)):
screen.blit(button_videoHover,(440,295))
if click:
video()
#to exit game
if button_back.get_rect(center=(405,473)).collidepoint((mx, my)):
screen.blit(button_backHover,(280,430))
if click:
running = False
#to go back
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
sys.exit()
if event.type == pygame.KEYDOWN:
if event.key == K_ESCAPE:
running = False
if event.type == pygame.MOUSEBUTTONDOWN:
if event.button == 1:
click = True
else:
click = False
pygame.display.update()
timer.tick(60)
def sound():
running = True
click = False
while running:
mx, my = pygame.mouse.get_pos()
sound_menu = pygame.image.load('C:/Users/Lam/Documents/Gallivanter/SoundMenu.png')
sound_menu = pygame.transform.scale(sound_menu, (700,500))
screen.blit(sound_menu, (60,95))
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
sys.exit()
if event.type == pygame.KEYDOWN:
if event.key == K_ESCAPE:
running = False
if event.type == pygame.MOUSEBUTTONDOWN:
if event.button == 1:
click = True
else:
click = False
pygame.display.update()
timer.tick(60)
def video():
running = True
click = False
while running:
mx, my = pygame.mouse.get_pos()
video_menu = pygame.image.load('C:/Users/Lam/Documents/Gallivanter/VideoMenu.png')
video_menu = pygame.transform.scale(video_menu, (700,500))
screen.blit(video_menu, (60,95))
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
sys.exit()
if event.type == pygame.KEYDOWN:
if event.key == K_ESCAPE:
running = False
if event.type == pygame.MOUSEBUTTONDOWN:
if event.button == 1:
click = True
else:
click = False
pygame.display.update()
timer.tick(60)
def run():
global steps
global screen
global enemy_health
global user_health
bool = True
x = 350
y = 400
f = 0
i = 1
round = False
while bool:
for event in pygame.event.get():
if event.type == pygame.QUIT:
bool = False
pygame.time.delay(60)
timer.tick(27)
background = pygame.image.load('C:/Users/Lam/Documents/Gallivanter/picture.PNG').convert()
#display the background onto the screen
screen.blit(background, (f,0))
#settings
settings_icon = pygame.image.load('C:/Users/Lam/Documents/Gallivanter/SettingsIcon.png')
settings_sized = pygame.transform.scale(settings_icon, (75,75))
#display settings onto the screen
screen.blit(settings_sized, (740, 15))
#get the position of the mouse
mouse_pos = pygame.mouse.get_pos()
#if the mouse clicks on the settings icon
if 740 < mouse_pos[0] < 790 and 15 < mouse_pos[1] < 65:
if event.type == pygame.MOUSEBUTTONDOWN:
settingsPause()
if round == False:
x,y,f,round, left, right = movement(x, y, f,round, False, False)
else:
#round 1
if i == 1:
round = round_1(x,y, round)
#round 2
if i == 2:
round = round_2(x,y, round)
#round 3
#round 4
if round == False:
f = 0
#i increases after each round ends
i +=1
#if steps is more than 27, then the array will reset
if steps >= 27:
steps = 0
#drawing the character
character_sized = pygame.transform.scale(moveRight[steps//3], (125,125))
standing_sized = pygame.transform.scale(standing, (125,125))
if right:
screen.blit(character_sized, (x,y))
#counting the steps to tell the code when the array will reset (so that it doesn't run out of photos)
steps = steps + 1
elif left:
#flip the image to make it seem like the user is moving left
screen.blit(pygame.transform.flip(character_sized, True, False), (x,y))
steps = steps + 1
#if the character is not moving then its standing picture will be shown on the screen
else:
screen.blit(standing_sized, (x,y))
pygame.display.update()
def movement(x,y,f, round, left, right):
#setting the background image
if f <= -606:
f = 0
#controls of the character and the background
keys = pygame.key.get_pressed()
if keys[pygame.K_a]:
left = True
right = False
if f >= 0:
x = x-10
if x <=0:
x = 0
else:
f = f+10
elif keys[pygame.K_d]:
right = True
left = False
if x < 350:
x = x + 10
else:
f = f-10
else:
left = False
right = False
steps = 0
#if the enemy appears
if(f <=-250):
round = True
right = False
left = False
#transition slide
screen.fill((0,0,0))
#center the characters
x = 220
return x, y, f, round, left, right
def round_1(x,y, round):
global enemy_sized
#enemy
enemy = pygame.image.load('C:/Users/Lam/Documents/Gallivanter/enemy.png')
enemy_sized = pygame.transform.scale(enemy, (125, 130))
screen.blit(enemy_sized, (x + 220, y))
#text box
text_box1 = pygame.image.load('C:/Users/Lam/Documents/Gallivanter/Textbox.png')
text_box1 = pygame.transform.scale(text_box1,(500,170))
screen.blit(text_box1,(170,200))
text1 = draw_text("Prepare to meet your doom!", fontTwo, (0,0,0), screen, 210,230)
incorrect = 0
variable = 1
global correct_variable
global incorrect_variable
correct_variable = 0
incorrect_variable = 0
global enemy_1
global user
user_damage = 20
enemy_damage = 50
enemy_1 = Enemies(enemy_health, enemy_damage)
user = Character(user_health, user_damage)
global user_dead
global enemy_dead
user_dead = False
enemy_dead = False
close = False
keys = pygame.key.get_pressed()
if keys[pygame.K_SPACE]:
run = True
while run:
mouse_pos = pygame.mouse.get_pos()
for event in pygame.event.get():
if event.type == pygame.QUIT:
run = False
#settings
settings_icon = pygame.image.load('C:/Users/Lam/Documents/Gallivanter/SettingsIcon.png')
settings_sized = pygame.transform.scale(settings_icon, (75,75))
#display settings onto the screen
screen.blit(settings_sized, (740, 15))
close, user_dead, enemy_dead = questions_screen('What is the mean of this set of numbers? 16, 7, 24, 2, 11.', '', 'The answer is: 12.', incorrect,'12',
user_damage, enemy_damage, close, 'Add them all together then divide by how many numbers there are.', user_dead, enemy_dead, True, False, False, False)
if close == True:
variable = variable + 1
run = False
#screen that shows that the health of the characters go down
close, user_dead, enemy_dead = questions_screen('In which quadrant of a Cartesian plane do you find the point (-4,-3)?', '', 'The answer is: Third quadrant.', incorrect,'Third quadrant',
user_damage, enemy_damage, close, 'Remember, both of the numbers are negative.', user_dead, enemy_dead, True, False, False, False)
#text box
text_box2 = pygame.image.load('C:/Users/Lam/Documents/Gallivanter/Textbox.png')
text_box2 = pygame.transform.scale(text_box1,(500,170))
screen.blit(text_box2,(170,200))
text2 = draw_text("You won!", fontTwo, (0,0,0), screen, 210,230)
#end the round if the enemy dies
if enemy_dead == True:
round = False
return round
if close == True:
variable = variable + 1
run = False
#screen that shows that the health of the characters go down
close, user_dead, enemy_dead = questions_screen('What is 0.45 as a percentage?', '', '45%', incorrect,'45%',
user_damage, enemy_damage, close, 'To convert decimal to a percentage, multiply by 100', user_dead, enemy_dead, True, False, False, False)
if enemy_dead == True:
round = False
return round
if close == True:
variable = variable + 1
run = False
#screen that shows that the health of the characters go down
close, user_dead, enemy_dead = questions_screen('What is 80000 / 1000?', '', 'The answer is: 80.', incorrect,'80', user_damage, enemy_damage, close, 'Try using long division. You can also cancel out the zeros to get the answer.', user_dead, enemy_dead, True, False, False, False)
if enemy_dead == True:
round = False
return round
if close == True:
variable = variable + 1
run = False
#screen that shows that the health of the characters go down
close, user_dead, enemy_dead = questions_screen('What is 2:40 am in 24 hour time?', '', 'The answer is: 2:40.', incorrect,'2:40',
user_damage, enemy_damage, close, 'If it before 12 pm, remove the am/pm, if it is after 12 pm, add 12 to the time and remove the am/pm.', user_dead, enemy_dead, True, False, False, False)
if enemy_dead == True:
round = False
return round
if user_dead == True:
#add something here to restart the game or round if the user dies + a message
#death message
text_box3 = pygame.image.load('C:/Users/Lam/Documents/Gallivanter/Textbox.png')
text_box3 = pygame.transform.scale(text_box1,(500,170))
screen.blit(text_box3,(170,200))
text3 = draw_text("You're no match for me!", fontTwo, (0,0,0), screen, 210,230)
round = False
return round
pygame.display.flip()
def round_2(x,y, round):
global enemy_sized
#enemy
enemy = pygame.image.load('C:/Users/Lam/Documents/Gallivanter/Enemy2.png')
enemy_sized = pygame.transform.scale(enemy, (125, 130))
screen.blit(enemy_sized, (x + 220, y))
#text box
text_box1 = pygame.image.load('C:/Users/Lam/Documents/Gallivanter/Textbox.png')
text_box1 = pygame.transform.scale(text_box1,(500,170))
screen.blit(text_box1,(170,200))
text1 = draw_text("You shouldn't be here.", fontTwo, (0,0,0), screen, 210,230)
incorrect = 0
variable = 1
global correct_variable
global incorrect_variable
correct_variable = 0
incorrect_variable = 0
global enemy_1
global user
user_damage = 30
enemy_damage = 35
enemy_1 = Enemies(enemy_health, enemy_damage)
user = Character(user_health, user_damage)
global user_dead
global enemy_dead
user_dead = False
enemy_dead = False
close = False
keys = pygame.key.get_pressed()
if keys[pygame.K_SPACE]:
run = True
while run:
print(enemy_dead)
mouse_pos = pygame.mouse.get_pos()
for event in pygame.event.get():
if event.type == pygame.QUIT:
run = False
#settings
settings_icon = pygame.image.load('C:/Users/Lam/Documents/Gallivanter/SettingsIcon.png')
settings_sized = pygame.transform.scale(settings_icon, (75,75))
#display settings onto the screen
screen.blit(settings_sized, (740, 15))
close, user_dead, enemy_dead = questions_screen('What is 1 x 1?', '', 'The answer is: 1.', incorrect,'1', user_damage, enemy_damage, close, 'Use addition to add the two numbers together.', user_dead, enemy_dead, False, True, False, False)
if close == True:
variable = variable + 1
run = False
#screen that shows that the health of the characters go down
close, user_dead, enemy_dead = questions_screen('What is 2 x 2?', '', 'The answer is: 4.', incorrect,'4', user_damage, enemy_damage, close, 'Use addition to add the two numbers together.', user_dead, enemy_dead, False, True, False, False)
#text box
text_box2 = pygame.image.load('C:/Users/Lam/Documents/Gallivanter/Textbox.png')
text_box2 = pygame.transform.scale(text_box1,(500,170))
screen.blit(text_box2,(170,200))
text2 = draw_text("You won!", fontTwo, (0,0,0), screen, 210,230)
#end the round if the enemy dies
if enemy_dead == True:
round = False
return round
if close == True:
variable = variable + 1
run = False
#screen that shows that the health of the characters go down
close, user_dead, enemy_dead = questions_screen('What is 4 x 4?', '', 'The answer is: 16.', incorrect,'16', user_damage, enemy_damage, close, 'Use addition to add the two numbers together.', user_dead, enemy_dead, False, True, False, False)
if enemy_dead == True:
round = False
return round
if close == True:
variable = variable + 1
run = False
#screen that shows that the health of the characters go down
close, user_dead, enemy_dead = questions_screen('What is 8 x 8?', '', 'The answer is: 64.', incorrect,'64', user_damage, enemy_damage, close, 'Use addition to add the two numbers together.', user_dead, enemy_dead, False, True, False, False)
if enemy_dead == True:
round = False
return round
if close == True:
variable = variable + 1
run = False
#screen that shows that the health of the characters go down
close, user_dead, enemy_dead = questions_screen('What is 9 + 9?', '', 'The answer is: 18.', incorrect,'18', user_damage, enemy_damage, close, 'Use addition to add the two numbers together.', user_dead, enemy_dead, False, True, False, False)
if enemy_dead == True:
round = False
return round
if user_dead == True:
#add something here to restart the game or round if the user dies + a message
#text box
text_box3 = pygame.image.load('C:/Users/Lam/Documents/Gallivanter/Textbox.png')
text_box3 = pygame.transform.scale(text_box1,(500,170))
screen.blit(text_box1,(170,200))
text3 = draw_text("You made the wrong choice.", fontTwo, (0,0,0), screen, 210,230)
round = False
return round
pygame.display.flip()
def questions_screen(text, input, solution, incorrect, quest_answer,user_damage, enemy_damage, close, hint, user_dead, enemy_dead, round1, round2, round3, round4):
#health values for the characters
health = 100
#input text setup
answer = pygame.Rect(100,200, 175,30)
answer_status = False
input_text = ''
keys = pygame.key.get_pressed()
space = False
questions = True
while questions:
mouse_pos = pygame.mouse.get_pos()
for event in pygame.event.get():
if event.type == pygame.QUIT:
questions = False
if event.type == pygame.MOUSEBUTTONDOWN:
if answer.collidepoint(event.pos):
answer_status = True
else:
answer_status = False
if event.type == pygame.KEYDOWN:
if answer_status == True:
if event.key == pygame.K_BACKSPACE:
input_text = input_text[:-1]
else:
input_text = input_text + event.unicode
#creating a new screen to display the math questions
questions = pygame.display.set_mode((800,600))
questions.fill((255,255,255))
#settings icon
settings_icon = pygame.image.load('C:/Users/Lam/Documents/Gallivanter/SettingsIcon.png')
settings_sized = pygame.transform.scale(settings_icon, (75,75))
#display settings onto the screen
screen.blit(settings_sized, (740, 15))
#question text
font = pygame.font.Font('freesansbold.ttf', 20)
question_text = font.render(text, True, (0,0,0))
#textbox to hold questions
textbox = question_text.get_rect()
textbox.center = (400,100)
#user input
questions.fill((0,0,0), answer)
answer_text = font.render(input_text, True, (255,255,255))
#submit button for question 1
if 300 < mouse_pos[0] < 375 and 200 < mouse_pos[1] < 230:
pygame.draw.rect(questions, (216,191,216), (300,200,75,30))
if event.type == pygame.MOUSEBUTTONDOWN:
if input_text != '':
if input_text == quest_answer:
#calls the outcome function
run = outcome('Correct!', False)
#calls the spell function by giving it booleans according to which round it is
test_bool = spell(round1, round2, round3, round4, True)
if test_bool == False:
space, user_dead, enemy_dead = spell_ball(True, health, user_damage, enemy_damage, space, user_dead, enemy_dead)
if space == True:
close = True
#return the booleans that indicate whether the characters are dead or not
return close, user_dead, enemy_dead
break
else:
run = outcome("Incorrect, try again.", True)
incorrect += 1
else:
draw_text("Try entering something", fontTwo, (0,0,0), screen, 100,500)
else:
pygame.draw.rect(questions, (153,50,204), (300,200,75,30))
#font settings for the hint button
hint_font = pygame.font.Font('freesansbold.ttf', 20)
hint_text = hint_font.render('Hint', True, (0,0,0))
hint_rect = hint_text.get_rect()
hint_rect.center = (695, 535)
#drawing the hint button
if incorrect >= 2:
if 620 < mouse_pos[0] < 770 and 500 < mouse_pos[1] < 570:
pygame.draw.rect(questions, (255,255,153), (620,500,150,70))
if event.type == pygame.MOUSEBUTTONDOWN:
hint_window(hint)
else:
pygame.draw.rect(questions, (255,255,0), (620,500,150,70))
#displaying the 'hint' text
questions.blit(hint_text, hint_rect)
#solution box
if incorrect >= 3:
#font settings for the solution
solution_font = pygame.font.Font('freesansbold.ttf', 20)
solution_text = solution_font.render(solution, True, (0,0,0))
solution_rect = solution_text.get_rect()
solution_rect = (100,350)
questions.blit(solution_text, solution_rect)
#making the submit button disappear (not completely done --> the user is still able to press it)
pygame.draw.rect(questions, (255,255,255), (300,200,75,30))
#font settings for the 'Ok.' button
ok_font = pygame.font.Font('freesansbold.ttf', 20)
ok_text = ok_font.render(' Ok. ', True, (0,0,0))
ok_rect = ok_text.get_rect()
ok_rect = (270,460)
questions.blit(ok_text, ok_rect)
#if the button OK. is pressed, then the enemy will attack the user
if 270 < mouse_pos[0] < 300 and 460 < mouse_pos[1] < 490:
if event.type == pygame.MOUSEBUTTONDOWN:
space, user_dead, enemy_dead = spell_ball(False, health, user_damage, enemy_damage, space, user_dead, enemy_dead)
if space == True:
close = True
return close, user_dead, enemy_dead
break
#font settings for the submit button
button_font = pygame.font.Font('freesansbold.ttf', 20)
button_text = button_font.render('Submit', True, (255,255,255))
button_rect = button_text.get_rect()
button_rect.center = (337, 215)
#adding the elements to the 'questions' screen
questions.blit(question_text, textbox)
questions.blit(answer_text, (answer.x, answer.y))
questions.blit(button_text, button_rect)
pygame.display.update()
pygame.display.flip()
#hint window
def hint_window(hint):
pressed = True
while pressed:
mouse_pos = pygame.mouse.get_pos()
for event in pygame.event.get():
if event.type == pygame.QUIT:
pop = False
hint_w = pygame.display.set_mode((800,600))
hint_w.fill((255,255,255))
#settings
settings_icon = pygame.image.load('C:/Users/Lam/Documents/Gallivanter/SettingsIcon.png')
settings_sized = pygame.transform.scale(settings_icon, (75,75))
#display settings onto the screen
screen.blit(settings_sized, (740, 15))
#font settings for the hint
hintText_font = pygame.font.Font('freesansbold.ttf', 30)
hintText_text = hintText_font.render(hint, True, (0,0,0))
hintText_rect = hintText_text.get_rect()
hintText_rect.center = (400,300)
if 350 < mouse_pos[0] < 450 and 400 < mouse_pos[1] < 440:
pygame.draw.rect(hint_w, (216,191,216), (350,400,100,40))
if event.type == pygame.MOUSEBUTTONDOWN:
pressed = False
else:
pygame.draw.rect(hint_w, (153,50,204), (350,400,100,40))
button_font = pygame.font.Font('freesansbold.ttf', 30)
button_text = button_font.render('Okay', True, (255,255,255))
button_rect = button_text.get_rect()
button_rect.center = (400, 420)
hint_w.blit(button_text, button_rect)
hint_w.blit(hintText_text, hintText_rect)
pygame.display.flip()
#'b' boolean is returned and reassigned as 'run' to determine whether or not round 1 will continue
def outcome(popup_text, b):
pop = True
while pop:
mouse_pos = pygame.mouse.get_pos()
for event in pygame.event.get():
if event.type == pygame.QUIT:
pop = False
window = pygame.display.set_mode((800,600))
window.fill((255,255,255))
#settings
settings_icon = pygame.image.load('C:/Users/Lam/Documents/Gallivanter/SettingsIcon.png')
settings_sized = pygame.transform.scale(settings_icon, (75,75))
#display settings onto the screen
screen.blit(settings_sized, (740, 15))
font = pygame.font.Font('freesansbold.ttf', 80)
display_text = font.render(popup_text, True, (0,0,0))
#textbox to hold questions
textbox = display_text.get_rect()
textbox.center = (400,300)
#take the position of the mouse and check if it matches the position of the rectangle.
#If the position matches, then the colour of the rectangle will change.
if 350 < mouse_pos[0] < 450 and 400 < mouse_pos[1] < 440:
pygame.draw.rect(window, (216,191,216), (350,400,100,40))
if event.type == pygame.MOUSEBUTTONDOWN:
pop = False
return b;
else:
pygame.draw.rect(window, (153,50,204), (350,400,100,40))
button_font = pygame.font.Font('freesansbold.ttf', 30)
button_text = button_font.render('Okay', True, (255,255,255))
button_rect = button_text.get_rect()
button_rect.center = (400, 420)
window.blit(display_text, textbox)
window.blit(button_text, button_rect)
pygame.display.flip()
def spell(round1, round2, round3, round4, test1):
spell = True
while spell:
mouse_pos = pygame.mouse.get_pos()
for event in pygame.event.get():
if event.type == pygame.QUIT:
spell = False
spell_window = pygame.display.set_mode((800,600))
spell_window.fill((255,255,255))
#settings
settings_icon = pygame.image.load('C:/Users/Lam/Documents/Gallivanter/SettingsIcon.png')
settings_sized = pygame.transform.scale(settings_icon, (75,75))
#display settings onto the screen
screen.blit(settings_sized, (740, 15))
#title font settings
title_font = pygame.font.Font('freesansbold.ttf', 40)
title_text = title_font.render('Choose an attack!', True, (0,0,0))
title_rect = title_text.get_rect()
title_rect.center = (230,100)
#displaying the title
spell_window.blit(title_text, title_rect)
if round1:
#get the mouse position and see if it matches the button
if 250 < mouse_pos[0] < 370 and 200 < mouse_pos[1] < 320:
pygame.draw.rect(spell_window, (216,191,216), (250,200,120,120))
if event.type == pygame.MOUSEBUTTONDOWN:
test1 = False
return test1
break
else:
pygame.draw.rect(spell_window, (153,50,204), (250,200,120,120))
#font for the button attack text
button_font = pygame.font.Font('freesansbold.ttf', 22)
button_text = button_font.render('Icy blast', True, (255,255,255))