-
Notifications
You must be signed in to change notification settings - Fork 2
/
FP Michal Shadman.py
2907 lines (2549 loc) · 145 KB
/
FP Michal Shadman.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
from pygame import *
from math import *
from random import *
import glob
#Final Project 2015: Super-HITMAN
#by: Michal Jez and Shadman Hassan
#SUPER-Hitman is a top down shooter where the objective is to kill all enemies onscreen
#per wave. He can move with WASD controls and can use primary and secondary weapons with mouse buttons.
#You can scroll to change weapons. There is a gun store to purchase more ammo. Press E to enter
#the gun store and press E at the counter to buy ammo, health, gun upgrades and special bullets
#such as homing and reflecting bullets. The shop can be entered at any time. The aim of the game is
#to survive the longest. Score is accumulated per kill, and text prompts show up for special kills (E.g.as #knife,
## reflect kills). To exit any part of the game, close the game window. Have fun!
#
resx,resy = 1280,720 #resolution size
cx,cy = resx//2,resy//2 #center coordinates, also half size of resolution
#The above actually change (ssshhhh dont tell anyone!) but they arent constantly
#changing. The only reason they are priviledged to be here is because they're
#needed in the next line :P
screen=display.set_mode((resx,resy),HWSURFACE|DOUBLEBUF|RESIZABLE|FULLSCREEN)
#-------------------Functions For The Loading Screen--------------------
#--------------------------------------While Loading------------------------------
JezInc=image.load("Loading\\Jez Inc Logo.png")
#And=image.load("Loading\\and.png")
ShadowGames=image.load("Loading\\shadowLogo.png")
#HavePartnered=image.load("Loading\\Have Partnered.png")
JezMan=image.load("Loading\\JezMan Logo.png")
#ProgrammedIn=image.load("Loading\\programmed in.png")
#PythonLogo=image.load("Loading\\Python Logo.png")
#WithModulesFrom=image.load("Loading\\with modules from.png")
#PygameLogo=image.load("Loading\\Pygame Logo.png")
def fadeIn(surface,logo):
for i in range(255//10):
surface.blit(logo,(0,0))
layer=Surface((surface.get_width(),surface.get_height()))
layer.set_alpha(255-i*10)
surface.blit(layer,(0,0))
display.flip()
def fadeOut(surface,logo):
for i in range(255//10):
surface.blit(logo,(0,0))
layer=Surface((surface.get_width(),surface.get_height()))
layer.set_alpha(i*10)
surface.blit(layer,(0,0))
display.flip()
#---------------------------------------------------------------------------------
fadeIn(screen,JezInc)
#time.wait(10)
#fadeOut(screen,JezInc)
#fadeIn(screen,And)
#time.wait(10)
#fadeOut(screen,And)
#fadeIn(screen,ShadowGames)
#time.wait(10)
#fadeOut(screen,ShadowGames)
#fadeIn(screen,HavePartnered)
#time.wait(10)
#fadeOut(screen,HavePartnered)
#fadeIn(screen,JezMan)
#time.wait(10)
#fadeOut(screen,JezMan)
#fadeIn(screen,ProgrammedIn)
#time.wait(10)
#fadeOut(screen,ProgrammedIn)
#fadeIn(screen,PythonLogo)
#time.wait(10)
#fadeOut(screen,PythonLogo)
#fadeIn(screen,WithModulesFrom)
#time.wait(10)
#fadeOut(screen,WithModulesFrom)
#fadeIn(screen,PygameLogo)
#time.wait(10)
#fadeOut(screen,PygameLogo)
#----------------------------------------------Controls Screen----------------------------
gameMap=image.load("Game Maps\Game Map.png").convert()
curPos=(1180,2450)
direction="North"
WASDkeys=image.load("Controls Screen\wasd keys.png")
RIGHTclick=image.load("Controls Screen\\right click.png")
RIGHTclick=transform.scale(RIGHTclick,(RIGHTclick.get_width()*2,RIGHTclick.get_height()*2))
LEFTclick=image.load("Controls Screen\\left click.png")
LEFTclick=transform.scale(LEFTclick,(LEFTclick.get_width()*2,LEFTclick.get_height()*2))
scroll=image.load("Controls Screen\\scroll.png")
scroll=transform.scale(scroll,(scroll.get_width()*2,scroll.get_height()*2))
pressScroll=image.load("Controls Screen\\press scroll button.png")
pressScroll=transform.scale(pressScroll,(pressScroll.get_width()*2,pressScroll.get_height()*2))
font.init()
textFont=font.SysFont("impact",30)
myClock=time.Clock()
def HelpScreen(screen,gameMap,curPos,direction,WASDkeys,
RIGHTclick,LEFTclick,scroll,pressScroll,myClock,textFont):
count=0
fps=0
fpsList=[]
helping=True
LEFTCLICK=textFont.render("LEFT CLICK:",True,(255,255,255))
SHOOT=textFont.render("shoot",True,(255,255,255))
SCROLL=textFont.render("SCROLL:",True,(255,255,255))
CHANGEWEP=textFont.render("swap weapon",True,(255,255,255))
RIGHTCLICK=textFont.render("RIGHT CLICK:",True,(255,255,255))
MELEE=textFont.render("secondary attack",True,(255,255,255))
PRESSSCROLL=textFont.render("CLICK SCROLL",True,(255,255,255))
CHANGEMELEE=textFont.render("change melee weapon",True,(255,255,255))
while helping:
for e in event.get():
if e.type==QUIT or (e.type == KEYDOWN and e.key == K_ESCAPE):
helping=False
#---Conditions to change current direction---
if curPos[1]<1175:
direction="East"
curPos=(curPos[0],curPos[1]+2)
elif curPos[0]>2350:
direction="South"
curPos=(curPos[0]-2,curPos[1])
elif curPos[1]>3840:
direction="West"
curPos=(curPos[0],curPos[1]-2)
elif curPos[0]<1170:
direction="North"
curPos=(curPos[0]+2,curPos[1])
curScreen=gameMap.subsurface((curPos[0]-screen.get_width()//2, #section of map currently viewed on screen
curPos[1]-screen.get_height()//2, screen.get_width(),screen.get_height())).copy()
screen.blit(curScreen,(0,0))
cover=Surface((screen.get_width(),screen.get_height()))
cover.set_alpha(50)
screen.blit(cover,(0,0))
screen.blit(WASDkeys,(0,0))
screen.blit(LEFTCLICK,(0,screen.get_height()-LEFTclick.get_height()-SHOOT.get_height()-LEFTCLICK.get_height()))
screen.blit(SHOOT,(0,screen.get_height()-LEFTclick.get_height()-SHOOT.get_height()))
screen.blit(LEFTclick,(0,screen.get_height()-LEFTclick.get_height()))
screen.blit(SCROLL,(LEFTclick.get_width(),screen.get_height()-scroll.get_height()-SCROLL.get_height()-CHANGEWEP.get_height()))
screen.blit(CHANGEWEP,(LEFTclick.get_width(),screen.get_height()-scroll.get_height()-CHANGEWEP.get_height()))
screen.blit(scroll,(LEFTclick.get_width(),screen.get_height()-scroll.get_height()))
screen.blit(RIGHTCLICK,(LEFTclick.get_width()+scroll.get_width(),screen.get_height()-RIGHTclick.get_height()-RIGHTCLICK.get_height()-MELEE.get_height()))
screen.blit(MELEE,(LEFTclick.get_width()+scroll.get_width(),screen.get_height()-RIGHTclick.get_height()-RIGHTCLICK.get_height()))
screen.blit(RIGHTclick,(LEFTclick.get_width()+scroll.get_width(),screen.get_height()-RIGHTclick.get_height()))
screen.blit(PRESSSCROLL,(LEFTclick.get_width()+scroll.get_width()+RIGHTclick.get_width(),screen.get_height()-pressScroll.get_height()-PRESSSCROLL.get_height()-CHANGEMELEE.get_height()))
screen.blit(MELEE,(LEFTclick.get_width()+scroll.get_width()+RIGHTclick.get_width(),screen.get_height()-pressScroll.get_height()-PRESSSCROLL.get_height()))
screen.blit(pressScroll,(LEFTclick.get_width()+scroll.get_width()+RIGHTclick.get_width(),screen.get_height()-pressScroll.get_height()))
if direction=="North":
curPos=(curPos[0],curPos[1]-2)
elif direction=="East":
curPos=(curPos[0]+2,curPos[1])
elif direction=="South":
curPos=(curPos[0],curPos[1]+2)
elif direction=="West":
curPos=(curPos[0]-2,curPos[1])
myClock.tick(60)
display.flip()
#----------------------------------------------END----------------------------------------
#------------------------------------------MENU SCREEN------------------------------------
menuPage=image.load("Menu Page.png")
gun=image.load("Gun_Pointing.png")
font.init()
play=font.SysFont("impact",75).render("PLAY",True,(150,150,150))
playClicked=font.SysFont("impact",75).render("PLAY",True,(255,255,255))
playRect=Rect(screen.get_width()//2-play.get_width()//2,screen.get_height()//2,play.get_width(),
play.get_height())
playList=(play,playClicked,playRect)
controls=font.SysFont("impact",75).render("CONTROLS",True,(150,150,150))
controlsClicked=font.SysFont("impact",75).render("CONTROLS",True,(255,255,255))
controlsRect=Rect(screen.get_width()//2-controls.get_width()//2,
screen.get_height()//2+play.get_height(),controls.get_width(),
controls.get_height())
controlsList=(controls,controlsClicked,controlsRect)
credit=font.SysFont("impact",75).render("CREDITS",True,(150,150,150))
creditsClicked=font.SysFont("impact",75).render("CREDITS",True,(255,255,255))
creditsRect=Rect(screen.get_width()//2-credit.get_width()//2,screen.get_height()//2+play.get_height()+controls.get_height(),credit.get_width(),
credit.get_height())
creditsList=(credit,creditsClicked,creditsRect)
htp=font.SysFont("impact",75).render("HOW TO PLAY",True,(150,150,150))
htpClicked=font.SysFont("impact",75).render("HOW TO PLAY",True,(255,255,255))
htpRect=Rect(screen.get_width()//2-htp.get_width()//2,screen.get_height()//2+play.get_height()+controls.get_height()+credit.get_height(),htp.get_width(),
htp.get_height())
htpList=[htp,htpClicked,htpRect]
optionsList=[playList,controlsList,creditsList,htpList]
class Menu:
def __init__(self):
self.lineList=[]
def addLine(self,screen):
length=randint(1,25)
ang=randint(0,360)
speed=randint(1,10)
self.lineList.append(((screen.get_width()//2+cos(radians(ang))*length,
screen.get_height()//2-sin(radians(ang))*length),
(screen.get_width()//2,screen.get_height()//2),
length,ang,speed))
def move(self,screen):
removeList=[]
for i in range(len(self.lineList)):
startX=self.lineList[i][0][0]
startY=self.lineList[i][0][1]
endX=self.lineList[i][1][0]
endY=self.lineList[i][1][1]
length=self.lineList[i][2]
ang=self.lineList[i][3]
speed=self.lineList[i][4]
self.lineList[i]=(((startX+cos(radians(ang))*speed,
startY-sin(radians(ang))*speed),
(endX+cos(radians(ang))*speed,
endY-sin(radians(ang))*speed),
length,ang,speed))
if self.lineList[i][0][0]<0 or self.lineList[i][0][0]>screen.get_width():
removeList.append(self.lineList[i])
elif self.lineList[i][0][1]<0 or self.lineList[i][0][1]>screen.get_height():
removeList.append(self.lineList[i])
for item in removeList:
self.lineList.remove(item)
def draw(self,screen):
for line in self.lineList:
draw.line(screen,(255,0,0),line[0],line[1],3)
def drawOptions(screen,optionsList,mx,my):
for option in optionsList:
if option[2].collidepoint((mx,my)):
screen.blit(option[0],(option[2][0],option[2][1]))
else :
screen.blit(option[1],(option[2][0],option[2][1]))
#-------------------------------------------------------------------------------------------
fadeOut(screen,JezInc)
fadeIn(screen,ShadowGames)
#----------------------------------------HOW TO PLAY----------------------------------------
howToPlayImg=image.load("how to play.png")
def howToPlay(screen,gun,howToPlayImg):
showingHowToPlay=True
back=Menu()
while showingHowToPlay:
for e in event.get():
if e.type==QUIT or (e.type == KEYDOWN and e.key == K_ESCAPE):
showingHowToPlay=False
screen.fill((0,0,0))
screen.blit(gun,(335,272))
menu.addLine(screen)
menu.move(screen)
menu.draw(screen)
screen.blit(transform.scale(howToPlayImg,(screen.get_width(),screen.get_height())),(0,0))
display.flip()
#---------------------------------------CREDITS---------------------------------------------
creditsFile=open("credits.txt","r")
creditsList=creditsFile.read().split("\n")
def displayCredits(screen,gun,creditsList):
displaying=True
creditsFontHeight=50
creditsFontCol=(0,0,255)
creditsFont=font.SysFont("impact",creditsFontHeight)
back=Menu()
while displaying:
for e in event.get():
if e.type==QUIT or (e.type == KEYDOWN and e.key == K_ESCAPE):
displaying=False
screen.fill((0,0,0))
screen.blit(gun,(335,272))
menu.addLine(screen)
menu.move(screen)
menu.draw(screen)
for i in range(len(creditsList)):
text=creditsFont.render(creditsList[i],True,creditsFontCol)
screen.blit(text,(screen.get_width()//2-text.get_width()//2,50*i+10*i))
display.flip()
count=0
fps=0
fpsList=[]
running=True
menu=Menu()
myClock=time.Clock()
#---------------------VARIABLES THAT DO NOT CHANGE----------------------
font.init()
#---weapons---
#contains all weapon information
#(weapon image names (idle and firing), number of bullets fired per shot,rate of fire (the lower it is,
#the faster the gun shoots), damage per bullet, gun level)
weapons = [((image.load('Player\m161.png'),image.load('Player\m162.png')),1,10,10,1),
((image.load('Player\pistol1.png'),image.load('Player\pistol2.png')),1,30,20,1),
((image.load('Player\shotgun1.png'),image.load('Player\shotgun2.png')),5,60,15,1),
((image.load('Player\dualPistols1.png'),image.load('Player\dualPistols2.png')),2,30,20,1)]
#((image.load("pistol1.png"),image.load("pistol2.png"),1,30,20)]
#---Creating the lists of the reloading images---
#shotgun reloading sprites:
shotgunReload=[]
for i in range(6):
shotgunReload.append(image.load("Player\shotgunR%d.png"%(i+1)))
shotgunReload=tuple(shotgunReload) #tuples are cooler
#M16 reloading sprites:
M16Reload=[]
for i in range(6):
M16Reload.append(image.load("Player\m16R%d.png"%(i+1)))
M16Reload=tuple(M16Reload) #tuples are cooler
#Pistol reloading sprites:
pistolReload=[]
for i in range(3):
pistolReload.append(image.load("Player\pistolR%d.png"%(i+1)))
pistolReload=tuple(pistolReload) #tuples are cooler
#Dual pistol reloading sprites:
DPReload=[]
for i in range(6):
DPReload.append(image.load("Player\dualPistolsR%d.png"%(i+1)))
DPReload=tuple(DPReload) #tuples are cooler
#list of reloading lists:
reloadList=[M16Reload,pistolReload,shotgunReload,DPReload]
#---
meleeList = [('grenade',[image.load('Player\grenade1.png'),image.load('Player\grenade2.png'),
image.load('Player\grenade3.png'),image.load('Player\grenade4.png'),
image.load('Player\grenadeT1.png'),image.load('Player\grenadeT2.png'),])]
sprites = []
for i in range(6):
sprites.append(image.load('Player\knife%d.png'%i))
meleeList.append(sprites)
meleeList[1] = ('knife',meleeList[1])
explosions = glob.glob('Player\Explosion\*.png')
explosions.sort()
texts = [(image.load('Text/attractHit0.png'),image.load('Text/attractHit1.png')),(image.load('Text/ricoshot0.png'),
image.load('Text/ricoshot1.png')),(image.load('Text/knifed0.png'),image.load('Text/knifed1.png')),
(image.load('Text/nuked0.png'),image.load('Text/nuked1.png'))]
#loads texts prompt images when kills are initiated
clip = 1000 #starting number of bullets of each clip
bLen = 20 #bullet length
bWid = 7 #bullet width
#dynamicView = True #setting for if dynamic view is turned on/off (will finish if we have time)
viewDelay = 8 #reduction of aim sensitivity
myClock = time.Clock()
peacefulSprites=[(image.load("Civilians\peaceful AI-1.png"),image.load("Civilians\peaceful AI-1-shot.png"))]
#list of images for peaceful ai sprites
maxCoinDrop=101 #the most $ that an AI can drop
minCoinDrop=1 #the least $ that an AI can drop
fadeSpeed=2 #speed at which onscreen info about pickups fade away
slowMoTime = 7 #number of seconds slow motion is active per use
minSpeed = 1 #lowest speed allowed for object/player/enemy movement in slow motion
defaultBSpeed = 20 #default bullet speed
grenadeDistPerc = 7 #percentage of wanted distance already traveled on first bounce divided by 10
grenadeSpeedCutback = 2 #grenade speed is reduce by this number on second bounce
lenPerks=30 #the length of time that the perks will last for
knifePts = 90 #points awarded to score for knife, regular bullet, homing bullet, reflecting bullet, grenade kill
bulletPts = 40
homingPts = 60
reflectPts = 80
grenadePts = 50
killDeduc = 100 #points deducted from score for killing/not saving civilian
invincibleSec = 3 #number of seconds player is invincible after hit
invincibleCount = 0 #counter to keep track of invinciblity timer
enemySpritesPistol=[] #list on enemy sprites that carry a pistol
gunNames=["M16","Pistol","Shotgun","Pistol"] #names of guns
totalPlayerHealth=200
for i in range(3):
enemySpritesPistol.append((image.load("Enemies\e%sPistols1.png"%(str(i+1))),
image.load("Enemies\e%sPistols2.png"%(str(i+1)))))
enemySpritesM16=[]
for i in range(3):
enemySpritesM16.append((image.load("Enemies\e%sm161.png"%(str(i+1))),
image.load("Enemies\e%sm162.png"%(str(i+1)))))
enemySpritesShotgun=[]
for i in range(3):
enemySpritesShotgun.append((image.load("Enemies\e%sshotgun1.png"%(str(i+1))),
image.load("Enemies\e%sshotgun2.png"%(str(i+1)))))
letterGrades = ['DEMOLITIONIST','CUTTTHROAT','BARBARIAN','ASSASSIN','SUPER-HITMAN']
ratingReq = [0,100,250,500,800] #list of letter grades the player can acquire minimum current score required for each
#---Shooter AI Constants---
#for each weapon list : [number of bullets per shot,rate of fire,damage per bullet]
pistol=[1,60,20,enemySpritesPistol]
m16=[1,10,15,enemySpritesM16]
shotgun=[5,60,10,enemySpritesShotgun]
weaponsAI=[m16,pistol,shotgun]
AIammo=100
shooterHealth=100
magazine=image.load("ammo magazine.png")
#---player constants---
knifeDmg = 5 #damage X 12 used per swipe
playerHealth = 200 #default player health
#---HUD---
HUDimgHeight=50
shotgunHUD=image.load("Shotgun HUD.png")
shotgunHUD=transform.scale(shotgunHUD,(shotgunHUD.get_width()//shotgunHUD.get_height()*HUDimgHeight,HUDimgHeight))
M16HUD=image.load("M16 HUD.png")
M16HUD=transform.scale(M16HUD,(M16HUD.get_width()//M16HUD.get_height()*HUDimgHeight,HUDimgHeight))
pistolHUD=image.load("Pistol HUD.png")
pistolHUD=transform.scale(pistolHUD,(pistolHUD.get_width()//pistolHUD.get_height()*HUDimgHeight,HUDimgHeight))
HUDList=[M16HUD,pistolHUD,shotgunHUD,pistolHUD]
secHUDimgHeight=40
knifeHUD=image.load("knife HUD.png")
knifeHUD=transform.scale(knifeHUD,(knifeHUD.get_width()//knifeHUD.get_height()*secHUDimgHeight,secHUDimgHeight))
grenadeHUD=image.load("grenade HUD.png")
grenadeHUD=transform.scale(grenadeHUD,(int(grenadeHUD.get_width()/grenadeHUD.get_height()*secHUDimgHeight),secHUDimgHeight))
secHUDlist=[grenadeHUD,knifeHUD]
healthImg = image.load('health.png')
crosshair = transform.scale(image.load('crosshair.png'),(100,100))
fadeOut(screen,ShadowGames)
fadeIn(screen,JezMan)
#-------------------------VARIABLES THAT CAN CHANGE------------------------
running = True #flag for if program is running
count = 0
fps = 0
fpsList = []
playerSpeed = 5 #movement speed of player and AIs (same speed) (changes in slow motion)
grenadeSpeed = playerSpeed*11 #travelling speed of grenade
sprSpeed = 0.5 #speed of melee attacks
reloadingSpeed = 0.1 #speed of reloading
AIspeed = playerSpeed #enemy ai speed
civSpeed = 2 #civilian speed
bSpeed = 20 #bullet speed
w = 1 #selected weapon can change by changing this variable / start with pistol
n = 1 #selected secondary weapon can change by changing this variable
weapon = weapons[w] #selected weapon inside weapon list
bulletList = [] #list of active bullets in play in the game
shot = False #flag checking if player is currently shooting
bCol = (218,165,32)
bRicochet=False
reflects=1
delay = 0 #counter keeping track of current frame number (0-29)
secDelay = 0 #counter for secondary weapon sprites
grenadeDelay = 0 #counter for grenade image sprites
grenadeDefDist = 300 #longest length of grenade throw
grenadeAng = 0 #angle grenade travels at
grenadeRot = 0 #grenade image default rotation
grenadeFuse = 3 #number of seconds grenade takes to blow up
explosionSpr = image.load(explosions[0]) #default explosion sprite
blastRad = 200 #grenade blast radius
impactTime = False #moment when grenade damage is applied
explosion = False
grenadeIdle = False #flag for if grenade is idle on ground
grenade2 = False #flag for second bounce of grenade
throw = False #flag for if grenade is thrown or not
grenx = 0 #default coordinates of grenade
greny = 0
grenDmg = 1.5 #max grenade damage (itself multiplied by grenade damage radius) at the centre of grenade explosion
peacefulAIList=[] #list of active civilians on screen
civHealth = 100
cur_x = 0 #default player coordinates in accordance to map
cur_y = 0
coinList=[] #the positions of dropped money by AIs and how much each is worth
money=0 #the amount of money that the player has
collectedCoinList=[] #list of coins that have been collected
#purpose is to display the amount for a little while after it has been collected
melSpr = image.load('Player\knife1.png') #default melee sprite
secondary = False #flag for if player is using secondary weapon or not
knife = False #flag for if player is knifing or not
dmgTip = (0,0) #default melee knife tip used for damage
deadList=[]
shooterAIList=[]
droppedClipList=[] #the list of ammo clips dropped by dead enemies
collectedClipList=[] #the list of ammo clips collected by the player
imgList=[] #the list of enemy coordinates killed different attack
para = False #flag for slow motion and counter used for parabola
grenade = False #flag for if grenade is thrown for the first time or not
c = -1 #counter for bullet time
totalScore = 0
score = 0
scoreMultiplier = 1
exploded = True #flag for if last grenade has exploded or not
#knifePrompt = False #flags for if a unique kill was executed (used to blit prompt messages onto killed people)
reflectPrompt = False
homePrompt =False
grenadePrompt = False
gameCountdown=10 #seconds left before the game starts
enemyHealth=20 #the enemy's health, changes every wave
#---gun ammo---
M16ammo=20
M16clip=20
pistolammo=12
pistolclip=12
DPammo=12
DPclip=24
shotgunammo=50
shotgunclip=50
reloadingFrame=0
hasReloaded=True
reloading=False
ammoList=[M16ammo,pistolammo,shotgunammo,DPammo]
clipList=[M16clip,pistolclip,shotgunclip,DPclip]
#---------------------------------FONT--------------------------------------
#---money---
moneyFontHeight=50
moneyFontCol=(0,255,0)
moneyFont=font.SysFont("impact",moneyFontHeight)
#---collected coin text---
collectedCoinFontHeight=40
collectedCoinFontCol=(255,255,0)
collectedCoinFont=font.SysFont("impact",collectedCoinFontHeight)
#---text blitted when u are near enough to enter the gun store---
enterFontHeight=60
enterFontCol=(0,0,255)
enterFont=font.SysFont("impact",enterFontHeight)
enterText=enterFont.render("E to enter",True,enterFontCol)
#---blitting ammo left in clip---
ammoInClipFontHeight=50
ammoInClipFontCol=(255,255,255)
ammoInClipFont=font.SysFont("impact",ammoInClipFontHeight)
ammoInClipFontDict={"col":ammoInClipFontCol,"font":ammoInClipFont}
#---total ammo---
ammoFontHeight=30
ammoFontCol=(255,255,255)
ammoFont=font.SysFont("impact",ammoFontHeight)
ammoFontDict={"col":ammoFontCol,"font":ammoFont}
#---collected clips text---
collectedClipFontHeight=40
collectedClipFontCol=(255,255,255)
collectedClipFont=font.SysFont("impact",collectedClipFontHeight)
collectedClipFontDict={"col":collectedClipFontCol,"font":collectedClipFont}
#---Timer font---
timerFontHeight=75
timerFontCol=(0,0,255)
timerFont=font.SysFont("impact",timerFontHeight)
#---Countdown Font---
countdownFontHeight=200
countdownFontCol=(200,0,0)
countdownFont=font.Font("youmurdererbb_reg.otf",countdownFontHeight)
#---Wave Number font---
waveFontHeight=100
waveFontCol=(200,0,0)
waveFont=font.Font("youmurdererbb_reg.otf",waveFontHeight)
#----------------------------------MAP--------------------------------------
#loads all map images
collide=image.load("Game Maps\Collide Check.png").convert()
horizontal = image.load("Game Maps\Horizontal Check.png").convert()
#top=image.load("Top of Map.png")
#bottom=image.load("Background of Map.png").convert_alpha()
gameMap=image.load("Game Maps\Game Map.png").convert()
#gameMapCopy=gameMap.copy()
coin=image.load("Coin.png")
#"""
gunStoreImg=image.load("Game Maps\Gun store.png").convert() #the actual gun store img
width=gunStoreImg.get_width()+screen.get_width()
height=gunStoreImg.get_height()+screen.get_height()
gunStore=Surface((width,height)) #actual surface that the player will see
#larger than actual img because if the player is in a corner, they can see outside the actual
#image
gunStore.fill((0,0,0))
gunStore.blit(gunStoreImg,(screen.get_width()//2,screen.get_height()//2))
gunStoreCollideImg=image.load("Game Maps\Gun store collide check.png").convert() #the actual gun store img
gunStoreCollide=Surface((width,height)) #will see
#larger than actual img because if the player is in a corner, they can see outside the actual
#image
gunStoreCollide.fill((0,0,0))
gunStoreCollide.blit(gunStoreCollideImg,(screen.get_width()//2,screen.get_height()//2))
#"""
#---------------------------------SOUNDS------------------------------------
mixer.init()
m16Sound="Sounds\Assault Rifle.wav" #sound filenames
shotgunSound="Sounds\Old School Shotgun.wav"
pistolSound="Sounds\Pistol.wav"
weaponSounds=[m16Sound,pistolSound,shotgunSound,pistolSound] #list of gun sounds to be used
mixer.music.load(weaponSounds[w]) #mixer.Sound doesnt work well in the setting of our game for our bullets
#so we use mixer.music instead
#--------------------------------MUSIC--------------------------------------
farKid=mixer.Sound("Music\Youre Gonna Go Far Kid.ogg") #the music files
solarisPhase=mixer.Sound("Music\Solaris Phase 2.ogg")
somethingDifferent=mixer.Sound("Music\\03 Something Different.ogg")
highScore=mixer.Sound("Music\High Score.ogg")
hisWorld=mixer.Sound("Music\His World.ogg")
musicList=[(farKid,farKid.get_length()),
(solarisPhase,solarisPhase.get_length()),
(somethingDifferent,somethingDifferent.get_length()),
(highScore,highScore.get_length()),
(hisWorld,hisWorld.get_length())] #the list containing the music files and their lengths
curSong=choice(musicList) #chooses a random song to play
curSong[0].play()
secondsPlayed=0 #the number of seconds that the song has been played for
#----------------------------------TIMER------------------------------------
time.set_timer(USEREVENT+1,1000) #creates an event that goes off every second
#---Reflecting Bullets---
reflectingCount=0
reflectingBullets=True #the flag for if the player has purchased reflecting bullets or not
reflectingBulletList=[]
reflectingBulletSpeed=bSpeed
#---Homing Bullets---
homingCount=0
homingBullets=False #if the bullets should home towards enemies because the player bought the perk
homingBulletList=[]
homingBulletSpeed=bSpeed//3
fadeOut(screen,JezMan)
#---------------------------------CLASSES-----------------------------------
class Player:
'''Player keeps track of:
x,y - current position
ang - current angle the Player is facing in degrees
pic1 - sprite to display when not moving
pic2 - sprite to alternate to when firing
fire - flag for if the player is shooting
money - the amount of money they start off with
'''
def __init__(self,x,y,ang,pic1,pic2,money,health,reloadSpeed=0,reloadingSprites=None,ammo=0,clipSize=1,reloadingFrame=0,
reloading=False,hasReloaded=True):
self.x = x
self.y = y
self.ang = ang
self.pic1 = pic1
self.pic2 = pic2
self.fire = False
self.money=money
self.reloadingSprites=reloadingSprites
self.reloading=reloading
self.reloadingFrame=reloadingFrame
self.reloadSpeed = reloadSpeed
self.ammo=ammo
self.clipSize=clipSize
self.hasReloaded=hasReloaded
self.ammoInClip=self.ammo%self.clipSize
self.health = health
#print(len(self.reloadingSprites))
def weaponChange(self,pic1,pic2,reloadingSprites,ammo,clipSize):
self.pic1=pic1
self.pic2=pic2
self.reloadingSprites=reloadingSprites
self.reloading=False
self.hasReloaded=True
self.reloadingFrame=0
self.ammo=ammo
self.clipSize=clipSize
self.ammoInClip=self.ammo%self.clipSize
def rotate(self,destX,destY,hScreenX,hScreenY):
'''Player angle changes based on mouse coordinates'''
moveX = destX - hScreenX
moveY = destY - hScreenY
self.ang = degrees(atan2(-moveY, moveX))
def collectMoney(self,coinList,coin,collectedCoinList):
"""Checks to see if the player comes in contact with any coins laying on the ground
If he does then he picks them up (obviously)"""
for curCoin in coinList:
if distance((player.x,player.y),curCoin[0])<=coin.get_width()//2+40: #width and height of coin are ==
player.money+=curCoin[1] #the players money total increases based on the coins amount
collectedCoinList.append((curCoin[0],curCoin[1],255)) #255 is the alpha that it
#will be blitted at
for c in collectedCoinList:
try :
coinList.remove((c[0],c[1])) #removes the collected coins
except ValueError: pass #occurs if the item has already been erased
def collectAmmo(self,droppedClipList,collectedClipList,ammoList,w):
"Collects any ammo if the player walks over any dropped magazines"
ammoList[w]=self.ammo #updates ammoList
if w==1:
ammoList[3]=self.ammo
elif w==3:
ammoList[1]=self.ammo
for clip in droppedClipList: #for every clip on the ground
if distance((player.x,player.y),clip[0])<=60: #if the player is pretty close to it
ammoList[clip[2]]+=clip[1] #bullets added to total
collectedClipList.append((clip[0],clip[1],clip[2],255))
self.reloading=False
self.hasReloaded=True
self.reloadingFrame=0
for c in collectedClipList: #removes collected magazines
#print(c)
for i in range(361):
try:
droppedClipList.remove((c[0],c[1],c[2],i))
except ValueError: pass
self.ammo=ammoList[w] #updates player's ammo info
self.ammoInClip=self.ammo%self.clipSize
if w==3 and self.ammo%2!=0: #if the player has dual pistols
#and they collected an odd number of bullet
self.ammo-=1 #makes it even
def draw(self,surface,delay,mb,secondary,meleeDelay,secWeap,meleeSprite,mx,my,cx,cy,damagedCount):
'''Player is rotated/drawn based on angle coordinates. If he is
shooting, the sprite drawn alternates between the idle and firing
sprites (pic1 and pic2)'''
#self.rotate(mx,my,cx,cy)
#print(self.ang)
if self.ammo%self.clipSize==0 and self.hasReloaded==False and self.ammo>0: #if a clip is empty and hasnt been reloaded yet
self.reloading=True
if self.ammo%self.clipSize!=0: #if it doesnt need to be reloaded
self.hasReloaded=False
if self.hasReloaded: #if it has been reloaded it doesnt need to reload anymore
self.reloading=False
if self.hasReloaded==True and self.ammoInClip==0 and self.ammo>0:
self.ammoInClip=self.clipSize
#print(self.ammo)
if damagedCount > 0 and damagedCount%20 == 0:
pass
else:
if self.reloading==True: #if its reloading
newpic=transform.rotate(self.reloadingSprites[int(self.reloadingFrame)],self.ang+270)
surface.blit(newpic,getCentre(newpic,surface.get_width()//2,surface.get_height()//2))
self.reloadingFrame += self.reloadSpeed #slows the speed at which the reloading frames are cycled through
if self.reloadingFrame>len(self.reloadingSprites):
self.reloadingFrame=0
self.hasReloaded=True #done reloading
else:
if secondary:
if secWeap == 'knife' or secWeap == 'grenade':
newPic = transform.rotate(meleeSprite,self.ang+270)
else:
if mb[0]==1 and delay % weapon[2] == 0 or mb[0]==1 and (delay-1) % weapon[2] == 0 or mb[0]==1 and (delay-2) % weapon[2] == 0:
newPic = transform.rotate(self.pic2,self.ang+270)
else:
newPic = transform.rotate(self.pic1,self.ang+270)
surface.blit(newPic,getCentre(newPic,surface.get_width()//2,surface.get_height()//2))
class Bullet:
'''Bullet keeps track of:
ex,ey - current end position
tx,ty - current tip position
ang - current angle bullet is going from player when it was shot in radians
damage - the amount of damage that a bullet deals
'''
def __init__(self,ex,ey,tx,ty,ang,damage):
self.ex = ex
self.ey = ey
self.tx = tx
self.ty = ty
self.ang = ang
self.damage=damage
def move(self,speed,length):
'''finds the bullet end's and tip's next coordinates by using trig and
the set distance and length of the bullet (which can be changed easily)'''
self.ex, self.ey = self.tx + cos(self.ang) * (speed-length), self.ty - sin(self.ang) * (speed-length)
self.tx, self.ty = self.tx + cos(self.ang) * speed, self.ty - sin(self.ang) * speed
def draw(self,surface,player,width,bulCol):
'''draws bullet using it's end and tip coordinates'''
if fitOnscreen(surface,(player.x,player.y),(self.tx,self.ty)):
new_tx=surface.get_width()//2-(player.x-self.tx)
new_ex=surface.get_width()//2-(player.x-self.ex)
new_ty=surface.get_height()//2-(player.y-self.ty)
new_ey=surface.get_height()//2-(player.y-self.ey)
draw.line(surface,bulCol,(new_tx,new_ty),(new_ex,new_ey),width)
class ReflectingBullet(Bullet):
def __init__(self,ex,ey,tx,ty,ang,damage,reflects):
self.ex = ex
self.ey = ey
self.tx = tx
self.ty = ty
self.ang = ang
self.damage=damage
self.reflects=reflects
self.reflectNum=0
class HomingBullet:
"""Class of bullets that reflect once, this perk can be bought in the gun store and only affects the player's bullets"""
def __init__(self,ex,ey,tx,ty,ang,damage):
"""ex,ey - current end position
tx,ty - current tip position
ang - current angle bullet is going from player when it was shot in degrees
damage - the amount of damage that a bullet deals
"""
self.ex = ex
self.ey = ey
self.tx = tx
self.ty = ty
self.ang = ang
self.damage=damage
#self.hasTarget=False
def selectTarget(self,AIList):
"""Chooses which target it wants to b-line towards, preferably the closest one"""
distList=[]
for ai in AIList:
dist=distance((ai.x,ai.y),(self.tx,self.ty))
distList.append(dist)
self.targetX=AIList[distList.index(min(distList))].x
self.targetY=AIList[distList.index(min(distList))].y
def home(self,speed,bLen):
"""
"""
dist=max(1,distance((self.tx, self.ty),(self.targetX, self.targetY)))
moveX = (self.targetX - self.tx)*speed/dist
moveY = (self.targetY - self.ty)*speed/dist
self.ang = degrees(atan2(-moveY, moveX))
self.tx+=moveX
self.ty+=moveY
self.ex=self.tx+bLen*cos(radians(self.ang))
self.ey=self.ty-bLen*sin(radians(self.ang))
def draw(self,surface,player,width,bulCol):
if fitOnscreen(surface,(player.x,player.y),(self.tx,self.ty)):
new_tx=surface.get_width()//2-(player.x-self.tx)
new_ex=surface.get_width()//2-(player.x-self.ex)
new_ty=surface.get_height()//2-(player.y-self.ty)
new_ey=surface.get_height()//2-(player.y-self.ey)
draw.line(surface,bulCol,(new_tx,new_ty),(new_ex,new_ey),width)
class peacefulAI:
"""The peaceful AI keeps track of:
x,y - current position
sprite - sprite of the AI
direction - direction headed (North, East, South, West or None if stationary)
health - current amount of health
maxHealth - default amount of starting health
money - the amount of money that they are carrying
shot - whether they have just been shot
count - serves as a count for when the ai is hit to display the shot sprite
"""
def __init__(self,x,y,sprites,direction,health,money):
self.x=x
self.y=y
self.direction=direction
self.sprite=sprites[0] #the original sprite
self.spriteShot=sprites[1]
self.rotated=self.sprite #self.sprite in its rotated form
self.rotatedShot=self.spriteShot
self.health=health
self.maxHealth=health #the amount of health they start off with
self.money=money
self.shot=False
self.count=0
def move(self,speed):
"""Moves the civilian
There is a 4 in 250 chance that the AI will change directions
the remaining chance will make the AI continue in the same direction
"""
num=randint(1,250)
directions = ['North','East','South','West','None']
for i in range(5):
if num-1 == i:
self.direction = directions[i]
if self.direction=="North" and collide.get_at((self.x,self.y-2))[:3]!=(0,0,0):
self.y -= speed #moves AI in set direction if possible
elif self.direction=="East" and collide.get_at((self.x+2,self.y))[:3]!=(0,0,0):
self.x += speed
elif self.direction=="South" and collide.get_at((self.x,self.y+2))[:3]!=(0,0,0):
self.y += speed
elif self.direction=="West" and collide.get_at((self.x-2,self.y))[:3]!=(0,0,0):
self.x -= speed
#---Rotation of sprite image for different directions---
if self.direction=="South" or self.direction=="None":
self.rotated=transform.rotate(self.sprite,0)
self.rotatedShot=transform.rotate(self.spriteShot,0)
elif self.direction=="East":
self.rotated=transform.rotate(self.sprite,90)
self.rotatedShot=transform.rotate(self.spriteShot,90)
elif self.direction=="North":
self.rotated=transform.rotate(self.sprite,180)
self.rotatedShot=transform.rotate(self.spriteShot,180)
elif self.direction=="West":
self.rotated=transform.rotate(self.sprite,270)
self.rotatedShot=transform.rotate(self.spriteShot,270)
def draw(self,surface,player):
"""
Blits the civilian onto the screen and draws health bar
"""
sx=surface.get_width()//2-(player.x-self.x) #x-coordinate relative to the screen
sy=surface.get_height()//2-(player.y-self.y) #y-coordinate relative to the screen
if self.shot==True: #if he is being shot
self.count+=0.2 #adds to the count
if self.count==1:
self.shot=False #if the shot sprite has been blitted for the correct
#number of frames, then it reverts to the original state
self.count=0
surface.blit(self.rotatedShot,getCentre(self.rotatedShot,sx,sy))
else :
surface.blit(self.rotated,getCentre(self.rotated,sx,sy))
width=int(self.rotated.get_width()/self.maxHealth*self.health) #width will be the
#same whether it is self.rotated of self.rotatedShot
height=10
col=(255-int(width*2.5),5+int(width*2.5),0)
draw.rect(surface,col,(sx-self.rotated.get_width()//2, #draws health bar
sy-self.rotated.get_height()//2-10,
width,height))
def rectangle(self):
"""
Returns the rectangular area that the sprite covers
Used for collision detection
"""
return Rect(self.x-self.rotated.get_width()//2,self.y-self.rotated.get_height()//2,
self.rotated.get_width(),self.rotated.get_height())
def reduceHealth(self,bulDamage):
'Reduces the AIs health based on how much damage the bullet deals'
self.health -= bulDamage
self.shot=True
class enemyShooter:
"""
This is the class for the AI enemies that shoot at the player
x - x coordinate of the enemy
y - y coordinate of the enemy
regSprite - sprite of the enemy when they are not shooting their gun
shootingSprite - sprite when they are shooting their gun
player - the class for the player
ang - the angle they are facing in degrees
dist - distance from the player
weapon - the weapon that they are carrying
rotatedReg/rotatedShoot - the rotated versions of the sprites
shot - if they are shooting or not
ammo - the amount of ammo they have