-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGallivanter.py
1637 lines (1210 loc) · 62.9 KB
/
Gallivanter.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
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
'''
Created on Mar. 4, 2020
@author: rkwan
'''
import pygame
import os
from Enemies import *
from Character import *
pygame.init()
timer = pygame.time.Clock()
screen = pygame.display.set_mode((800,600))
pygame.display.set_caption('Gallivanter')
right = False
left = False
steps = 0
#Animated pictures
moveRight = [pygame.image.load('C:/Users/rkwan/Desktop/R1.png'), pygame.image.load('C:/Users/rkwan/Desktop/R2.PNG'), pygame.image.load('C:/Users/rkwan/Desktop/R3.PNG'), pygame.image.load('C:/Users/rkwan/Desktop/R4.PNG'), pygame.image.load('C:/Users/rkwan/Desktop/R5.PNG'), pygame.image.load('C:/Users/rkwan/Desktop/R6.PNG'), pygame.image.load('C:/Users/rkwan/Desktop/R7.PNG'), pygame.image.load('C:/Users/rkwan/Desktop/R8.PNG'), pygame.image.load('C:/Users/rkwan/Desktop/R9.PNG')]
standing = pygame.image.load('C:/Users/rkwan/Desktop/R10.PNG')
transparent = (0,0,0,0)
enemy_health = 100
user_health = 100
#hit sound effect
hit_sound = pygame.mixer.Sound('C:/Users/rkwan/Downloads/Hit.wav')
#dying sound effect
dying_sound = pygame.mixer.Sound('C:/Users/rkwan/Downloads/die.wav')
dying_sound.set_volume(1.0)
#music
music = pygame.mixer.music.load('C:/Users/rkwan/Downloads/Ducktales.mp3')
#play the music on loop
pygame.mixer.music.play(-1)
#making the music quieter.
pygame.mixer.music.set_volume(0.5)
def save_highscore(new_score):
score_file = open('Highscore.txt', 'w')
score_file.write(str(new_score))
score_file.close()
def get_highscore(highscore):
score_file = open('Highscore.txt', 'r')
highscore = int(score_file.read())
return highscore
score_file.close()
def run():
global steps
global screen
global enemy_health
global user_health
bool = True
#obstacle
obstacle = False
x = 350
y = 400
f = 0
global i
#round number
i = 1
#starting highscore
highscore = 0
highscore = get_highscore(highscore)
current_score = i
if current_score > highscore:
save_highscore(current_score)
round = False
while bool:
for event in pygame.event.get():
if event.type == pygame.QUIT:
bool = False
#starting highscore
highscore = 0
highscore = get_highscore(highscore)
current_score = i
if current_score > highscore:
save_highscore(current_score)
pygame.time.delay(60)
timer.tick(27)
background = pygame.image.load('C:/Users/rkwan/Desktop/picture.PNG').convert()
#display the background onto the screen
screen.blit(background, (f,0))
# #settings
# settings_icon = pygame.image.load('C:/Users/rkwan/Desktop/Settings.png')
# settings_sized = pygame.transform.scale(settings_icon, (50,50))
#
# #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:
# settings()
if round == False:
x,y,f,round, left, right = movement(x, y, f,round, False, False)
if i == 1:
#font for the button attack text
round1_font = pygame.font.Font('freesansbold.ttf', 50)
round1_text = round1_font.render('Round 1', True, (255,255,255))
round1_rect = round1_text.get_rect()
round1_rect.center = (175,100)
#high score text
score_font = pygame.font.Font('freesansbold.ttf', 16)
score_text = score_font.render('Highscore: ' + str(highscore), True, (255,255,255))
score_rect = score_text.get_rect()
score_rect.center = (680,40)
screen.blit(score_text, score_rect)
screen.blit(round1_text, round1_rect)
if i == 2:
#font for the button attack text
round_font = pygame.font.Font('freesansbold.ttf', 50)
round_text = round_font.render('Round 2', True, (255,255,255))
round_rect = round_text.get_rect()
round_rect.center = (175,100)
score_font = pygame.font.Font('freesansbold.ttf', 16)
score_text = score_font.render('Highscore: ' + str(highscore), True, (255,255,255))
score_rect = score_text.get_rect()
score_rect.center = (680,40)
screen.blit(score_text, score_rect)
screen.blit(round_text, round_rect)
if i == 3:
#font for the button attack text
round_font = pygame.font.Font('freesansbold.ttf', 50)
round_text = round_font.render('Round 3', True, (255,255,255))
round_rect = round_text.get_rect()
round_rect.center = (175,100)
score_font = pygame.font.Font('freesansbold.ttf', 16)
score_text = score_font.render('Highscore: ' + str(highscore), True, (255,255,255))
score_rect = score_text.get_rect()
score_rect.center = (680,40)
screen.blit(score_text, score_rect)
screen.blit(round_text, round_rect)
if i == 4:
#font for the button attack text
round1_font = pygame.font.Font('freesansbold.ttf', 50)
round1_text = round1_font.render('Round 4', True, (255,255,255))
round1_rect = round1_text.get_rect()
round1_rect.center = (175,100)
score_font = pygame.font.Font('freesansbold.ttf', 16)
score_text = score_font.render('Highscore: ' + str(highscore), True, (255,255,255))
score_rect = score_text.get_rect()
score_rect.center = (680,40)
screen.blit(score_text, score_rect)
screen.blit(round1_text, round1_rect)
#obstacle code
t = 700
if x >=350:
while obstacle:
y = 400
for event in pygame.event.get():
if event.type == pygame.QUIT:
run = False
# #settings
# settings_icon = pygame.image.load('C:/Users/rkwan/Desktop/Settings.png')
# settings_sized = pygame.transform.scale(settings_icon, (50,50))
#
# #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:
# settings()
keys = pygame.key.get_pressed()
if keys[pygame.K_SPACE] or keys[pygame.K_w] or keys[pygame.K_UP]:
y = y - 200
#tumbleweed picture
tumbleweed = pygame.image.load('C:/Users/rkwan/Desktop/tumbleweed.PNG').convert()
t=t-1
#displaying the elements on the screen
obstacle_box = pygame.draw.rect(screen, (0,0,0),(t+100, 470, 70,70),1)
character_box = pygame.draw.rect(screen, (0,0,0),(x+10, y, 90,130),1)
screen.blit(background, (f,0))
screen.blit(pygame.transform.scale(tumbleweed, (70,70)),(t, 460))
screen.blit(pygame.transform.scale(standing, (125,125)), (x,y))
#display settings onto the screen
# screen.blit(settings_sized, (740, 15))
#boundary collision
if obstacle_box.y - 70 < character_box.y + 130 and obstacle_box.y + 70> character_box.y:
if obstacle_box.x > character_box.x and obstacle_box.x < character_box.x + 90:
obstacle = False
dying_sound.play()
#if the obstacle touches the character, they will go back one round
if i <= 1:
i = 1
else:
i -= 1
#while loop will be stopped if the obstacle moves off the screen
if obstacle_box.x + 70 < 0:
obstacle = False
screen.fill(0,0,0)
pygame.display.update()
pygame.display.flip()
else:
#round 1
if i == 1:
round = round_1(x,y, round)
#round 2
if i == 2:
round = round_2(x,y, round)
#obstacle will appear after this round is finished
obstacle = True
#round 3
if i == 3:
round = round_3(x,y, round)
#round 4
if i == 4:
round = round_4(x,y, round)
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 += 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 += 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):
y = 400
#setting the background image
if f <= -606:
f = 0
#controls of the character and the background
keys = pygame.key.get_pressed()
#moving to the left
if keys[pygame.K_LEFT] or keys[pygame.K_a]:
left = True
right = False
if f >= 0:
x -= 10
if x <=0:
x = 0
else:
f += 10
#moving to the right
elif keys[pygame.K_RIGHT] or keys[pygame.K_d] :
right = True
left = False
if x < 350:
x += 10
else:
f -= 10
#jumping control
elif keys[pygame.K_w]or keys[pygame.K_UP] or keys[pygame.K_SPACE]:
y = y - 150
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
#settings screen
def settings():
x = 175
y = 175
settings_bool = True
#screen initialization
settings_screen = pygame.display.set_mode((800,600))
settings_screen.fill((255,255,255))
#background image
background = pygame.image.load('C:/Users/rkwan/Desktop/picture.PNG').convert()
settings_screen.blit(background, (0,0))
while settings_bool:
#get the position of the mouse
mouse_pos = pygame.mouse.get_pos()
#creating a box to hold all the setting elements.
pygame.draw.rect(settings_screen, (192,192,192), (150,100,500,400))
#Sounds slider
rectangle_1 = pygame.draw.rect(settings_screen, (0,0,0), (175,150, 450,8))
pygame.draw.circle(settings_screen, (0,0,0),(y, 150), 10)
#Slider #2 (music)
rectangle_2 = pygame.draw.rect(settings_screen, (0,0,0), (175,230, 450,8))
pygame.draw.circle(settings_screen, (0,0,0),(x, 230), 10)
for event in pygame.event.get():
if event.type == pygame.QUIT:
settings_bool = False
elif event.type == pygame.MOUSEBUTTONDOWN:
if rectangle_1.collidepoint(event.pos):
mouse_pos = event.pos
y = mouse_pos[0]
#adjust the volume of the sounds
hit_sound.set_volume(y/500)
if rectangle_2.collidepoint(event.pos):
mouse_pos = event.pos
x = mouse_pos[0]
#adjust the volume of the music
pygame.mixer.music.set_volume(x/500)
#exit button
if 175 < mouse_pos[0] < 625 and 425 < mouse_pos[1] < 475:
pygame.draw.rect(settings_screen, (216,191,216), (175,425,450, 50))
if event.type == pygame.MOUSEBUTTONDOWN:
settings_bool = False
else:
pygame.draw.rect(settings_screen, (153,50,204), (175,425,450,50))
#font for the button attack text
exit_font = pygame.font.Font('freesansbold.ttf', 22)
exit_text = exit_font.render('Exit', True, (255,255,255))
exit_rect = exit_text.get_rect()
exit_rect.center = (400, 450)
#Main menu button
if 175 < mouse_pos[0] < 625 and 355 < mouse_pos[1] < 405:
pygame.draw.rect(settings_screen, (216,191,216), (175,355,450, 50))
if event.type == pygame.MOUSEBUTTONDOWN:
#change outcome
settings_bool = False
else:
pygame.draw.rect(settings_screen, (153,50,204), (175,355,450,50))
#font for the button attack text
menu_font = pygame.font.Font('freesansbold.ttf', 22)
menu_text = menu_font.render('Main Menu', True, (255,255,255))
menu_rect = menu_text.get_rect()
menu_rect.center = (400, 380)
#Save Game Button
if 175 < mouse_pos[0] < 625 and 280 < mouse_pos[1] < 330:
pygame.draw.rect(settings_screen, (216,191,216), (175,280,450, 50))
if event.type == pygame.MOUSEBUTTONDOWN:
#change outcome
settings_bool = False
else:
pygame.draw.rect(settings_screen, (153,50,204), (175,280,450,50))
#font for the button attack text
save_font = pygame.font.Font('freesansbold.ttf', 22)
save_text = save_font.render('Save Game', True, (255,255,255))
save_rect = save_text.get_rect()
save_rect.center = (400, 305)
#displaying the buttons on the screen
settings_screen.blit(exit_text, exit_rect)
settings_screen.blit(menu_text, menu_rect)
settings_screen.blit(save_text, save_rect)
pygame.display.flip()
def round_1(x,y, round):
global enemy_sized
#enemy
enemy = pygame.image.load('C:/Users/rkwan/Desktop/enemy.png')
enemy_sized = pygame.transform.scale(enemy, (125, 130))
screen.blit(enemy_sized, (x + 220, y))
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/rkwan/Desktop/Settings.png')
# settings_sized = pygame.transform.scale(settings_icon, (50,50))
#
# #display settings onto the screen
# screen.blit(settings_sized, (740, 15))
#
close, user_dead, enemy_dead = questions_screen('What is 1 + 1?', '', 'The answer is: 2.', incorrect,'2', user_damage, enemy_damage, close, 'Use addition to add the two numbers together.', 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('What is 2 + 2?', '', 'The answer is: 4.', incorrect,'4', user_damage, enemy_damage, close, 'Use addition to add the two numbers together.', user_dead, enemy_dead, True, False, False, False)
#add textbox here to congratulate the player
#
#
#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 + 4?', '', 'The answer is: 8.', incorrect,'8', user_damage, enemy_damage, close, 'Use addition to add the two numbers together.', 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 8 + 8?', '', 'The answer is: 16.', incorrect,'16', user_damage, enemy_damage, close, 'Use addition to add the two numbers together.', 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 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, 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
#
#
round = False
return round
pygame.display.flip()
def round_2(x,y, round):
global enemy_sized
#enemy
enemy = pygame.image.load('C:/Users/rkwan/Desktop/Enemy2.png')
enemy_sized = pygame.transform.scale(enemy, (125, 130))
screen.blit(enemy_sized, (x + 220, y))
#text box
#text_1 = pygame.draw.rect(screen, (255, 255, 255), (100, 100, 600,125))
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/rkwan/Desktop/Settings.png')
# settings_sized = pygame.transform.scale(settings_icon, (50,50))
#
# #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)
#add textbox here to congratulate the player
#
#
#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
#
#
round = False
return round
pygame.display.flip()
def round_3(x,y, round):
global enemy_sized
#enemy
enemy = pygame.image.load('C:/Users/rkwan/Desktop/enemy3.gif')
enemy_sized = pygame.transform.scale(enemy, (125, 130))
screen.blit(enemy_sized, (x + 220, y))
#text box
#text_1 = pygame.draw.rect(screen, (255, 255, 255), (100, 100, 600,125))
incorrect = 0
variable = 1
global correct_variable
global incorrect_variable
correct_variable = 0
incorrect_variable = 0
global enemy_1
global user
user_damage = 35
enemy_damage = 30
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/rkwan/Desktop/Settings.png')
# settings_sized = pygame.transform.scale(settings_icon, (50,50))
#
# #display settings onto the screen
# screen.blit(settings_sized, (740, 15))
close, user_dead, enemy_dead = questions_screen('What is 1 / 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, False, True, 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 / 2?', '', 'The answer is: 1.', incorrect,'1', user_damage, enemy_damage, close, 'Use addition to add the two numbers together.', user_dead, enemy_dead, False, False, True, False)
#add textbox here to congratulate the player
#
#
#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 / 4?', '', 'The answer is: 1.', incorrect,'1', user_damage, enemy_damage, close, 'Use addition to add the two numbers together.', user_dead, enemy_dead, False, False, True, 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 / 8?', '', 'The answer is: 1.', incorrect,'1', user_damage, enemy_damage, close, 'Use addition to add the two numbers together.', user_dead, enemy_dead, False, False, True, 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: 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 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
#
#
round = False
return round
pygame.display.flip()
def round_4(x,y, round):
global enemy_sized
#enemy
enemy = pygame.image.load('C:/Users/rkwan/Desktop/enemy4.gif')
enemy_sized = pygame.transform.scale(enemy, (125, 130))
screen.blit(pygame.transform.flip(enemy_sized, True, False), (x + 220, y))
incorrect = 0
variable = 1
global correct_variable
global incorrect_variable
correct_variable = 0
incorrect_variable = 0
global enemy_1
global user
user_damage = 40
enemy_damage = 30
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/rkwan/Desktop/Settings.png')
# settings_sized = pygame.transform.scale(settings_icon, (50,50))
#
# #display settings onto the screen
# screen.blit(settings_sized, (740, 15))
close, user_dead, enemy_dead = questions_screen('What is 1 / 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, False, False, True)
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 / 2?', '', 'The answer is: 1.', incorrect,'1', user_damage, enemy_damage, close, 'Use addition to add the two numbers together.', user_dead, enemy_dead, False, False, False, True)
#add textbox here to congratulate the player
#
#
#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 / 4?', '', 'The answer is: 1.', incorrect,'1', user_damage, enemy_damage, close, 'Use addition to add the two numbers together.', user_dead, enemy_dead, False, False, False, True)
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 / 8?', '', 'The answer is: 1.', incorrect,'1', user_damage, enemy_damage, close, 'Use addition to add the two numbers together.', user_dead, enemy_dead, False, False, False, True)
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: 1.', incorrect,'1', user_damage, enemy_damage, close, 'Use addition to add the two numbers together.', user_dead, enemy_dead, False, True, False, True)
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
#
#
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):
#spells
ice = False
fire = False
#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/rkwan/Desktop/Settings.png')
# settings_sized = pygame.transform.scale(settings_icon, (50,50))
# #display settings onto the screen
# screen.blit(settings_sized, (740, 15))
#question text
font = pygame.font.Font('freesansbold.ttf', 30)
question_text = font.render(text, True, (0,0,0))
#textbox to hold questions
textbox = question_text.get_rect()
textbox.center = (200,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, ice, fire = spell(round1, round2, round3, round4, True, ice, fire)
if test_bool == False:
space, user_dead, enemy_dead = spell_ball(True, health, user_damage, enemy_damage, space, user_dead, enemy_dead, ice, fire)
if space == True: