-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathballblast.py
2832 lines (2367 loc) · 84.8 KB
/
ballblast.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
#####BALL BLAST DIMENSIONS MENU.py
from pygame import *
from datetime import datetime
from math import *
from random import *
init()
font.init()
mixer.init()
fontSize = 22
storyFont=font.SysFont("Comic Sans MS",fontSize) #font for scrolling story
dialogueFont=font.Font("A Goblin Appears!.otf",10)#dialogue font
lvlFont=font.Font("CRACKERS BRUSHER.otf", 100)#lvlfont
lolfont=font.SysFont("Comic Sans MS",30)#font for each lvl
myClock=time.Clock()
size=width,height=1280,900
screen=display.set_mode(size)
RED=(255,0,0)
GREEN=(0,255,0)
BLUE=(0,0,255)
BLACK=(0,0,0)
WHITE=(255,255,255)
ORANGE=(242,76,0)
YELLOW=(255,248,50)
#####
donelevels=set() #set with levels that are completed
################################################
MAXRAPID=2 #fire a bullet when rapid reaches MAXRAPID
rapid=MAXRAPID
#loading images
circle=image.load("circle2.png")
bigcircle=transform.scale(circle,(140,140))
midcircle=transform.scale(circle,(100,100))
smcircle=transform.scale(circle,(60,60))
guypic=image.load("guy.png")
guypic=transform.scale(guypic,(60,80))
ghostguypic=image.load("ghostguy.png")
ghostguypic=transform.scale(ghostguypic,(60,80))
fastpic=image.load("fast.png")
fastpic=transform.scale(fastpic,(60,60))
slowpic=image.load("slowpic.png")
slowpic=transform.scale(slowpic,(60,60))
xpic=image.load("2x.png")
xpic=transform.scale(xpic,(60,60))
ghostpic=image.load("ghost.png")
ghostpic=transform.scale(ghostpic,(60,60))
bulletpic=image.load("9mm.png")
bulletpic=transform.scale(bulletpic,(20,20))
#initializing variables
score=0
tmin=20 #min & max health for full-sized targets
tmax=40
mtmin=10 #min & max for medium targets
mtmax=20
stmin=5 #min & max small targets
stmax=10
yspeed=0.015 #angle added to sin function get next y-value of balls
slowyspeed=0.0075 #when slow powerup is on
xspeed=6 #pixels to move left or right every frame
slowxspeed=3 #when slow is on
targets=[] #list of full-sized targets
midtargets=[] #medium targets
smtargets=[] #small
maxtarg=12 #maximum "number" of targets on screen at a time
death=False
slow=False #slow balls powerup
ghost=False #ghost player powerup
powerupchance=2400 #1/2400 chance of a powerup appearing every frame
#duration left of each powerup
fastduration=0 #faster bullets powerup
slowduration=0
xduration=0 #2x bullets powerup
ghostduration=0
#list of powerup balls on screen
slowballs=[]
gunfastballs=[]
xballs=[]
ghostballs=[]
bullets=[]
def moveBalls(targets,lvl,midtargets,smtargets,gfastballs,slowballs,xballs,ghostballs,slow):
for target in targets: #full-sized targets
if slow: #slow down speeds if show powerup is on
if target[2]>0:
target[2]=slowxspeed
else:
target[2]=-slowxspeed
else: #speed up otherwise
if target[2]>0:
target[2]=xspeed
else:
target[2]=-xspeed
if target[5]: #if target is in frame
if target[0]>1210 or target[0]<70: #if target hits edges
target[2]*=-1 #switch horizontal direction
else: #if outside frame
if target[0]<1100 and target[0]>180: #if enters frame
target[5]=True
target[0]+=target[2] #move ball horizontally
target[1]=int(-(sin(target[3])*600)+730) #using sin function to determine path of ball
if slow:
target[3]+=slowyspeed #change to next angle
else:
target[3]+=yspeed
if target[3]>pi: #reset to 0 when angle reaches 180 degrees
target[3]-=pi
for target in midtargets: #medium targets
if slow:
if target[2]>0:
target[2]=slowxspeed
else:
target[2]=-slowxspeed
else:
if target[2]>0:
target[2]=xspeed
else:
target[2]=-xspeed
if target[0]>1250 or target[0]<30:
target[2]*=-1
target[0]+=target[2]
if target[5]: #if ball has hit the bottom at leaast once
target[1]=int(-(sin(target[3])*500)+750) #follow medium-sized ball path
if slow:
target[3]+=slowyspeed
else:
target[3]+=yspeed
else: #if ball just spawned from parent full-sized ball
target[1]=int(-(sin(target[3])*600)+750) #keep following full-sized ball path for smoothness
if slow:
target[3]+=slowyspeed
else:
target[3]+=yspeed
if target[3]>pi: #when hits bottom
target[5]=True #start following medium ball path
if target[3]>pi:
target[3]-=pi
for target in smtargets: #small targets
if slow:
if target[2]>0:
target[2]=slowxspeed
else:
target[2]=-slowxspeed
else:
if target[2]>0:
target[2]=xspeed
else:
target[2]=-xspeed
if target[0]>1250 or target[0]<30:
target[2]*=-1
target[0]+=target[2]
if target[5]:
target[1]=int(-(sin(target[3])*400)+770)
if slow:
target[3]+=slowyspeed
else:
target[3]+=yspeed
else:
target[1]=int(-(sin(target[3])*500)+770)
if slow:
target[3]+=slowyspeed
else:
target[3]+=yspeed
if target[3]>pi:
target[5]=True
if target[3]>pi:
target[3]-=pi
#powerup balls, follow same rules as small balls except they don't spawn from a parent ball and don't need smoothness fix
for target in gfastballs:
if slow:
if target[2]>0:
target[2]=slowxspeed
else:
target[2]=-slowxspeed
else:
if target[2]>0:
target[2]=xspeed
else:
target[2]=-xspeed
if target[4]:
if target[0]>1250 or target[0]<30:
target[2]*=-1
else:
if target[0]<1100 and target[0]>180:
target[4]=True
target[0]+=target[2]
target[1]=int(-(sin(target[3])*400)+770)
if slow:
target[3]+=slowyspeed
else:
target[3]+=yspeed
if target[3]>pi:
target[3]-=pi
for target in slowballs:
if slow:
if target[2]>0:
target[2]=slowxspeed
else:
target[2]=-slowxspeed
else:
if target[2]>0:
target[2]=xspeed
else:
target[2]=-xspeed
if target[4]:
if target[0]>1250 or target[0]<30:
target[2]*=-1
else:
if target[0]<1100 and target[0]>180:
target[4]=True
target[0]+=target[2]
target[1]=int(-(sin(target[3])*400)+770)
if slow:
target[3]+=slowyspeed
else:
target[3]+=yspeed
if target[3]>pi:
target[3]-=pi
for target in xballs:
if slow:
if target[2]>0:
target[2]=slowxspeed
else:
target[2]=-slowxspeed
else:
if target[2]>0:
target[2]=xspeed
else:
target[2]=-xspeed
if target[4]:
if target[0]>1250 or target[0]<30:
target[2]*=-1
else:
if target[0]<1100 and target[0]>180:
target[4]=True
target[0]+=target[2]
target[1]=int(-(sin(target[3])*400)+770)
if slow:
target[3]+=slowyspeed
else:
target[3]+=yspeed
if target[3]>pi:
target[3]-=pi
for target in ghostballs:
if slow:
if target[2]>0:
target[2]=slowxspeed
else:
target[2]=-slowxspeed
else:
if target[2]>0:
target[2]=xspeed
else:
target[2]=-xspeed
if target[4]:
if target[0]>1250 or target[0]<30:
target[2]*=-1
else:
if target[0]<1100 and target[0]>180:
target[4]=True
target[0]+=target[2]
target[1]=int(-(sin(target[3])*400)+770)
if slow:
target[3]+=slowyspeed
else:
target[3]+=yspeed
if target[3]>pi:
target[3]-=pi
#change max targets depending on level and current score
if lvl<3:
maxtarg=12+int(score/500)
elif lvl<6:
maxtarg=13+int(score/500)
elif lvl<9:
maxtarg=14+int(score/500)
else:
maxtarg=15+int(score/500)
return maxtarg #return updated max targets
#player/guy bullets all 3 target lists powerup balls ghost powerup duration ghost boolean pic to blit for boss levels location to blit
def drawScene(screen,score, g ,bull,targ,midtarg,smtarg,gunfastballs,slowballs,xballs,ghostballs,ghostduration,background,ghost,health,maxhealth, pic, loc):
y=0
if background==startback: #blitting background (startback is special because it's tall)
y=-1200
screen.blit(background,(0,y))
for b in bull:
screen.blit(bulletpic,(b[0]-10,b[1]-10)) #blitting bullet pic
for t in targ:
screen.blit(bigcircle,(t[0]-70,t[1]-70)) #ball pic
num=lolfont.render(str(t[4]),True,BLACK) #health text
if t[4]>10:
screen.blit(num,(t[0]-17,t[1]-19)) #blitting at different spots depending on width of text
else:
screen.blit(num,(t[0]-9,t[1]-23))
for t in midtarg:
screen.blit(midcircle,(t[0]-50,t[1]-50))
num=lolfont.render(str(t[4]),True,BLACK)
if t[4]>10:
screen.blit(num,(t[0]-17,t[1]-19))
else:
screen.blit(num,(t[0]-9,t[1]-23))
for t in smtarg:
screen.blit(smcircle,(t[0]-30,t[1]-30))
num=lolfont.render(str(t[4]),True,BLACK)
screen.blit(num,(t[0]-9,t[1]-23))
for t in gunfastballs: #blitting powerup pics
screen.blit(fastpic,(t[0]-30,t[1]-30))
for t in slowballs:
screen.blit(slowpic,(t[0]-30,t[1]-30))
for t in xballs:
screen.blit(xpic,(t[0]-30,t[1]-30))
for t in ghostballs:
screen.blit(ghostpic,(t[0]-30,t[1]-30))
if ghost: #flashing ghost effect when 1 second of ghost powerup left
if ghostduration<20:
screen.blit(ghostguypic,(g[0]-30,g[1]-50))
elif ghostduration<45:
screen.blit(guypic,(g[0]-30,g[1]-50))
elif ghostduration<75:
screen.blit(ghostguypic,(g[0]-30,g[1]-50))
elif ghostduration<110:
screen.blit(guypic,(g[0]-30,g[1]-50))
else:
screen.blit(ghostguypic,(g[0]-30,g[1]-50))
else:
screen.blit(guypic,(g[0]-30,g[1]-50)) #regular non-ghost guy
scoretext=lolfont.render(str(score),True,WHITE)
screen.blit(scoretext,(5,0)) #score in top-left corner
#health bar
maxhealthrect=Rect(760,20,500,40)
healthrect=Rect(760,20,500*(health/maxhealth),40)
draw.rect(screen,GREEN,healthrect)
draw.rect(screen,BLACK,maxhealthrect,5)
#blitting boss pic
screen.blit(pic,(loc))
display.flip()
def checkHits(bull,targets,midtargets,smtargets,score):
for b in bull:
for target in targets:
if sqrt((b[0]-target[0])**2+(b[1]-target[1])**2)<75: #if bullet hits target
score+=1 #gain 1 point
if target[4]==1: #if ball has one hp left
midtargets.append([target[0],target[1],-target[2],target[3],randint(mtmin,mtmax),False]) #split into 2 medium balls
midtargets.append([target[0],target[1],target[2],target[3],randint(mtmin,mtmax),False])
targets.remove(target)
else: #if more hp
target[4]-=1 #take one hp off
try:
bull.remove(b)
except:
pass
for target in midtargets: #same for medium targets
if sqrt((b[0]-target[0])**2+(b[1]-target[1])**2)<55:
score+=1
if target[4]==1:
smtargets.append([target[0],target[1],-target[2],target[3],randint(stmin,stmax),False])
smtargets.append([target[0],target[1],target[2],target[3],randint(stmin,stmax),False])
midtargets.remove(target)
else:
target[4]-=1
try:
bull.remove(b)
except:
pass
for target in smtargets:
if sqrt((b[0]-target[0])**2+(b[1]-target[1])**2)<35:
score+=1
if target[4]==1:
smtargets.remove(target) #no split from small balls
else:
target[4]-=1
try:
bull.remove(b)
except:
pass
return score
def checkDeath(targets,midtargets,smtargets,guy,ghost):
if ghost==False: #if ghost powerup isn't active
#death=True if ball hits player
for t in targets:
if sqrt((t[0]-guy[0])**2+(t[1]-guy[1])**2)<100:
return True
for t in midtargets:
if sqrt((t[0]-guy[0])**2+(t[1]-guy[1])**2)<80:
return True
for t in smtargets:
if sqrt((t[0]-guy[0])**2+(t[1]-guy[1])**2)<60:
return True
return False #death=False if balls don't hit or if ghost is active
def moveBullets(bull): #move bullets up
for b in bull:
b[0]+=b[2]
b[1]+=b[3]
if b[1]<0: #delete bullet when it leaves frame
bull.remove(b)
def gunfastcheck(gunfastballs,guy,fastduration):
for t in gunfastballs:
if sqrt((t[0]-guy[0])**2+(t[1]-guy[1])**2)<60:
gunfastballs.remove(t)
return (450) #fast gun powerup duration if powerup touches player
if fastduration>0:
fastduration-=1 #duration goes down by 1 every frame if powerup is active
return (fastduration)
else:
return (0)
def slowcheck(slowballs,guy,slowduration):
for t in slowballs:
if sqrt((t[0]-guy[0])**2+(t[1]-guy[1])**2)<60:
slowballs.remove(t)
return (300) #same as fast powerup ^
if slowduration>0:
slowduration-=1
return (slowduration)
else:
return (0)
def xcheck(xballs,guy,xduration):
for t in xballs:
if sqrt((t[0]-guy[0])**2+(t[1]-guy[1])**2)<60:
xballs.remove(t)
return (450)
if xduration>0:
xduration-=1
return (xduration)
else:
return (0)
def ghostcheck(ghostballs,guy,ghostduration):
for t in ghostballs:
if sqrt((t[0]-guy[0])**2+(t[1]-guy[1])**2)<60:
ghostballs.remove(t)
return (600)
if ghostduration>0:
ghostduration-=1
return (ghostduration)
else:
return (0)
#health values #pic of boss location
def checkhealth(maxhealth,health,bullets,frame, x,y):
hitbox=Rect(x,y,frame.get_width(),frame.get_height()) #hitbox is the boss's picture in current frame
for b in bullets:
if hitbox.collidepoint(b[0],b[1]):
health-=1 #take health off if hit
bullets.remove(b)
return (health) #return updated health
###############################################
#########menu picture loading
startpic=image.load("Text Pictures\start.png")
controlpic=image.load("Text Pictures\controls.png")
exitpic=image.load("Text Pictures\exit.png")
titlepic=image.load("Text Pictures\\title.png")
menuback=image.load("Text Pictures\\menuback.jpg")
menuback=transform.scale(menuback,(width,height))
startback=image.load("Text Pictures\\startback.png")
startback=transform.scale(startback,(width,2100))
dbox=image.load("txtbox.png")
endback=image.load("endstory.jpg")
endback=transform.scale(endback,(width,2100))
startpic.get_width()
endpic=image.load("Text Pictures\\end.png")
hubpic=image.load("Hub.jpg")
hubpic=transform.scale(hubpic,(800,height))
guy=image.load("maincharacter.png")
###dialogue box values
dboxX=240
dboxY=700
###oVALS for hub
stagelist=[Rect(375,750,50,25),
Rect(400,700,50,25),
Rect(425,650,50,25),
Rect(450,590,50,25),
Rect(410,560,50,25),
Rect(380,520,50,25),
Rect(320,470,50,25),
Rect(350,430,50,25),
Rect(370,380,50,25),
Rect(400,330,50,25),
Rect(400,280,50,25),
Rect(400,220,50,25),
Rect(385,175,50,25)]
###background for each world
lvl2back=image.load("lvl2back.jpg")
lvl2back=transform.scale(lvl2back,(1280,900))
lvl3back=image.load("lvl3back.png")
lvl3back=transform.scale(lvl3back,(1280,900))
lvl4back=image.load("lvl4back.png")
lvl4back=transform.scale(lvl4back,(1280,900))
lvl5back=image.load("lvl5back.jpg")
lvl5back=transform.scale(lvl5back,(1280,900))
####knight/skeleton
dialoguetxt_skeleton=open("dialogue.txt","r") #opening txt file
dialoguetxt_skeleton=dialoguetxt_skeleton.readlines()
dlist_skeleton=[]
for i in dialoguetxt_skeleton:
d=i.strip().split(" ")
dlist_skeleton.append(d)
final_skeleton=" ".join(dlist_skeleton[0])
final2_skeleton=" ".join(dlist_skeleton[1])
final3_skeleton=" ".join(dlist_skeleton[2]) #creating a different variable for each line
dbox=image.load("txtbox.png")####loading dialogue
dbox=transform.scale(dbox,(800,150))
###knight
xyknight=[] ###list to append after knight dies
def knight(): #knight boss
pics=[] ##sprites
frame=0
frameDelay=6
y=177 #starting y val
j=1 #changing val for y
x=(-1/5*(1/2*((y-100)**2))+600)*j ####horizontal parabola
active=False ###to run function 1 time
for i in range(7,10,1):
pics.append(image.load("knight"+str(i)+".png")) ##sprite
######
#resetting all variables that can be changed in other levels
MAXRAPID=2
rapid=MAXRAPID
maxhealth=50 #knight's health
health=50
score=0
targets=[]
midtargets=[]
smtargets=[]
maxtarg=12
death=False
slow=False
ghost=False
powerupchance=1200
fastduration=0
slowduration=0
xduration=0
ghostduration=0
slowballs=[]
gunfastballs=[]
xballs=[]
ghostballs=[]
bullets=[]
lvl=0 #level number
powerupchance=1200
maxtarg=12
#start with 3 targets
targets.append([randint(100,1180),0,xspeed,pi/2,randint(tmin,tmax),True])
targets.append([-70,xspeed,6,pi/2,randint(tmin,tmax),False])
targets.append([1350,0,-xspeed,pi/2,randint(tmin,tmax),False])
###
running=True
while running:
for evt in event.get():
if evt.type==QUIT:
running=False
quit()
mb=mouse.get_pressed()
if not active: #knight dialogue
dialogue_knight()
active=True
mixer.music.load("Sounds\\knight.mp3")
mixer.music.set_volume(0.1)
mixer.music.play(-1)
y+=j
x=(-1/5*(1/2*((y-100)**2))+600)*j #path
frameDelay-=1
if frameDelay==0:
frameDelay=5
frame+=1
if frame==3:
frame=0
if x<-600 or x>600: #reversing direction and flipping pic
j*=-1
for i in range(len(pics)):
pics[i]=transform.flip(pics[i],1,0)
if not active: #running dialogue 1 time
dialogue_knight()
mixer.music.set_volume(0.8)
active=True
mx,my=mouse.get_pos()
guy=[mx,770] #pos of main character
#add ball if less on screen than max target points
#big balls worth 4 points mid-2 small-1
if len(targets)*4+len(midtargets)*2+len(smtargets)<maxtarg:
lr=randint(1,2) #coming from left or right
if lr==1:
# x y xspeed yspeed health inside frame=False
targets.append([-30,100,6, pi/2, randint(tmin,tmax), False])
else:
targets.append([1310,100,-6,pi/2,randint(tmin,tmax),False])
powerup=randint(0,powerupchance) #powerups awarded if randint lands on 1-4
lr=randint(1,2)
#add ball to corresponding powerup list if the powerup isn't already on screen
if powerup==1 and len(gunfastballs)==0:
if lr==1:
gunfastballs.append([-30,100,6,pi/2,False])
else:
gunfastballs.append([1310,100,-6,pi/2,False])
if powerup==2 and len(slowballs)==0:
if lr==1:
slowballs.append([-30,100,6,pi/2,False])
else:
slowballs.append([1310,100,-6,pi/2,False])
if powerup==3 and len(xballs)==0:
if lr==1:
xballs.append([-30,100,6,pi/2,False])
else:
xballs.append([1310,100,-6,pi/2,False])
if powerup==4 and len(ghostballs)==0:
if lr==1:
ghostballs.append([-30,100,6,pi/2,False])
else:
ghostballs.append([1310,100,-6,pi/2,False])
if fastduration>0:
MAXRAPID=1 #fires twice as fast with fast powerup active
else:
MAXRAPID=2
if slowduration>0:
slow=True
else:
slow=False
if rapid>=MAXRAPID: #when rapid hits MAXRAPID
if xduration>0: #add 2 bullets if 2x bullets powerup active
bullets.append([guy[0]-10,guy[1]-20,0,-25])
bullets.append([guy[0]+10,guy[1]-20,0,-25])
else:
bullets.append([guy[0],guy[1]-20,0,-25])
rapid=0 #reset rapid
else:
rapid+=1
if ghostduration>0:
ghost=True
else:
ghost=False
if death==False:
maxtarg=moveBalls(targets,lvl,midtargets,smtargets,gunfastballs,slowballs,xballs,ghostballs,slow) # bg boss pic location
drawScene(screen,score,guy,bullets,targets,midtargets,smtargets,gunfastballs,slowballs,xballs,ghostballs,ghostduration,startback,ghost,health,maxhealth,pics[int(frame)],(width/2+x,y))
health=checkhealth(maxhealth,health,bullets,pics[int(frame)],(width/2+x),y)
moveBullets(bullets)
score=checkHits(bullets,targets,midtargets,smtargets,score)
fastduration=gunfastcheck(gunfastballs,guy,fastduration)
slowduration=slowcheck(slowballs,guy,slowduration)
xduration=xcheck(xballs,guy,xduration)
ghostduration=ghostcheck(ghostballs,guy,ghostduration)
death=checkDeath(targets,midtargets,smtargets,guy,ghost)
if health<=0: #when knight dies
donelevels.add(0) #add knight's level to set of completed levels
#####blitting end text if win
xyknight.append(x)
xyknight.append(y)
death_knight() ###animation for win
endtext=lolfont.render("CONGRATULATIONS",True,BLACK)
screen.blit(endtext,(550,400))
endscore=lolfont.render("Score: "+str(score),True,BLACK)
screen.blit(endscore,(570,450))
nexttxt=lolfont.render("Back to hub (Left Click)",True,BLACK)
screen.blit(nexttxt,(520,500))
if mb[0]==1: #returning to hub
hub()
else:
##########blitting end text if lose
endtext=lolfont.render("GAME OVER",True,BLACK)
screen.blit(endtext,(550,400))
endscore=lolfont.render("Score: "+str(score),True,BLACK)
screen.blit(endscore,(570,450))
nexttxt=lolfont.render("Back to hub (Left Click)",True,BLACK)
screen.blit(nexttxt,(520,500))
if mb[0]==1: #return to hub
hub()
myClock.tick(60)
display.flip()
def death_knight(): ###################################################################################################################################################################################
active=False
pics=[]
x=0
for i in range(4,6,1):
pics.append(image.load("knight"+str(i)+".png"))
frame=0
frameDelay=6
running=True
mixer.music.load("Sounds\\victory.mp3")
mixer.music.play()
while running:
for evt in event.get():
if evt.type==QUIT:
quit()
screen.blit(startback,(0,-1200))
screen.blit(pics [int(frame)],(width/2+xyknight[0]+x,xyknight[1]))
if not active:
deathdialogue_knight()
myClock.tick(5)
active=True
x-=10
frameDelay-=1
if frameDelay==0:
frameDelay=4
frame+=1
if frame==2:
frame=0
mpos=mixer.music.get_pos()
if mpos==-1:
hub()
myClock.tick(60)
display.flip()
def dialogue_knight():
finaldialogue=""
finaldialogue2=""
screen.blit(dbox,(dboxX,dboxY))
for i in range (len(final_skeleton)):
finaldialogue+=final_skeleton[i]
d1=dialogueFont.render(finaldialogue,False,BLACK)
screen.blit(d1,(dboxX+50,dboxY+50))
display.flip()
myClock.tick(30)
for i in range(len(final2_skeleton)):
finaldialogue2+=final2_skeleton[i]
d1=dialogueFont.render(finaldialogue2,False,BLACK)
screen.blit(d1,(dboxX+50,dboxY+50+20))
display.flip()
myClock.tick(30)
time.wait(10000)
def deathdialogue_knight():
pics=[]
finaldialogue=""
screen.blit(dbox,(dboxX,dboxY))
for i in range(len(final3_skeleton)):
finaldialogue+=final3_skeleton[i]
d1=dialogueFont.render(finaldialogue,False,BLACK)
screen.blit(d1,(dboxX+50,dboxY+50))
display.flip()
myClock.tick(30)
###########################################################################################################################################################################################
#number of level
def level(lvl):
screen=display.set_mode(size)
mixer.music.load("Sounds\\dragon.mp3") ###################################################################################################################################################################################
mixer.music.play(-1)
############## mostly same as knight
MAXRAPID=2
rapid=MAXRAPID
health=lvl*50+300 #different health (score needed to win) based on number of level
maxhealth=health
targets=[]
midtargets=[]
smtargets=[]
death=False
slow=False
ghost=False
#different settings for each group of levels
if lvl<3:
powerupchance=1200
maxtarg=12
background=lvl2back
elif lvl<6:
powerupchance=1800
maxtarg=13
background=lvl3back
elif lvl<9:
powerupchance=2400
maxtarg=14
background=lvl4back
else:
powerupchance=3000
maxtarg=15
background=lvl5back
score=0
fastduration=0
slowduration=0
xduration=0
ghostduration=0
slowballs=[]
gunfastballs=[]
xballs=[]
ghostballs=[]
bullets=[]
targets.append([randint(100,1180),0,xspeed,pi/2,randint(tmin,tmax),True])
if lvl>3: #add a 4th ball after the first 4 levels
targets.append([randint(100,1180),0,xspeed,pi*2/3,randint(tmin,tmax),True])
targets.append([-70,xspeed,6,pi/2,randint(tmin,tmax),False])
targets.append([1350,0,-xspeed,pi/2,randint(tmin,tmax),False])
###############
running=True
while running:
for evt in event.get():
if evt.type==QUIT:
running=False
quit()
mb=mouse.get_pressed()
keys=key.get_pressed()
mx,my=mouse.get_pos()
guy=[mx,770]
if len(targets)*4+len(midtargets)*2+len(smtargets)<maxtarg:
lr=randint(1,2)
if lr==1:
targets.append([-30,100,6,pi/2,randint(tmin,tmax),False])
else:
targets.append([1310,100,-6,pi/2,randint(tmin,tmax),False])
powerup=randint(0,powerupchance)
lr=randint(1,2)
if powerup==1 and len(gunfastballs)==0:
if lr==1:
gunfastballs.append([-30,100,6,pi/2,False])
else:
gunfastballs.append([1310,100,-6,pi/2,False])
if powerup==2 and len(slowballs)==0:
if lr==1:
slowballs.append([-30,100,6,pi/2,False])
else:
slowballs.append([1310,100,-6,pi/2,False])
if powerup==3 and len(xballs)==0:
if lr==1:
xballs.append([-30,100,6,pi/2,False])
else:
xballs.append([1310,100,-6,pi/2,False])
if powerup==4 and len(ghostballs)==0:
if lr==1:
ghostballs.append([-30,100,6,pi/2,False])
else:
ghostballs.append([1310,100,-6,pi/2,False])
if fastduration>0:
MAXRAPID=1
else:
MAXRAPID=2
if slowduration>0:
slow=True
else:
slow=False
if rapid>=MAXRAPID:
if xduration>0:
bullets.append([guy[0]-10,guy[1]-20,0,-25])
bullets.append([guy[0]+10,guy[1]-20,0,-25])
else:
bullets.append([guy[0],guy[1]-20,0,-25])
rapid=0
else:
rapid+=1
if ghostduration>0:
ghost=True
else:
ghost=False
if death==False:
maxtarg=moveBalls(targets,lvl,midtargets,smtargets,gunfastballs,slowballs,xballs,ghostballs,slow) #boss pic not needed for regular levels
drawScene(screen,score,guy,bullets,targets,midtargets,smtargets,gunfastballs,slowballs,xballs,ghostballs,ghostduration,background,ghost,health,maxhealth,ghostpic,(-100,-100))
health=maxhealth-score #health=score left
moveBullets(bullets)
score=checkHits(bullets,targets,midtargets,smtargets,score)
fastduration=gunfastcheck(gunfastballs,guy,fastduration)
slowduration=slowcheck(slowballs,guy,slowduration)
xduration=xcheck(xballs,guy,xduration)
ghostduration=ghostcheck(ghostballs,guy,ghostduration)
death=checkDeath(targets,midtargets,smtargets,guy,ghost)
if health<=0: #when score requirement reached
donelevels.add(lvl) #add current level to completed list
running=False
endtext=lolfont.render("WINNER!!!",True,BLACK)
screen.blit(endtext,(550,400))
endscore=lolfont.render("Score: "+str(score),True,BLACK)
screen.blit(endscore,(570,450))
display.flip()
time.wait(1000)
hub()
else:
endtext=lolfont.render("GAME OVER",True,BLACK)
screen.blit(endtext,(550,400))
endscore=lolfont.render("Score: "+str(score),True,BLACK)
screen.blit(endscore,(570,450))
nexttxt=lolfont.render("Back to hub (Left Click)",True,BLACK)
screen.blit(nexttxt,(520,500))
if mb[0]==1:
hub()
myClock.tick(60)
display.flip()
###dragon, same as knight but with different pictures and harder gameplay settings
dialoguetxt_dragon=open("dialogue_dragon.txt","r")
dialoguetxt_dragon=dialoguetxt_dragon.readlines()
dlist_dragon=[]
for i in dialoguetxt_dragon:
d=i.strip().split(" ")
dlist_dragon.append(d)
final_dragon=" ".join(dlist_dragon[0])
final2_dragon=" ".join(dlist_dragon[1])
final3_dragon=" ".join(dlist_dragon[2])
xydragon=[]
def dragon():
screen=display.set_mode(size)
pics=[]
frame=0
frameDelay=6
x=5
j=5