-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstar_wars_game.py
2319 lines (2319 loc) · 123 KB
/
star_wars_game.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 cmu_graphics import *
app.background = 'black'
app.hazardLst = []
app.level = 1
app.setMaxShapeCount(100000)
app.sizeMulti = 2
app.width = 400*app.sizeMulti
app.height = 400*app.sizeMulti
class Projectile:
lst = []
def __init__(self, rA, speed, power, harmShip, projectileType, *, piercing = 1):
self.rA = rA
self.speed = speed
self.previousSpeed = speed
self.power = power
self.piercing = piercing
self.harmShip = harmShip
self.type = projectileType
Projectile.lst.append(self)
if harmShip:
self.speed += app.score/1000
app.hazardLst.append(self)
# moves projectile
def move(self):
if self.shape.visible:
self.shape.centerX, self.shape.centerY = getPointInDir(self.shape.centerX, self.shape.centerY, self.rA, self.speed)
if not (self.shape.left > 400*app.sizeMulti or self.shape.right < 0 or self.shape.bottom < 0 or self.shape.top > 400*app.sizeMulti):
# collision
if not self.harmShip:
for e in EnemyShip.lst:
if self.shape.hitsShape(e.shape) and e.hp>0:
e.hp -= self.power*2-1
if self.piercing <= 1:
self.shape.visible = False
else:
self.piercing -= 1
else:
for s in Ship.lst:
if self.shape.hitsShape(s.shape):
if s.invTime <= 0:
s.invTime = 1
s.shields -= self.power
if self.piercing <= 1:
self.shape.visible = False
else:
self.piercing -= 1
if self.type != "ib":
for a in Asteroid.lst:
if self.shape.hitsShape(a.shape):
if a.shape.radius-self.power*2*app.sizeMulti <= 4*app.sizeMulti:
a.reset()
else:
a.shape.radius -= self.power*2*app.sizeMulti
if self.piercing <= 1:
self.shape.visible = False
else:
self.piercing -= 1
for b in Bomb.lst:
if self.shape.hitsShape(b.shape):
if self.type == "l":
if (not self.harmShip) or (self.harmShip and (not b.harmShip)):
if self.piercing <= 1:
self.shape.visible = False
else:
self.piercing -= 1
b.shape.visible = False
else:
if self.harmShip != b.harmShip:
self.shape.visible = False
b.shape.visible = False
else:
# removes object if off screen
removeObject(self)
else:
# removes object, does effect
removeObject(self)
self.effect()
def effect(self):
pass
class Laser(Projectile):
lst = []
def __init__(self, sX, sY, laserFill, speed, power, *, lW = 2*app.sizeMulti, length = 5*app.sizeMulti, rA = 90, harmShip = False, piercing = 1):
x2, y2 = getPointInDir(sX, sY, rA, length)
self.shape = Line(sX, sY, x2, y2, fill = laserFill, lineWidth = lW)
# calls Projectile constructor
super().__init__(rA, speed, power, harmShip, "l", piercing = piercing)
Laser.lst.append(self)
class Bomb(Projectile):
lst = []
def __init__(
self, sX, sY, speed, power, explosionPower, *, radius = 6*app.sizeMulti,
explosionSize = 35*app.sizeMulti, rA = 90, harmShip = False, bombFill = 'dimgray'
):
x2, y2 = getPointInDir(sX, sY, rA, radius)
self.shape = Circle(x2, y2, radius, fill = bombFill)
self.bombFill = bombFill
self.explosionPower = explosionPower
self.explosionSize = explosionSize
# calls Projectile constructor
super().__init__(rA, speed, power, harmShip, "b")
Bomb.lst.append(self)
# creates an explosion based on the Bomb's stats
def effect(self):
Explosion(self.shape.centerX, self.shape.centerY, self.explosionPower, size = self.explosionSize)
class ClusterBomb(Bomb):
def __init__(
self, sX, sY, speed, power, *, radius = 6*app.sizeMulti, rA = 90, harmShip = False, numBombs = 3, clusterBombExplosionSize = 15*app.sizeMulti,
bombFill = 'dimgray', clusterBombExplosionDamage = 2, recursions = 0
):
self.numBombs = numBombs
self.clusterBombExplosionSize = clusterBombExplosionSize
self.clusterBombExplosionDamage = clusterBombExplosionDamage
self.recursions = recursions
# calls Bomb constructor
super().__init__(
sX, sY, speed, power, 0, radius = radius, explosionSize = 1*app.sizeMulti,
rA = rA, harmShip = harmShip, bombFill = bombFill
)
# spawns bombs or more cluster bombs depending on how many rcrsns are left
def effect(self):
if self.recursions > 0:
for i in range(self.numBombs):
rotate = randrange(0, 360)
if self.numBombs-1 < 3:
self.numBombs = 4
sX, sY = getPointInDir(self.shape.centerX, self.shape.centerY, rotate, randrange(5, 15))
ClusterBomb(
sX, sY, int(self.speed/2)+1*app.sizeMulti, self.power*0.75, radius = int(self.shape.radius/2)+1*app.sizeMulti,
rA = rotate, harmShip = self.harmShip, numBombs = self.numBombs-1, recursions = self.recursions-1,
bombFill = self.bombFill, clusterBombExplosionSize = int(self.clusterBombExplosionSize*0.875)+1*app.sizeMulti,
clusterBombExplosionDamage = self.clusterBombExplosionDamage
)
else:
for i in range(self.numBombs):
rotate = randrange(0, 360)
sX, sY = getPointInDir(self.shape.centerX, self.shape.centerY, rotate, randrange(5, 15)*app.sizeMulti)
Bomb(
sX, sY, int(self.speed/2)+2.5*app.sizeMulti, self.power*0.75, self.clusterBombExplosionDamage, bombFill = self.bombFill,
radius = self.shape.radius/2, rA = rotate, explosionSize = self.clusterBombExplosionSize, harmShip = self.harmShip
)
class Explosion:
lst = []
def __init__(self, cX, cY, power, *, size = 15*app.sizeMulti):
self.shape = Circle(cX, cY, 1*app.sizeMulti, fill = gradient('yellow', 'gold', 'orange', 'orangered', 'red', 'crimson'))
self.power = power
self.size = size
Explosion.lst.append(self)
app.hazardLst.append(self)
def explode(self):
if self.shape.radius < self.size:
# expands Explosion, does collision
self.shape.radius += randrange(1, 4)*app.sizeMulti
for e in EnemyShip.lst:
if self.shape.hitsShape(e.shape):
e.hp -= self.power*1.5
for s in Ship.lst:
if self.shape.hitsShape(s.shape) and s.invTime <= 0:
s.shields -= self.power
s.invTime = 3
for a in Asteroid.lst:
if self.shape.hitsShape(a.shape):
if a.shape.radius-self.power*2*app.sizeMulti <= 4*app.sizeMulti:
a.reset()
else:
a.shape.radius -= self.power*2*app.sizeMulti
for b in Bomb.lst:
if self.shape.hitsShape(b.shape):
b.shape.visible = False
else:
# removes Explosion
removeObject(self)
class IonBlast(Projectile):
lst = []
def __init__(
self, sX, sY, ionFill, speed, *, empSize = 15*app.sizeMulti, lW = 2*app.sizeMulti,
length = 5*app.sizeMulti, rA = 90, harmShip = False, empDuration = 60
):
x2, y2 = getPointInDir(sX, sY, rA, length)
self.shape = Line(sX, sY, x2, y2, fill = ionFill, lineWidth = lW)
self.empSize = empSize
self.empDuration = empDuration
# calls Projectile constructor
super().__init__(rA, speed, 0, harmShip, "ib")
IonBlast.lst.append(self)
# creates EMP depending on the IonBlast's stats
def effect(self):
EMP(self.shape.right, self.shape.centerY, size = self.empSize, duration = self.empDuration)
class EMP:
lst = []
def __init__(self, cX, cY, *, size = 15*app.sizeMulti, duration = 60):
self.shape = Circle(cX, cY, 1*app.sizeMulti, fill = gradient('blue', 'navy', 'mediumvioletred', 'magenta', 'purple'))
self.size = size
self.duration = duration
EMP.lst.append(self)
app.hazardLst.append(self)
def stun(self):
if self.shape.radius <= self.size:
# expands EMP, stuns hit ships
self.shape.radius += randrange(3, 11)*app.sizeMulti
for e in EnemyShip.lst:
if self.shape.hitsShape(e.shape):
e.speed = 0
e.cooldown = self.duration*2
for s in Ship.lst:
if self.shape.hitsShape(s.shape):
s.stunned = True
elif self.duration > 0:
# ticks down duration
self.shape.visible = False
self.duration -= 1
else:
# removes EMP
self.shape.visible = True
for e in EnemyShip.lst:
if self.shape.hitsShape(e.shape):
e.speed = e.previousSpeed
for s in Ship.lst:
if self.shape.hitsShape(s.shape):
s.stunned = False
removeObject(self)
class EnemyShip:
lst = []
def __init__(self, cY, speed, hp, score, cooldownMax, type, destroyerSpawned):
self.shape.centerY = cY
self.speed = speed+app.score/1000
self.hp = hp+int(app.score/100)+app.enemyHPMod
self.cooldown = 10
self.cooldownMax = cooldownMax+app.enemyCooldownMod
self.direction = 0
self.deployCooldown = 150
self.score = score
self.type = type
self.destroyerSpawned = destroyerSpawned
self.previousSpeed = speed+app.score/1000
EnemyShip.lst.append(self)
app.hazardLst.append(self)
# moves EnemyShip
def move(self):
if self.hp > 0:
# tracks nearest player ship
shipDistance = 1000000000
shipY = 0
for ship in Ship.lst:
if ship.shape.visible:
if distance(self.shape.centerX, self.shape.centerY, ship.shape.centerX, ship.shape.centerY) < shipDistance:
shipDistance = distance(self.shape.centerX, self.shape.centerY, ship.shape.centerX, ship.shape.centerY)
shipY = ship.shape.centerY
if shipY < self.shape.centerY:
self.direction = -1
elif shipY > self.shape.centerY:
self.direction = 1
else:
self.direction = 0
# shoots
self.shape.centerY += self.speed*self.direction
if self.cooldown <= 0:
self.cooldown = self.cooldownMax
self.shoot()
else:
self.cooldown -= 1
# if the EnemyShip is a StarDestroyer, spawns more enemies
if self.type == "sd":
if self.deployCooldown <= 0:
self.deployCooldown = 150+app.enemyCooldownMod
for i in range(randrange(0, 5)):
TieFighter(cY = self.shape.centerY+randrange(-30, 31)*app.sizeMulti, destroyerSpawned = True)
for i in range(randrange(0, 3)):
TieBomber(cY = self.shape.centerY+randrange(-30, 31)*app.sizeMulti, destroyerSpawned = True)
else:
self.deployCooldown -= 1
else:
# removes EnemyShip
removeObject(self)
if self.type == "tf":
Explosion(self.shape.centerX, self.shape.centerY, 0.5+app.enemyDMGMod)
elif self.type == "tb":
Explosion(self.shape.centerX, self.shape.centerY, 1+app.enemyDMGMod, size = 25*app.sizeMulti)
else:
Explosion(self.shape.centerX, self.shape.centerY, 2+app.enemyDMGMod, size = 35*app.sizeMulti)
# adds to score, potentially adds a new Asteroid
app.score += self.score
i = 0
while i < self.score:
if app.score%app.asteroidRate == i and app.score != 0 and len(Asteroid.lst) < app.asteroidCap:
Asteroid()
i += 1
# spawns upgrades
if app.numPlayers == 1:
if not self.destroyerSpawned:
if self.type == "tf":
Level.levelLst[app.level].tFDestroyed += 1
if randrange(1, 16) == 1:
upgradeSpawn(self.shape.centerX, self.shape.centerY)
elif self.type == "tb":
Level.levelLst[app.level].tBDestroyed += 1
for i in range(randrange(0, 2)):
if randrange(1, 11) == 1:
upgradeSpawn(self.shape.centerX, self.shape.centerY)
if self.type == "sd":
Level.levelLst[app.level].sDDestroyed += 1
for i in range(randrange(0, 2)+3):
if randrange(1, 11) == 1:
upgradeSpawn(self.shape.centerX, self.shape.centerY)
class TieFighter(EnemyShip):
lst = []
def __init__(self, cY, *, destroyerSpawned = False):
self.shape = Group(
RegularPolygon(380, cY, 20, 6, border = 'gray', rotateAngle = 90),
RegularPolygon(380, cY, 5, 6, border = 'dimgray', rotateAngle = 90)
)
for i in range(6):
x1, y1 = getPointInDir(380, cY, 30+60*i, 5)
x2, y2 = getPointInDir(380, cY, 30+60*i, 20)
self.shape.add(Line(x1, y1, x2, y2, fill = 'gray'))
self.shape.width *= (4/5)*app.sizeMulti
self.shape.height *= (4/5)*app.sizeMulti
self.shape.centerX = 380*app.sizeMulti
# calls EnemyShip constructor
super().__init__(cY, 1*app.sizeMulti, 15, 2, 35, "tf", destroyerSpawned)
TieFighter.lst.append(self)
# shoots Laser
def shoot(self):
Laser(
self.shape.left, self.shape.centerY, 'limegreen', 4.5*app.sizeMulti, 1+app.enemyDMGMod,
harmShip = True, lW = 3.5*app.sizeMulti, rA = 270, length = 7.5*app.sizeMulti, piercing = 2
)
class TieBomber(EnemyShip):
lst = []
def __init__(self, cY, *, destroyerSpawned = False):
self.shape = Group(
Line(357.5, cY, 402.5, cY, lineWidth = 20, fill = 'gray'),
RegularPolygon(380, cY, 20, 6, border = 'gray', rotateAngle = 90),
RegularPolygon(380, cY, 5, 6, border = 'dimgray', rotateAngle = 90)
)
for i in range(6):
x1, y1 = getPointInDir(380, cY, 30+60*i, 5)
x2, y2 = getPointInDir(380, cY, 30+60*i, 20)
self.shape.add(Line(x1, y1, x2, y2, fill = 'gray'))
self.shape.width *= (4/5)*app.sizeMulti
self.shape.height *= (4/5)*app.sizeMulti
self.shape.centerX = 380*app.sizeMulti
# calls EnemyShip constructor
super().__init__(cY, 0.75*app.sizeMulti, 30, 4, 60, "tb", destroyerSpawned)
TieBomber.lst.append(self)
# shoots Bomb
def shoot(self):
Bomb(
self.shape.left, self.shape.centerY, 3*app.sizeMulti, 4+app.enemyDMGMod, 1,
radius = 7.5*app.sizeMulti, explosionSize = 15*app.sizeMulti, rA = 270, harmShip = True
)
class StarDestroyer(EnemyShip):
lst = []
def __init__(self, cY):
self.shape = Group(
Line(390, cY, 397.5, cY, lineWidth = 10, fill = 'dimgray'),
Line(397.5, cY-5, 397.5, cY+5, fill = 'cyan'),
Line(387.5, cY-12.5, 387.5, cY, fill = 'dimgray', lineWidth = 6),
Line(382.5, cY-15, 392.5, cY-15, fill = 'gray', lineWidth = 5),
Circle(387.5, cY-20, 2.5, fill = 'gray'),
Polygon(395, cY-7.5, 395, cY+10, 385, cY+10, 310, cY+6.5, 310, cY, 385, cY-7.5, fill = 'gray')
)
self.shape.width *= 1.25*app.sizeMulti
self.shape.height *= 1.25*app.sizeMulti
self.shape.right = 397.5*app.sizeMulti
# calls EnemyShip constructor
super().__init__(cY, 0.75*app.sizeMulti, 60, 10, 105, "sd", False)
StarDestroyer.lst.append(self)
# shoots Laser
def shoot(self):
Laser(
self.shape.centerX+15*app.sizeMulti, self.shape.centerY-1*app.sizeMulti, 'limegreen', 4, 5+app.enemyDMGMod,
harmShip = True, lW = 4*app.sizeMulti, rA = 270, length = 10*app.sizeMulti, piercing = 3
)
class Asteroid:
lst = []
def __init__(self):
self.shape = RegularPolygon(
430*app.sizeMulti+10, randrange(20, 380)*app.sizeMulti, randrange(10, 30)*app.sizeMulti, 7,
fill = gradient('dimgray', 'grey', 'darkgray', 'grey', 'dimgray', start = 'left')
)
self.speed = 6*app.sizeMulti-self.shape.radius/10
Asteroid.lst.append(self)
app.hazardLst.append(self)
# moves asteroid, does collision, resets Asteroid if off screen
def move(self):
self.speed = 6*app.sizeMulti-self.shape.radius/10+app.score/1000*app.sizeMulti
if self.shape.right > 0:
self.shape.centerX -= self.speed
self.shape.rotateAngle += 1
else:
self.reset()
for ship in Ship.lst:
if self.shape.hitsShape(ship.shape):
if ship.invTime <= 0:
ship.shields -= int(self.shape.radius/10/app.sizeMulti)+1
ship.invTime = 1
self.reset()
# resets Asteroid
def reset(self):
# resets asteroids, gives them new size and speed
self.shape.left = (375+randrange(50, 200))*app.sizeMulti
self.shape.centerY = randrange(20, 380)*app.sizeMulti
self.shape.radius = (randrange(10, 30)+app.score/100)*app.sizeMulti
if self.shape.radius > (100+app.asteroidSizeMod)*app.sizeMulti:
self.shape.radius = (100+app.asteroidSizeMod)*app.sizeMulti
self.speed = 6*app.sizeMulti-self.shape.radius/10+app.score/1000*app.sizeMulti
# adds a new asteroid every app.asteroidRate score
if app.score%app.asteroidRate == 0 and app.score != 0 and len(Asteroid.lst) < app.asteroidCap:
Asteroid()
if app.numPlayers == 1:
Level.levelLst[app.level].asteroidsDestroyed += 1
app.score += 1
class Ship:
lst = []
def __init__(self, speed, shotCooldown, hp, shields, shieldCooldown, upKey, downKey, rightKey, leftKey, shootKey, abilityKey):
self.speed = speed
self.shotCooldown = 0
self.shotCooldownMax = shotCooldown
self.hp = hp
self.hpMax = hp
self.shields = shields
self.shieldsMax = shields
self.shieldCooldown = shieldCooldown
self.shieldCooldownMax = shieldCooldown
self.upKey = upKey
self.downKey = downKey
self.rightKey = rightKey
self.leftKey = leftKey
self.shootKey = shootKey
self.abilityKey = abilityKey
self.abilityCooldown = 0
self.abilityTimer = 0
self.stunned = False
self.invTime = 30
# information (hp, shield, shotCooldown, abilityCooldown) bars (lets the player know roughly what these values are at)
self.healthBarBack = Line(
self.shape.centerX-40*app.sizeMulti, self.shape.bottom+1.25*app.sizeMulti, self.shape.centerX+40*app.sizeMulti,
self.shape.bottom+1.25*app.sizeMulti, fill = 'seagreen', lineWidth = 2.5*app.sizeMulti
)
self.shieldBarBack = Line(
self.shape.centerX-40*app.sizeMulti, self.shape.bottom+5*app.sizeMulti, self.shape.centerX+40*app.sizeMulti,
self.shape.bottom+5*app.sizeMulti, fill = 'cadetblue', lineWidth = 2.5*app.sizeMulti
)
self.shotCooldownBarBack = Line(
self.shape.centerX-40*app.sizeMulti, self.shape.bottom+8.75*app.sizeMulti, self.shape.centerX,
self.shape.bottom+8.75*app.sizeMulti, fill = 'firebrick', lineWidth = 2.5*app.sizeMulti
)
self.abilityBarBack = Line(
self.shape.centerX, self.shape.bottom+8.75*app.sizeMulti, self.shape.centerX+40*app.sizeMulti,
self.shape.bottom+8.75*app.sizeMulti, fill = 'darkkhaki', lineWidth = 2.5*app.sizeMulti
)
self.hpBar = Line(
self.shape.centerX-40*app.sizeMulti, self.shape.bottom+1.25*app.sizeMulti, self.shape.centerX+40*app.sizeMulti,
self.shape.bottom+1.25*app.sizeMulti, fill = 'limegreen', lineWidth = 2.5*app.sizeMulti
)
self.shieldBar = Line(
self.shape.centerX-40*app.sizeMulti, self.shape.bottom+5*app.sizeMulti, self.shape.centerX+40*app.sizeMulti,
self.shape.bottom+5*app.sizeMulti, fill = 'cyan', lineWidth = 2.5*app.sizeMulti
)
self.shieldCooldownBar = Line(
self.shape.centerX-40*app.sizeMulti, self.shape.bottom+5*app.sizeMulti, self.shape.centerX+40*app.sizeMulti,
self.shape.bottom+5*app.sizeMulti, fill = 'lightcyan', lineWidth = 1.25*app.sizeMulti
)
self.shotCooldownBar = Line(
self.shape.centerX-40*app.sizeMulti, self.shape.bottom+8.75*app.sizeMulti, self.shape.centerX,
self.shape.bottom+8.75*app.sizeMulti, fill = 'red', lineWidth = 2.5*app.sizeMulti
)
self.abilityBar = Line(
self.shape.centerX, self.shape.bottom+8.75*app.sizeMulti, self.shape.centerX+40*app.sizeMulti,
self.shape.bottom+8.75*app.sizeMulti, fill = 'gold', lineWidth = 2.5*app.sizeMulti
)
self.barGroup = Group(
self.healthBarBack, self.shieldBarBack, self.shotCooldownBarBack, self.abilityBarBack, self.hpBar,
self.shieldBar, self.shieldCooldownBar, self.shotCooldownBar, self.abilityBar
)
Ship.lst.append(self)
def shieldRegen(self):
if self.shields < self.shieldsMax:
if self.shieldCooldown <= 0:
self.shieldCooldown = self.shieldCooldownMax
self.shields += 1
else:
self.shieldCooldown -= 1
def onStep(self):
if self.hp > 0:
self.invTime -= 1
# updates hp
if self.shields < 0:
self.hp += self.shields
self.shields = 0
if not self.stunned:
# regens shield (or hp if the ship is the Falcon and has hp regen Enabled)
if self.type == "F" and self.hp < self.hpMax:
if self.healthRegenEnabled:
if self.shieldCooldown <= 0:
self.shieldCooldown = self.shieldCooldownMax
self.hp += 1
else:
self.shieldCooldown -= 1
else:
self.shieldRegen()
else:
self.shieldRegen()
if self.abilityTimer <= 0 or self.moveWhileAbility:
# updates shotCooldown(Bar)
if self.shotCooldown > 0:
self.shotCooldown -= 1
self.shotCooldownBar.fill = 'crimson'
self.shotCooldownBar.lineWidth = 1.25*app.sizeMulti
else:
self.shotCooldownBar.fill = 'red'
self.shotCooldownBar.lineWidth = 2.5*app.sizeMulti
# checks if certain keys are pressed
# moves Ship
if self.upKey in app.keys or (app.numPlayers == 1 and "w" in app.keys):
if self.shape.top-self.speed < 0:
self.shape.top = 0
else:
self.shape.centerY -= self.speed
self.keysLst.append(self.upKey)
elif self.downKey in app.keys or (app.numPlayers == 1 and "s" in app.keys):
if self.shape.bottom+self.speed > 400*app.sizeMulti:
self.shape.bottom = 400*app.sizeMulti
else:
self.shape.centerY += self.speed
self.keysLst.append(self.downKey)
if self.leftKey in app.keys or (app.numPlayers == 1 and "a" in app.keys):
if self.shape.left-self.speed < 0:
self.shape.left = 0
else:
self.shape.centerX -= self.speed
self.keysLst.append(self.leftKey)
elif self.rightKey in app.keys or (app.numPlayers == 1 and "d" in app.keys):
if self.shape.right+self.speed > 400*app.sizeMulti:
self.shape.right = 400*app.sizeMulti
else:
self.shape.centerX += self.speed
self.keysLst.append(self.rightKey)
# calls shoot function (each Ship has a unique shot pattern)
if self.shootKey in app.keys and self.shotCooldown <= 0:
app.keys.remove(self.shootKey)
shoot = True
if self.abilityTimer > 0:
if self.type == "f":
if self.autoAimEnabled:
shoot = False
elif self.type == "x":
if self.dashEnabled:
shoot = False
if shoot:
self.shotCooldown = self.shotCooldownMax
self.shoot()
# calls ability function (each Ship has unique abilities)
self.ability()
# updates information bars
self.barGroup.centerX = self.shape.centerX
self.barGroup.centerY = self.shape.bottom+7.5
self.hpBar.x2 = self.shape.centerX+(-40+self.hp*80/self.hpMax)*app.sizeMulti
self.shieldBar.x2 = self.shape.centerX+(-40+self.shields*(80/self.shieldsMax))*app.sizeMulti
if self.shieldCooldownMax > 0:
self.shieldCooldownBar.x2 = self.shape.centerX+(40-self.shieldCooldown*80/self.shieldCooldownMax)*app.sizeMulti
if self.shotCooldownMax > 0:
self.shotCooldownBar.x2 = self.shape.centerX-self.shotCooldown*(40*app.sizeMulti/self.shotCooldownMax)
self.shape.toFront()
self.barGroup.toFront()
else:
# removes Ship
removeObject(self)
self.barGroup.visible = False
class XWing(Ship):
# ability: dash
boostLst = []
for i in range(10):
boostLst.append(0)
abilityBoostLst = []
for i in range(5):
abilityBoostLst.append(0)
abilityBoostNameLst = ["Dash Ability Cooldown" , "Support Ability Cooldown", "Support Ability Duration", "Support Strength", "# of Support Ships"]
def __init__(self, cX, cY, upKey, downKey, rightKey, leftKey, shootKey, abilityKey, *, dashEnabled = False, supportEnabled = False):
self.shape = Group(
Polygon(
300, 198, 263, 184, 211, 176, 175, 160, 137, 146, 97, 148, 78, 164, 34, 172, 38, 204, 299, 204,
fill = gradient('grey', 'firebrick', 'grey', 'firebrick', 'grey', 'grey', 'grey', 'dimGrey', 'dimGrey', start = 'right')
),
Polygon(263, 183, 123, 172, 123, 147, 137, 146, 175, 154, 211, 176, fill = gradient('grey', 'black', 'grey', 'grey', 'grey', start = 'left')),
Polygon(
76, 164, 26, 165, 24, 170, 26, 181, 74, 181, 75, 175, 139, 175, 139, 164,
fill = gradient('dimGrey', 'dimGrey', 'dimGrey', 'black', start = 'right'),
border = gradient('grey', 'dimGrey', start = 'left')
),
Polygon(
76, 190, 26, 191, 24, 96, 26, 207, 74, 207, 75, 201, 139, 201, 139, 190,
fill = gradient('dimGrey', 'dimGrey', 'dimGrey', 'black', start = 'right'),
border = gradient('grey', 'dimGrey', start = 'left')
),
Line(65, 114, 130, 114, fill = 'dimGrey', lineWidth = 8),
Line(130, 114, 155, 114, lineWidth = 5, fill = 'dimGrey'),
Line(155, 114, 193, 114, lineWidth = 3, fill = 'dimGrey'),
Line(65, 251, 130, 251, fill = 'dimGrey', lineWidth = 8),
Line(130, 251, 155, 251, lineWidth = 5, fill = 'dimGrey'),
Line(155, 251, 193, 251, lineWidth = 3, fill = 'dimGrey'),
Polygon(93, 255, 116, 255, 133, 190, 72, 190, fill = gradient('gainsboro', 'dimGrey', start = 'bottom')),
Polygon(72, 175, 93, 110, 116, 110, 133, 175, fill = gradient('gainsboro', 'dimGrey', start = 'top')),
Polygon(72, 175, 72, 190, 133, 190, 133, 175, fill = gradient('dimGrey', 'black', 'dimGrey', start = 'top')),
Polygon(263, 184, 265, 189, 267, 194, 265, 200, 263, 204, 299, 204, 300, 198, fill = 'white')
)
self.shape.width = 70*app.sizeMulti
self.shape.height = 40*app.sizeMulti
self.shape.centerX = cX
self.shape.centerY = cY
self.dashEnabled = dashEnabled
self.supportEnabled = supportEnabled
if dashEnabled:
self.moveWhileAbility = False
self.abilityTimerMax = 15
else:
self.moveWhileAbility = True
self.keysLst = [rightKey]
self.type = "X"
# calls Ship constructor with different values depending on if the player chose multiplayer or not
if app.numPlayers == 1:
if dashEnabled:
self.abilityCooldownMax = 61-15*XWing.abilityBoostLst[0]
elif supportEnabled:
self.abilityCooldownMax = 151-15*XWing.abilityBoostLst[1]
self.abilityTimerMax = 180+5*XWing.abilityBoostLst[2]
self.dashSpeed = (7.5+XWing.boostLst[0]*0.01)*app.sizeMulti
self.numOfSupports = 2+int(XWing.abilityBoostLst[4]/5)
super().__init__(
4.5*app.sizeMulti+(XWing.boostLst[0]*0.25)*app.sizeMulti, 0, 3+XWing.boostLst[2], 3+XWing.boostLst[3],
210-(XWing.boostLst[4]*15), upKey, downKey, rightKey, leftKey, shootKey, abilityKey
)
else:
if dashEnabled:
self.abilityCooldownMax = 61
elif supportEnabled:
self.abilityCooldownMax = 151
self.abilityTimerMax = 180
self.dashSpeed = 7.5*app.sizeMulti
self.numOfSupports = 2
super().__init__(4.5*app.sizeMulti, 0, 3, 3, 210, upKey, downKey, rightKey, leftKey, shootKey, abilityKey)
# shoots Lasers
def shoot(self):
if app.numPlayers == 1:
Laser(
self.shape.right-27*app.sizeMulti, self.shape.centerY-16*app.sizeMulti, 'red', (6+(XWing.boostLst[6]*0.25))*app.sizeMulti, 1.5+(XWing.boostLst[5]*0.25),
lW = (2+(XWing.boostLst[8]*0.25))*app.sizeMulti, length = (5+(XWing.boostLst[9]*0.5))*app.sizeMulti, piercing = 2+XWing.boostLst[7]
)
Laser(
self.shape.right-27*app.sizeMulti, self.shape.centerY+19*app.sizeMulti, 'red', (6+(XWing.boostLst[6]*0.25))*app.sizeMulti, 1.5+(XWing.boostLst[5]*0.25),
lW = (2+(XWing.boostLst[8]*0.25))*app.sizeMulti, length = (5+(XWing.boostLst[9]*0.5))*app.sizeMulti, piercing = 2+XWing.boostLst[7]
)
else:
Laser(self.shape.right-27*app.sizeMulti, self.shape.centerY-16*app.sizeMulti, 'red', 6*app.sizeMulti, 1.5, lW = 2*app.sizeMulti, length = 5*app.sizeMulti, piercing = 2)
Laser(self.shape.right-27*app.sizeMulti, self.shape.centerY+19*app.sizeMulti, 'red', 6*app.sizeMulti, 1.5, lW = 2*app.sizeMulti, length = 5*app.sizeMulti, piercing = 2)
# defines what the XWing's abilities do
def ability(self):
if self.abilityKey in app.keys and self.abilityCooldown <= 0:
self.abilityCooldown = self.abilityCooldownMax
app.keys.remove(self.abilityKey)
if self.supportEnabled:
if app.numPlayers == 1:
for i in range(10):
temp = SupportShip.boostLst[i]
SupportShip.boostLst[i] = XWing.boostLst[i]*((1+XWing.abilityBoostLst[3])/100)
XWing.boostLst[i] = temp
for i in range(self.numOfSupports):
SupportShip(randrange(0, 401), duration = self.abilityTimerMax)
if app.numPlayers == 1:
for i in range(10):
temp = int(SupportShip.boostLst[i]/((1+XWing.abilityBoostLst[3])/100))
SupportShip.boostLst[i] = XWing.boostLst[i]
XWing.boostLst[i] = temp
self.abilityTimer = self.abilityTimerMax
elif self.abilityTimer > 0:
# dash ability
if self.dashEnabled:
# moves XWing
if self.keysLst[len(self.keysLst)-1] == self.upKey:
self.shape.centerY -= self.dashSpeed
elif self.keysLst[len(self.keysLst)-1] == self.downKey:
self.shape.centerY += self.dashSpeed
elif self.keysLst[len(self.keysLst)-1] == self.leftKey:
self.shape.centerX -= self.dashSpeed
elif self.keysLst[len(self.keysLst)-1] == self.rightKey:
self.shape.centerX += self.dashSpeed
if self.shape.top < 0:
self.shape.top = 0
elif self.shape.bottom > 400*app.sizeMulti:
self.shape.bottom = 400*app.sizeMulti
if self.shape.left < 0:
self.shape.left = 0
elif self.shape.right > 400*app.sizeMulti:
self.shape.right = 400*app.sizeMulti
if self.supportEnabled:
if len(SupportShip.lst) == 0:
self.abilityTimer = 1
# updates ability bar, updates timers
self.abilityTimer -= 1
self.abilityBar.fill = 'yellow'
self.abilityBar.x2 = self.shape.centerX+self.abilityTimer*(40*app.sizeMulti/self.abilityTimerMax)
elif self.abilityCooldown > 0:
self.abilityCooldown -= 1
self.abilityBar.fill = 'palegoldenrod'
self.abilityBar.x2 = self.shape.centerX+(40-self.abilityCooldown*40/self.abilityCooldownMax)*app.sizeMulti
self.abilityBar.lineWidth = 1.25*app.sizeMulti
else:
self.abilityBar.fill = 'gold'
self.abilityBar.lineWidth = 2.5*app.sizeMulti
class YWing(Ship):
# ability: bomb, ion cannon
boostLst = []
for i in range(10):
boostLst.append(0)
abilityBoostLst = []
for i in range(10):
abilityBoostLst.append(0)
abilityBoostNameLst = [
"Ability Cooldown", "Bomb Charges", "Bomb Size", "Bomb Radius", "EMP Charges", "EMP Radius", "EMP Duration", "Cluster Bomb Charges",
"Cluster Bomb Fragments", "Cluster Bomb Recursions"
]
def __init__(self, cX, cY, upKey, downKey, rightKey, leftKey, shootKey, abilityKey, *, bomb = False, emp = False, cluster = False):
self.shape = Group(
Polygon(118, 193, 248, 193, 258, 187, 294, 187, 294, 185, 310, 185, 310, 183, 294, 183, 293, 181, 269, 175, 257, 167, 217, 167, 216, 176, 118, 176, fill = 'dimGrey'),
Rect(33, 178, 85, 19, fill = None, border = 'grey'),
Polygon(100, 185, 100, 190, 112, 197, 170, 197, 174, 193, 175, 188, 175, 186, 175, 186, 174, 182, 173, 181, 167, 178, 110, 178, fill = 'grey'),
Polygon(217, 167, 257, 167, 269, 176, 259, 176, 216, 176, fill = 'steelBlue'),
Polygon(247, 169, 255, 169, 260, 174, 247, 174, fill = gradient('grey', 'grey', 'cornflowerBlue', start = 'bottom-left')),
Polygon(235, 170, 223, 170, 222, 174, 235, 174, fill = gradient('grey', 'grey', 'cornflowerBlue', start = 'bottom-left'))
)
self.shape.width = 84*app.sizeMulti
self.shape.height = 15*app.sizeMulti
self.shape.centerX = cX
self.shape.centerY = cY
self.abilityTimerMax = 1
self.keysLst = []
self.bombEnabled = bomb
self.empEnabled = emp
self.clusterEnabled = cluster
self.moveWhileAbility = True
self.type = "Y"
# calls Ship constructor with different values depending on if the player chose multiplayer or not
if app.numPlayers == 1:
self.bombCharges = 3+YWing.abilityBoostLst[1]
self.bombSize = 4-YWing.abilityBoostLst[2]*0.25
self.empCharges = 3+YWing.abilityBoostLst[4]
self.clusterCharges = 3+YWing.abilityBoostLst[7]
self.abilityCooldownMax = 91-15*YWing.abilityBoostLst[0]
super().__init__(
2.5*app.sizeMulti+(YWing.boostLst[0]*0.25)*app.sizeMulti, 20-int(YWing.boostLst[1]/2), 5+YWing.boostLst[2],
4+YWing.boostLst[3], 450-(YWing.boostLst[4]*15), upKey, downKey, rightKey, leftKey, shootKey, abilityKey
)
else:
self.bombCharges = 3
self.clusterCharges = 3
self.abilityCooldownMax = 91
self.empCharges = 3
super().__init__(2.5*app.sizeMulti, 20, 5, 4, 450, upKey, downKey, rightKey, leftKey, shootKey, abilityKey)
self.bombChargesMax = self.bombCharges
self.empChargesMax = self.empCharges
self.clusterChargesMax = self.clusterCharges
# shoots Laser
def shoot(self):
if app.numPlayers == 1:
Laser(
self.shape.right, self.shape.centerY, 'green', (4.25+(YWing.boostLst[6]*0.25))*app.sizeMulti, 7.5+(YWing.boostLst[5]*0.25),
lW = (3+(YWing.boostLst[8]*0.25))*app.sizeMulti, length = (7.5+(YWing.boostLst[9]*0.5))*app.sizeMulti,
piercing = 2+YWing.boostLst[7]
)
else:
Laser(self.shape.right, self.shape.centerY, 'green', 4.25*app.sizeMulti, 7.5 , lW = 3*app.sizeMulti, length = 7.5*app.sizeMulti, piercing = 2)
# defines what the YWing's abilities do
def ability(self):
if self.abilityKey in app.keys:
# shoots projectile depending on what abilities are Enabled, lowers the amount of Chrgs left
# shoots Bomb if bomb is Enabled
if self.bombEnabled and self.bombCharges > 0:
if app.numPlayers == 1:
Bomb(
self.shape.right, self.shape.centerY, (3.5+YWing.boostLst[6]*0.1)*app.sizeMulti, 15+YWing.boostLst[5]*0.25, 2+YWing.boostLst[5]*0.05,
radius = self.bombSize*app.sizeMulti, explosionSize = 25*app.sizeMulti+int(YWing.abilityBoostLst[3]*0.5)*app.sizeMulti, rA = 90
)
else:
Bomb(self.shape.right, self.shape.centerY, 3.5*app.sizeMulti, 15, 2, radius = 4*app.sizeMulti, explosionSize = 25*app.sizeMulti, rA = 90)
self.bombCharges -= 1
# shoots IonBlast if emp is Enabled
if self.empEnabled and self.empCharges > 0:
if app.numPlayers == 1:
IonBlast(
self.shape.right, self.shape.centerY, 'magenta', (5+(YWing.boostLst[6]*0.25))*app.sizeMulti,
empSize = (30+int(YWing.abilityBoostLst[5]*0.1))*app.sizeMulti, lW = 4*app.sizeMulti,
length = 7*app.sizeMulti, empDuration = 120+YWing.abilityBoostLst[6]
)
else:
IonBlast(
self.shape.right, self.shape.centerY, 'magenta', 5*app.sizeMulti, empSize = 30*app.sizeMulti,
lW = 4*app.sizeMulti, length = 7*app.sizeMulti, empDuration = 120
)
self.empCharges -= 1
# shoots ClusterBomb if cluster is enabled
if self.clusterEnabled and self.clusterCharges > 0:
if app.numPlayers == 1:
ClusterBomb(
self.shape.right, self.shape.centerY, (3.5+YWing.boostLst[6]*0.1)*app.sizeMulti, 15+YWing.boostLst[5]*0.25,
radius = 6*app.sizeMulti, clusterBombExplosionSize = (25+int(YWing.abilityBoostLst[3]*0.5))*app.sizeMulti, rA = 90,
clusterBombExplosionDamage = 1+(YWing.boostLst[5]*0.05)/2, numBombs = 3+int(YWing.abilityBoostLst[8]/10),
recursions = 0+int(YWing.abilityBoostLst[9]/10)
)
else:
ClusterBomb(
self.shape.right, self.shape.centerY, 3.5*app.sizeMulti, 15, radius = 6*app.sizeMulti, clusterBombExplosionSize = 25*app.sizeMulti,
rA = 90, clusterBombExplosionDamage = 1, numBombs = 3, recursions = 0
)
self.clusterCharges -= 1
# updates ability bar, updates cooldowns and Charges
if (
(self.clusterCharges <= 0 and self.clusterEnabled) or (self.bombCharges <= 0 and self.bombEnabled) or
(self.empCharges <= 0 and self.empEnabled)
):
self.abilityBarBack.fill = 'darkkhaki'
self.abilityBar.fill = 'yellow'
self.abilityBar.x2 = self.shape.centerX+40*app.sizeMulti
app.keys.remove(self.abilityKey)
elif self.abilityCooldown > 0:
self.abilityCooldown -= 1
self.abilityBar.fill = 'palegoldenrod'
self.abilityBar.x2 = self.shape.centerX+(40-self.abilityCooldown*40/self.abilityCooldownMax)*app.sizeMulti
self.abilityBar.lineWidth = 1.25*app.sizeMulti
else:
self.abilityBarBack.fill = 'gold'
self.abilityBar.fill = 'gold'
self.abilityBar.lineWidth = 2.5*app.sizeMulti
if self.bombCharges < self.bombChargesMax and self.bombEnabled:
self.bombCharges += 1
self.abilityCooldown = self.abilityCooldownMax
elif self.empCharges < self.empChargesMax and self.empEnabled:
self.empCharges += 1
self.abilityCooldown = self.abilityCooldownMax
elif self.clusterCharges < self.clusterChargesMax and self.clusterEnabled:
self.clusterCharges += 1
self.abilityCooldown = self.abilityCooldownMax
class Falcon(Ship):
# ability: auto aim, regen hp
# boosts
boostLst = []
for i in range(10):
boostLst.append(0)
abilityBoostLst = []
for i in range(2):
abilityBoostLst.append(0)
abilityBoostNameLst = ["Ability Cooldown", "Ability Duration"]
def __init__(self, cX, cY, upKey, downKey, rightKey, leftKey, shootKey, abilityKey, *, autoAimEnabled = False, healthRegenEnabled = False):
self.shape = Group(
Polygon(338, 196, 270, 196, 265, 180, 338, 180, fill = gradient(rgb(120, 125, 126), rgb(120, 125, 126), rgb(120, 125, 126), rgb(95, 98, 98), start = 'left')),
Polygon(292, 196, 168, 220, 168, 196, fill = gradient(rgb(120, 125, 126), rgb(95, 98, 98), rgb(95, 98, 98), rgb(74, 75, 75), start = 'top')),
Polygon(153, 220, 153, 196, 29, 196, fill = gradient(rgb(120, 125, 126), rgb(95, 98, 98), rgb(95, 98, 98), rgb(74, 75, 75), start = 'top')),
Rect(153, 196, 15, 28, fill = rgb(95, 98, 98)),
Rect(29, 180, 51, 16, fill = 'lightBlue'),
Polygon(80, 180, 80, 196, 270, 196, 265, 180, fill = gradient(rgb(120, 125, 126), rgb(120, 125, 126), rgb(120, 125, 126), rgb(95, 98, 98))),
Line(80, 196, 196, 196),
Polygon(292, 180, 168, 164, 168, 180, fill = gradient(rgb(120, 125, 126), rgb(120, 125, 126), rgb(120, 125, 126), rgb(95, 98, 98), start = 'bottom')),
Polygon(153, 164, 153, 180, 29, 180, fill = gradient(rgb(120, 125, 126), rgb(120, 125, 126), rgb(120, 125, 126), rgb(95, 98, 98), start = 'bottom')),
Rect(153, 164, 15, 16, fill = gradient(rgb(120, 125, 126), rgb(120, 125, 126), rgb(120, 125, 126), rgb(95, 98, 98), start = 'bottom')),
Line(80, 180, 181, 180),
Circle(160, 192, 21, fill = gradient(rgb(120, 125, 126), rgb(120, 125, 126), rgb(120, 125, 126), rgb(89, 93, 94), rgb(89, 93, 94))),
Polygon(
154, 180, 164, 180, 172, 192, 164, 205, 154, 205, 147, 192,
fill = gradient(
rgb(89, 93, 94), rgb(89, 93, 94), rgb(74, 75, 75), rgb(74, 75, 75), rgb(74, 75, 75), rgb(74, 75, 75), rgb(74, 75, 75),
rgb(74, 75, 75), 'darkRed', rgb(74, 75, 75), rgb(74, 75, 75), rgb(74, 75, 75), start = 'bottom'
)
),
Polygon(168, 164, 202, 205, 240, 205, 240, 170, 206, 171, fill = gradient(rgb(120, 125, 126), rgb(89, 93, 94), rgb(89, 93, 94), start = 'bottom')),
Polygon(240, 170, 266, 177, 266, 192, 240, 205, fill = gradient(rgb(120, 125, 126), rgb(89, 93, 94), rgb(89, 93, 94), start = 'bottom')),
Line(240, 205, 266, 192, fill = rgb(89, 93, 94)),
Line(195, 196, 202, 205),
Line(168, 164, 195, 196),
Polygon(244, 172, 261, 180, 261, 182, 244, 180, fill = 'lightBlue'),
Polygon(153, 164, 168, 164, 164, 158, 157, 158, fill = gradient(rgb(120, 125, 126), rgb(120, 125, 126), rgb(120, 125, 126), rgb(95, 98, 98), start = 'bottom')),
Polygon(153, 224, 168, 224, 164, 230, 157, 230, fill = gradient(rgb(120, 125, 126), rgb(95, 98, 98), rgb(95, 98, 98), rgb(74, 75, 75), start = 'top')),
Line(164, 162, 173, 156),
Line(164, 227, 173, 229),
Oval(37, 188, 30, 20, fill = 'aqua', opacity = 32),
Line(206, 171, 206, 159, fill = gradient(rgb(120, 125, 126), rgb(120, 125, 126), rgb(120, 125, 126), rgb(95, 98, 98), start = 'bottom')),
Polygon(213, 145, 209, 152, 206, 159, 213, 168, 209, 158, fill = gradient(rgb(120, 125, 126), rgb(120, 125, 126), rgb(120, 125, 126), rgb(95, 98, 98), start = 'bottom'))
)
self.shape.height = 38/1.35*app.sizeMulti
self.shape.width = 130/1.35*app.sizeMulti
self.shape.centerX = cX
self.shape.centerY = cY
self.type = "F"
self.autoAimEnabled = autoAimEnabled
self.healthRegenEnabled = healthRegenEnabled
self.moveWhileAbility = True
self.keysLst = []
# calls Ship constructor with different values depending on if the player chose multiplayer or not
if app.numPlayers == 1:
self.abilityTimerMax = 6+Falcon.abilityBoostLst[1]
self.abilityCooldownMax = 121-5*Falcon.abilityBoostLst[0]
super().__init__(
1.15*app.sizeMulti+(Falcon.boostLst[0]*0.25)*app.sizeMulti, 25-int(Falcon.boostLst[1]/2), 10+Falcon.boostLst[2],
8+Falcon.boostLst[3], 180-(Falcon.boostLst[4]*15), upKey, downKey, rightKey, leftKey, shootKey, abilityKey
)
else:
self.abilityTimerMax = 6
self.abilityCooldownMax = 121
super().__init__(1.15*app.sizeMulti, 25, 10, 8, 180, upKey, downKey, rightKey, leftKey, shootKey, abilityKey)
# shoots Laser
def shoot(self):
if app.numPlayers == 1:
Laser(
self.shape.centerX-5*app.sizeMulti, self.shape.top-0.5*app.sizeMulti, 'red', (3.5+(Falcon.boostLst[6]*0.25))*app.sizeMulti, 1.5+(Falcon.boostLst[5]*0.25),
lW = 2*app.sizeMulti+(Falcon.boostLst[8]*0.25)*app.sizeMulti, length = (5+(Falcon.boostLst[9]*0.5))*app.sizeMulti, piercing = 2+Falcon.boostLst[7]
)
Laser(
self.shape.centerX-5*app.sizeMulti, self.shape.top+2.5*app.sizeMulti, 'red', (3.5+(Falcon.boostLst[6]*0.25))*app.sizeMulti, 1.5+(Falcon.boostLst[5]*0.25),
lW = 2*app.sizeMulti+(Falcon.boostLst[8]*0.25)*app.sizeMulti, length = (5+(Falcon.boostLst[9]*0.5))*app.sizeMulti, piercing = 2+Falcon.boostLst[7]
)
Laser(
self.shape.centerX-5*app.sizeMulti, self.shape.bottom-2.5*app.sizeMulti, 'red', (3.5+(Falcon.boostLst[6]*0.25))*app.sizeMulti, 1.5+(Falcon.boostLst[5]*0.25),
lW = 2*app.sizeMulti+(Falcon.boostLst[8]*0.25)*app.sizeMulti, length = (5+(Falcon.boostLst[9]*0.5))*app.sizeMulti, piercing = 2+Falcon.boostLst[7]
)
Laser(
self.shape.centerX-5*app.sizeMulti, self.shape.bottom+0.5*app.sizeMulti, 'red', (3.5+(Falcon.boostLst[6]*0.25))*app.sizeMulti, 1.5+(Falcon.boostLst[5]*0.25),
lW = 2*app.sizeMulti+(Falcon.boostLst[8]*0.25)*app.sizeMulti, length = (5+(Falcon.boostLst[9]*0.5))*app.sizeMulti, piercing = 2+Falcon.boostLst[7]
)
else:
Laser(self.shape.centerX-5*app.sizeMulti, self.shape.top-0.5*app.sizeMulti, 'red', 3.5*app.sizeMulti, 1.5, lW = 2*app.sizeMulti, length = 5*app.sizeMulti, piercing = 2)
Laser(self.shape.centerX-5*app.sizeMulti, self.shape.top+2.5*app.sizeMulti, 'red', 3.5*app.sizeMulti, 1.5, lW = 2*app.sizeMulti, length = 5*app.sizeMulti, piercing = 2)
Laser(self.shape.centerX-5*app.sizeMulti, self.shape.bottom-2.5*app.sizeMulti, 'red', 3.5*app.sizeMulti, 1.5, lW = 2*app.sizeMulti, length = 5*app.sizeMulti, piercing = 2)
Laser(self.shape.centerX-5*app.sizeMulti, self.shape.bottom+0.5*app.sizeMulti, 'red', 3.5*app.sizeMulti, 1.5, lW = 2*app.sizeMulti, length = 5*app.sizeMulti, piercing = 2)
# defines what the Falcon's abilities do
def ability(self):
if self.abilityKey in app.keys and self.abilityCooldown <= 0:
self.abilityTimer = self.abilityTimerMax
self.abilityCooldown = self.abilityCooldownMax
app.keys.remove(self.abilityKey)
elif self.abilityTimer > 0:
# auto aim ability
if self.autoAimEnabled:
if self.shotCooldown <= 0:
self.shotCooldown = self.shotCooldownMax
self.abilityTimer -= 1
# finds where the hazard with the closest centerY on the top and bottom will be with some inaccuracy
topHazardDistance = 10000
topHazardX = 400*app.sizeMulti
topHazardY = self.shape.top
bottomHazardDistance = 10000
bottomHazardX = 400*app.sizeMulti
bottomHazardY = self.shape.bottom
for hazard in app.hazardLst:
if hazard not in Laser.lst and hazard not in Explosion.lst and hazard.shape.left <= 400*app.sizeMulti:
if hazard.shape.centerY < self.shape.centerY:
newDistance = distance(0, self.shape.centerY, 0, hazard.shape.centerY)
if newDistance < topHazardDistance:
topHazardDistance = newDistance
topHazardX = hazard.shape.centerX
if hazard not in EnemyShip.lst:
if app.numPlayers == 1:
topHazardX = hazard.shape.centerX-hazard.speed*(newDistance/((3.5+Falcon.boostLst[6]*0.25)*app.sizeMulti)*app.sizeMulti)
else:
topHazardX = hazard.shape.centerX-hazard.speed*(newDistance/(3.5*app.sizeMulti)*app.sizeMulti)
topHazardY = hazard.shape.centerY
else:
newDistance = distance(0, self.shape.centerY, 0, hazard.shape.centerY)
if newDistance < bottomHazardDistance:
bottomHazardDistance = newDistance
bottomHazardX = hazard.shape.centerX
if hazard not in EnemyShip.lst:
if app.numPlayers == 1:
bottomHazardX = hazard.shape.centerX-hazard.speed*(newDistance/((3.5+Falcon.boostLst[6]*0.25)*app.sizeMulti)*app.sizeMulti)
else:
bottomHazardX = hazard.shape.centerX-hazard.speed*(newDistance/(3.5*app.sizeMulti)*app.sizeMulti)
bottomHazardY = hazard.shape.centerY
# shoots Laser at nearest hazard
if app.numPlayers == 1:
Laser(
self.shape.centerX-5*app.sizeMulti, self.shape.top-0.5*app.sizeMulti, 'red', (3.5+Falcon.boostLst[6]*0.25)*app.sizeMulti,
1.5+(Falcon.boostLst[5]*0.25), lW = (2+Falcon.boostLst[8]*0.25)*app.sizeMulti, length = (5+Falcon.boostLst[9]*0.5)*app.sizeMulti,
piercing = 2+Falcon.boostLst[7], rA = angleTo(self.shape.centerX-5*app.sizeMulti, self.shape.top-0.5*app.sizeMulti, topHazardX, topHazardY-0.5*app.sizeMulti)
)
Laser(
self.shape.centerX-5*app.sizeMulti, self.shape.top+2.5*app.sizeMulti, 'red', (3.5+Falcon.boostLst[6]*0.25)*app.sizeMulti,
1.5+(Falcon.boostLst[5]*0.25), lW = (2+Falcon.boostLst[8]*0.25)*app.sizeMulti, length = (5+Falcon.boostLst[9]*0.5)*app.sizeMulti,
piercing = 2+Falcon.boostLst[7], rA = angleTo(self.shape.centerX-5*app.sizeMulti, self.shape.top+2.5*app.sizeMulti, topHazardX, topHazardY+2.5*app.sizeMulti)
)
Laser(
self.shape.centerX-5*app.sizeMulti, self.shape.top-2.5*app.sizeMulti, 'red', (3.5+Falcon.boostLst[6]*0.25)*app.sizeMulti,
1.5+(Falcon.boostLst[5]*0.25), lW = (2+Falcon.boostLst[8]*0.25)*app.sizeMulti, length = (5+Falcon.boostLst[9]*0.5)*app.sizeMulti,
piercing = 2+Falcon.boostLst[7], rA = angleTo(self.shape.centerX-5*app.sizeMulti, self.shape.top-2.5*app.sizeMulti, topHazardX, topHazardY-2.5*app.sizeMulti)
)
Laser(
self.shape.centerX-5*app.sizeMulti, self.shape.top+0.5*app.sizeMulti, 'red', (3.5+Falcon.boostLst[6]*0.25)*app.sizeMulti,
1.5+(Falcon.boostLst[5]*0.25), lW = (2+Falcon.boostLst[8]*0.25)*app.sizeMulti, length = (5+Falcon.boostLst[9]*0.5)*app.sizeMulti,
piercing = 2+Falcon.boostLst[7], rA = angleTo(self.shape.centerX-5*app.sizeMulti, self.shape.top+0.5*app.sizeMulti, topHazardX, topHazardY+0.5*app.sizeMulti)
)
else:
Laser(
self.shape.centerX-5*app.sizeMulti, self.shape.top-0.5*app.sizeMulti, 'red', 3.5*app.sizeMulti,
1.5, lW = 2*app.sizeMulti, length = 5*app.sizeMulti, piercing = 2,