-
Notifications
You must be signed in to change notification settings - Fork 6
/
Enemy.cs
1320 lines (1116 loc) · 36.7 KB
/
Enemy.cs
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
using System;
using SplashKitSDK;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using static AsteroidsGame.Program;
public abstract class Enemy
{
private Window _gameWindow;
public double X { get; protected set; }
public double Y { get; protected set; }
public bool IsDead { get; protected set; }
protected bool _IsDying;
protected int _IsDyingCount;
public bool SpawnSmallRocks { get; protected set; }
public bool SmallRocksSpawned { get; set; }
public bool CanShoot { get; protected set; } //{ get { return CanShoot; } protected set { CanShoot = false; } }
public SoundEffect deathSound;
protected double _Angle;
public Vector2D _Velocity { get; protected set; }
protected double _RotationSpeed;
public double Height { get; protected set; }
public double Width { get; protected set; }
public int GetSpeed { get; protected set; }
public virtual Circle[] HitCircle()
{
Circle[] Cir = { SplashKit.CircleAt(X + (Height / 2), Y + (Width / 2), Width / 4) };
return Cir;
}
public virtual Sprite HitSprite()
{
return null;
}
public Enemy(Window gameWindow)
{
_gameWindow = gameWindow;
_IsDying = false;
SpawnSmallRocks = false;
SmallRocksSpawned = false;
SplashKit.SelectSpritePack("Enemies");
deathSound = new SoundEffect("death", "punch-a-rock-161647.ogg");
}
public abstract void Draw();
public void KillTest() { _IsDying = true; }
protected void Rotation(double change)
{
_Angle = (_Angle + change) % 360;
}
public virtual Tuple<String, int> HitCheck(Player player)
{
return new Tuple<string, int>("False", 0);
}
public virtual void freesprite()
{
//Does nothing but allows inherited classes to free their own sprite
}
public virtual void Update()
{
Rotation(_RotationSpeed);
if (_IsDying)
{
_IsDyingCount += 1;
}
else
{
X += _Velocity.X;
Y += _Velocity.Y;
}
}
public virtual Tuple<String, int> HitBy(Player wasHitBy)
{
if (_IsDying)
{ return new Tuple<string, int>("False", 0); }
_IsDying = true;
return new Tuple<string, int>("Life", -1);
}
public virtual Tuple<String, int> HitBy(Shooting wasHitBy)
{
if (_IsDying)
{ return new Tuple<string, int>("False", 0); }
_IsDying = true;
wasHitBy.freesprite();
deathSound.Play(0.5f);
return new Tuple<string, int>("Score", 10);
}
public virtual bool IsOffscreen(Window screen)
{
bool Offscreen = false;
if (X < -Width | X > screen.Width | Y < -Height | Y > screen.Height)
{
Offscreen = true;
}
return Offscreen;
}
protected Point2D RndfromPt()
{
if (SplashKit.Rnd() < 0.5)
{
X = SplashKit.Rnd(_gameWindow.Width);
if (SplashKit.Rnd() < 0.5)
{ Y = -Height; }
else
{ Y = _gameWindow.Height; }
}
else
{
Y = SplashKit.Rnd(_gameWindow.Height);
if (SplashKit.Rnd() < 0.5)
{ X = -Width; }
else
{ X = _gameWindow.Width; }
}
return new Point2D()
{ X = X, Y = Y };
}
protected void SetCourse(int fX = -1, int fY = -1, int tX = -1, int tY = -1)
{
Point2D fromPt;
Point2D tmpPT = RndfromPt();
if (fX == -1)
{
fromPt.X = tmpPT.X;
}
else
{
X = fX;
fromPt.X = fX;
}
if (fY == -1)
{
fromPt.Y = tmpPT.Y;
}
else
{
Y = fY;
fromPt.Y = fY;
}
Point2D toPt;
if (tX == -1)
{
toPt.X = _gameWindow.Width / 2 + SplashKit.Rnd(-100, 100);
}
else
{
toPt.X = tX;
}
if (tY == -1)
{
toPt.Y = _gameWindow.Height / 2 + SplashKit.Rnd(-100, 100);
}
else
{
toPt.Y = tY;
}
X = fromPt.X;
Y = fromPt.Y;
Vector2D dir;
dir = SplashKit.UnitVector(SplashKit.VectorPointToPoint(fromPt, toPt));
_Velocity = SplashKit.VectorMultiply(dir, GetSpeed);
}
}
public class RockLarge : Enemy
{
protected AstGameObj _AGO;
public RockLarge(Window gameWindow, int Speed, double RotationSpeed, int fX = -1, int fY = -1, int tX = -1, int tY = -1) : base(gameWindow)
{
_AGO = new AstGameObj(SplashKit.JsonFromFile("Enemy_Rock_Large.json")); // load sprite with cell details and script
//_AGO._sprite.Scale = 0.5F;
_AGO.rotSpeed = (float)RotationSpeed; // set rotation speed
GetSpeed = (int)(Speed * gameScale); // set velocity magnitude
if (GetSpeed == 0) { GetSpeed = 1; } // prevent zero velocity
SetCourse(fX, fY, tX, tY); // randomized start and direction
X -= _AGO._sprite.Width / 2; // starting completely offscreen breaks the enemy list, original XY is based on top left corner of image
Y -= _AGO._sprite.Height / 2;
_AGO._sprite.X = (float)X; // set sprite coords
_AGO._sprite.Y = (float)Y;
_AGO.setVelocity(_Velocity); // set sprite velocity
Height = _AGO._sprite.Height; // set height and width
Width = _AGO._sprite.Width;
}
public override Circle[] HitCircle() // returns sprite circle that fits within rectangle
{
return new Circle[] { _AGO._sprite.CollisionCircle() };
}
public override Tuple<String, int> HitBy(Player wasHitBy) // if called, start animation
{
if (!_IsDying)
{
_AGO._sprite.StartAnimation("explode");
}
return base.HitBy(wasHitBy);
}
public override Tuple<String, int> HitBy(Shooting wasHitBy)
{
if (!_IsDying)
{
_AGO._sprite.StartAnimation("explode");
}
return base.HitBy(wasHitBy);
}
public override bool IsOffscreen(Window screen)
{
return _AGO._sprite.Offscreen();
}
public override void Update() // update rotation value, check if animations finished
{
X = _AGO._sprite.CenterPoint.X;
Y = _AGO._sprite.CenterPoint.Y;
_AGO.updateAngle();
if (_AGO._sprite.AnimationName() == "explode" && _AGO._sprite.AnimationHasEnded) // first stage, end will set spawn flag
{
SpawnSmallRocks = true;
_AGO._sprite.StartAnimation("explode2");
}
else if (_AGO._sprite.AnimationName() == "explode2" && _AGO._sprite.AnimationHasEnded) // second stage, end should destroy object, freesprite is not called in level due to currently set for bitmap
{
IsDead = true;
SplashKit.FreeSprite(_AGO._sprite);
}
//base.Update(); // not used
}
public override void Draw()
{
//Circle c = _AGO._sprite.CollisionCircle(); // used for debugging
//c.Draw(Color.White);
//_AGO._sprite.Draw();
}
}
public class RockMed : Enemy
{
protected AstGameObj _AGO;
public RockMed(Window gameWindow, int Speed, double RotationSpeed, int fX = -1, int fY = -1, int tX = -1, int tY = -1) : base(gameWindow)
{
_AGO = new AstGameObj(SplashKit.JsonFromFile("Enemy_Rock_Medium.json"));
_AGO.rotSpeed = (float)RotationSpeed;
GetSpeed = (int)(Speed * gameScale); // set velocity magnitude
if (GetSpeed == 0) { GetSpeed = 1; } // prevent zero velocity
SetCourse(fX, fY, tX, tY);
X -= _AGO._sprite.Width / 2;
Y -= _AGO._sprite.Height / 2;
_AGO._sprite.X = (float)X;
_AGO._sprite.Y = (float)Y;
_AGO.setVelocity(_Velocity);
Height = _AGO._sprite.Height; // set height and width
Width = _AGO._sprite.Width;
}
public override Circle[] HitCircle()
{
return new Circle[] { _AGO._sprite.CollisionCircle() };
}
public override Tuple<String, int> HitBy(Player wasHitBy)
{
if (!_IsDying)
{
_AGO._sprite.StartAnimation("explode");
}
return base.HitBy(wasHitBy);
}
public override Tuple<String, int> HitBy(Shooting wasHitBy)
{
if (!_IsDying)
{
_AGO._sprite.StartAnimation("explode");
}
return base.HitBy(wasHitBy);
}
public override bool IsOffscreen(Window screen)
{
return _AGO._sprite.Offscreen();
}
public override void Update()
{
X = _AGO._sprite.CenterPoint.X;
Y = _AGO._sprite.CenterPoint.Y;
_AGO.updateAngle();
if (_AGO._sprite.AnimationName() == "explode" && _AGO._sprite.AnimationHasEnded)
{
IsDead = true;
SplashKit.FreeSprite(_AGO._sprite);
}
base.Update();
}
public override void Draw()
{
//Circle c = _AGO._sprite.CollisionCircle();
//c.Draw(Color.White);
//_AGO._sprite.Draw();
}
}
public class RockSmall : Enemy
{
protected AstGameObj _AGO;
public RockSmall(Window gameWindow, int Speed, double RotationSpeed, int fX = -1, int fY = -1, int tX = -1, int tY = -1) : base(gameWindow)
{
_AGO = new AstGameObj(SplashKit.JsonFromFile("Enemy_Rock_Small.json"));
_AGO.rotSpeed = (float)RotationSpeed;
GetSpeed = (int)(Speed * gameScale); // set velocity magnitude
if (GetSpeed == 0) { GetSpeed = 1; } // prevent zero velocity
SetCourse(fX, fY, tX, tY);
X -= _AGO._sprite.Width / 2;
Y -= _AGO._sprite.Height / 2;
_AGO._sprite.X = (float)X;
_AGO._sprite.Y = (float)Y;
_AGO.setVelocity(_Velocity);
Height = _AGO._sprite.Height; // set height and width
Width = _AGO._sprite.Width;
}
public RockSmall(Window gameWindow, Vector2D Vel, double Rot, Point2D Start) : base(gameWindow)
{
_AGO = new AstGameObj(SplashKit.JsonFromFile("Enemy_Rock_Small.json"));
_AGO.rotSpeed = (float)Rot;
GetSpeed = (int)SplashKit.VectorMagnitude(Vel);
_AGO._sprite.X = (float)(Start.X - _AGO._sprite.CenterPoint.X);
_AGO._sprite.Y = (float)(Start.Y - _AGO._sprite.CenterPoint.Y);
_AGO.setVelocity(Vel);
}
public override Circle[] HitCircle()
{
return new Circle[] { _AGO._sprite.CollisionCircle() };
}
public override Tuple<String, int> HitBy(Player wasHitBy)
{
if (!_IsDying)
{
_AGO._sprite.StartAnimation("explode");
}
return base.HitBy(wasHitBy);
}
public override Tuple<String, int> HitBy(Shooting wasHitBy)
{
if (!_IsDying)
{
_AGO._sprite.StartAnimation("explode");
}
return base.HitBy(wasHitBy);
}
public override bool IsOffscreen(Window screen)
{
return _AGO._sprite.Offscreen();
}
public override void Update()
{
X = _AGO._sprite.CenterPoint.X;
Y = _AGO._sprite.CenterPoint.Y;
_AGO.updateAngle();
if (_AGO._sprite.AnimationName() == "explode" && _AGO._sprite.AnimationHasEnded)
{
IsDead = true;
SplashKit.FreeSprite(_AGO._sprite);
}
base.Update();
}
public override void Draw()
{
//Circle c = _AGO._sprite.CollisionCircle();
//c.Draw(Color.White);
//_AGO._sprite.Draw();
}
}
public class BlueRock : Enemy
{
private Bitmap _Rock;
private Sprite _RockSprite;
private AnimationScript _RockAnimation;
public BlueRock(Window gameWindow, int Speed, double RotationSpeed, int fX = -1, int fY = -1, int tX = -1, int tY = -1) : base(gameWindow)
{
_RotationSpeed = RotationSpeed;
_Angle = 0;
if (SplashKit.HasBitmap("RockBlue"))
{
_Rock = SplashKit.BitmapNamed("RockBlue");
}
else
{
_Rock = SplashKit.LoadBitmap("Rock4", "BlueRockSpriteSheet.png");
_Rock.SetCellDetails(150, 150, 3, 3, 9);
}
if (SplashKit.HasAnimationScript("RockBlueAnimation"))
{
_RockAnimation = SplashKit.AnimationScriptNamed("RockBlueAnimation");
}
else
{
_RockAnimation = SplashKit.LoadAnimationScript("RockBlueAnimation", "BlueRock.txt");
}
_RockSprite = SplashKit.CreateSprite(_Rock, _RockAnimation);
//_RockSprite.AnchorPoint = new Point2D() { X = 75, Y = 75 };
_RockSprite.AnchorPoint = _RockSprite.CenterPoint;
_RockSprite.StartAnimation("normal");
_RockSprite.AddValue("Health", 5);
Height = _Rock.CellHeight;
Width = _Rock.CellWidth;
GetSpeed = (int)(Speed * gameScale); // set velocity magnitude
if (GetSpeed == 0) { GetSpeed = 1; } // prevent zero velocity
SetCourse(fX, fY, tX, tY);
}
public override Circle[] HitCircle()
{
if (!_IsDying) return new Circle[] { _RockSprite.CollisionCircle() };
return new Circle[] { SplashKit.CircleAt(-5, -5, 1) };
}
public override void Update()
{
if (_IsDying)
{
_IsDyingCount += 1;
}
else
{
Rotation(_RotationSpeed);
_RockSprite.Rotation = Convert.ToSingle(_Angle);
X += _Velocity.X;
Y += _Velocity.Y;
_RockSprite.MoveTo(X, Y);
}
if (_RockSprite.AnimationName() == "dying" && _RockSprite.AnimationHasEnded) IsDead = true;
}
public override Tuple<String, int> HitBy(Shooting wasHitBy)
{
int tmpscore = 0;
if (_IsDying) return new Tuple<string, int>("False", 0);
if (_RockSprite.Value("Health") > 0)
{
_RockSprite.SetValue("Health", _RockSprite.Value("Health") - 1);
_RockSprite.StartAnimation("hit");
tmpscore = 10;
}
if (_RockSprite.Value("Health") == 0)
{
_IsDying = true;
_RockSprite.StartAnimation("dying");
tmpscore = +50; // may need to check this, can't remember if it's meant to be trying to add 50 or just set it to 50
}
return new Tuple<string, int>("Score", tmpscore);
}
public override Tuple<String, int> HitBy(Player wasHitBy)
{
if (_IsDying)
{ return new Tuple<string, int>("False", 0); }
_IsDying = true;
_RockSprite.StartAnimation("dying");
return new Tuple<string, int>("Life", -1);
}
public override void freesprite()
{
SplashKit.FreeSprite(_RockSprite);
}
public override Sprite HitSprite()
{
return _RockSprite;
}
public override void Draw()
{ }
}
public class Boss1 : Enemy
{
private Bitmap _Boss;
private Animation _BossAnimation;
private AnimationScript _BossScript;
private DrawingOptions _opt;
private bool _ShieldUp;
private int _ShieldHealth, _ShipHealth;
private bool _ShieldFlash;
private string _Phase;
private bool _XRight;
private bool _YDown;
private List<Shooting> _shots = new List<Shooting>();
private List<Shooting> _KillShots = new List<Shooting>();
private SplashKitSDK.Timer _shootingTime;
private Window _gameWindow;
private int _shootingSmallShot, _shootingEnergyShot;
private Game _game;
public Boss1(Window gameWindow, Game game) : base(gameWindow)
{
if (SplashKit.HasBitmap("Boss1"))
{
_Boss = SplashKit.BitmapNamed("Boss1");
}
else
{
_Boss = SplashKit.LoadBitmap("Boss1", "MotherShipAll.png");
_Boss.SetCellDetails(400, 300, 3, 2, 6);
}
if (SplashKit.HasAnimationScript("MotherShip"))
{
_BossScript = SplashKit.AnimationScriptNamed("MotherShip");
}
else
{
_BossScript = SplashKit.LoadAnimationScript("MotherShip", "MotherShip1.txt");
}
_BossAnimation = _BossScript.CreateAnimation("ShieldUp");
_RotationSpeed = 0;
_Angle = 0;
Height = _Boss.CellHeight;
Width = _Boss.CellWidth;
_ShieldUp = true;
_ShieldHealth = 100; // was 100
_ShieldFlash = false;
_ShipHealth = 50;
_Phase = "Start";
X = (gameWindow.Width / 2 - _Boss.CellWidth / 2);
Y = -299 * gameScale;
_XRight = true;
_YDown = true;
CanShoot = true;
_opt = SplashKit.OptionWithAnimation(_BossAnimation);
_shootingTime = SplashKit.CreateTimer("Boss1Shooting");
_shootingTime.Stop();
_shootingTime.Reset();
_shootingSmallShot = 1;
_shootingEnergyShot = 1;
_gameWindow = gameWindow;
_game = game;
}
public override void Draw()
{
if (_IsDying == false)
{
if (_ShieldUp)
{
if (_ShieldFlash == true)
{
if (_BossAnimation.Ended) _BossAnimation.Assign("ShieldFlash");
_ShieldFlash = false;
}
else
{
if (_BossAnimation.Ended) _BossAnimation.Assign("ShieldUp");
}
}
else
{
if (_ShipHealth <= 10)
{
if (_BossAnimation.Ended) _BossAnimation.Assign("CriticalDamage");
}
else
{
if (_BossAnimation.Ended) _BossAnimation.Assign("ShieldDown");
}
}
}
else
{
if (_BossAnimation.Ended) _BossAnimation.Assign("CriticalDamage");
//if (_BossAnimation.Ended) _BossAnimation.Assign("Dying"); // to be added to the animation
}
foreach (Shooting s in _shots)
{
s.Draw();
}
_Boss.Draw(X, Y, _opt);
}
public override void Update()
{
_BossAnimation.Update();
switch (_Phase)
{
case "Start":
if (Y <= 50 * gameScale)
{
Y++;
}
else
{
_Phase = "Mid";
}
break;
case "Mid":
if (X < 200 * gameScale) _XRight = true;
if (X + Width > _gameWindow.Width - (200 * gameScale)) _XRight = false;
if (Y < 50 * gameScale) _YDown = true;
if (Y > 70 * gameScale) _YDown = false;
if (_XRight == true)
{
X += 2 * gameScale;
}
else
{
X -= 2 * gameScale;
}
if (_YDown == true)
{
// Y++;
Y += 1 * gameScale;
}
else
{
// Y--;
Y -= 1 * gameScale;
}
if (!_shootingTime.IsStarted) _shootingTime.Start();
if (_shootingTime.Ticks / 800 == _shootingSmallShot)
{
ShootSmall();
_shootingSmallShot++;
}
if (_shootingTime.Ticks / 5000 == _shootingEnergyShot)
{
RedEnergyBall();
_shootingEnergyShot++;
}
break;
case "End":
if (X < 200 * gameScale) _XRight = true;
if (X + Width > _gameWindow.Width - (200 * gameScale)) _XRight = false;
if (Y < 50 * gameScale) _YDown = true;
if (Y > 70 * gameScale) _YDown = false;
if (_XRight == true)
{
X += 2 * gameScale;
}
else
{
X -= 2 * gameScale;
}
if (_YDown == true)
{
Y += 1 * gameScale;
}
else
{
Y -= 1 * gameScale;
}
if (_shootingTime.Ticks / 2000 == _shootingEnergyShot)
{
RedEnergyBall();
_shootingEnergyShot++;
}
break;
case "Dead":
if (_BossAnimation.Ended && _shots.Count == 0) IsDead = true;
break;
}
if (_ShieldHealth < 0)
{
if (_ShieldUp == true)
{
_Phase = "End";
_shootingTime.Reset();
_shootingEnergyShot = 1;
}
_ShieldUp = false;
}
if (_ShipHealth < 0)
{
_IsDying = true;
_Phase = "Dead";
}
foreach (Shooting s in _shots)
{
s.Update();
if (s.IsOffscreen(_gameWindow)) _KillShots.Add(s);
}
foreach (Shooting s in _KillShots)
{
s.freesprite();
_shots.Remove(s);
}
_KillShots.Clear();
}
public override void freesprite()
{
foreach (Shooting s in _KillShots)
{
s.freesprite();
_shots.Remove(s);
}
foreach (Shooting s in _shots)
{
s.freesprite();
_shots.Remove(s);
}
}
public override Tuple<String, int> HitBy(Player wasHitBy)
{
/* if(_IsDying)
{return new Tuple<string, int>("False",0);}
_IsDying = true;
return new Tuple<string, int>("Life",-1); */
return new Tuple<string, int>("Life", -1);
// return new Tuple<string, int>("False", 0);
}
public override Tuple<String, int> HitBy(Shooting wasHitBy)
{
/* if(_IsDying)
{return new Tuple<string, int>("False",0);} */
//_IsDying = true;
if (_ShieldUp)
{
_ShieldHealth -= 1;
_ShieldFlash = true;
}
else
{
_ShipHealth -= 1;
}
return new Tuple<string, int>("Score", 10);
}
public override Circle[] HitCircle()
{
Circle[] Cir =
{
SplashKit.CircleAt(X + (198 * gameScale), Y + (116 * gameScale), 102 * gameScale),
SplashKit.CircleAt(X + (293 * gameScale), Y + (112 * gameScale), 78 * gameScale),
SplashKit.CircleAt(X + (102 * gameScale), Y + (112 * gameScale), 78 * gameScale)
};
return Cir;
}
public override Tuple<String, int> HitCheck(Player player)
{
foreach (Shooting s in _shots)
{
if (s.HitCheck(player))
{
_KillShots.Add(s);
if (!player.IsInvulnerable)
{
return new Tuple<string, int>("Life", -1);
}
}
}
return new Tuple<string, int>("False", 0);
}
private void ShootSmall()
{
Shooting ShotType;
Point2D pt1 = new Point2D();
Point2D pt2 = new Point2D();
Point2D pt3 = new Point2D();
pt1.X = X + _Boss.CellCenter.X;
pt1.Y = Y + _Boss.CellCenter.Y;
pt2.X = X + _Boss.CellCenter.X - (20 * gameScale);
pt2.Y = Y + _Boss.CellCenter.Y;
pt3.X = X + _Boss.CellCenter.X + (20 * gameScale);
pt3.Y = Y + _Boss.CellCenter.Y;
ShotType = new BossSmallShot(pt1, 90);
_shots.Add(ShotType);
ShotType = new BossSmallShot(pt1, 70);
_shots.Add(ShotType);
ShotType = new BossSmallShot(pt1, 110);
_shots.Add(ShotType);
}
private void RedEnergyBall()
{
Point2D fromPT = new Point2D();
fromPT.X = X + _Boss.CellCenter.X;
fromPT.Y = Y + _Boss.CellCenter.Y;
foreach (Player p in _game.Players)
{
if (!p.PlayerScore.IsDead)
{
Shooting ShotType = new RedEnergyBall(fromPT, p);
_shots.Add(ShotType);
}
}
}
}
public class Boss2 : Enemy
{
protected Bitmap _Boss;
protected Animation _BossAnimation;
protected AnimationScript _BossScript;
protected string _Phase;
private List<Shooting> _shots = new List<Shooting>();
private List<Shooting> _KillShots = new List<Shooting>();
protected SplashKitSDK.Timer _MoveTimer, _ShotTimer;
protected Window _gameWindow;
private int _shootingSmallShot, _shootingEnergyShot;
protected Game _game;
private List<Sprite> _ShipList = new List<Sprite>();
private List<double> _time = new List<double>();
private double _radius;
private int _Y_point;
protected int _playerKillThreshold;
public Boss2(Window gameWindow, Game game) : base(gameWindow)
{
_gameWindow = gameWindow;
_game = game;
if (SplashKit.HasBitmap("Boss2"))
{
_Boss = SplashKit.BitmapNamed("Boss2");
}
else
{
_Boss = SplashKit.LoadBitmap("Boss2", "MotherShipAll.png");
_Boss.SetCellDetails(400, 300, 3, 2, 6);
}
if (SplashKit.HasAnimationScript("SmallBossShips"))
{
_BossScript = SplashKit.AnimationScriptNamed("SmallBossShips");
}
else
{
_BossScript = SplashKit.LoadAnimationScript("SmallBossShips", "SmallBossShips.txt");
}
double window_3rd = _gameWindow.Width / 4;
Height = _Boss.CellHeight;
Width = _Boss.CellWidth;
Console.WriteLine("Ship Spawn");
for (int i = 1; i <= 3; i++)
{
// _tmpShip.VectorTo(toPoint);
}
_Y_point = (int)(-Height);
_Phase = "Main";
Console.WriteLine("Constructor Done");
if (!SplashKit.HasTimer("Boss2MoveTimer")) _MoveTimer = SplashKit.CreateTimer("Boss2MoveTimer");
else _MoveTimer = SplashKit.TimerNamed("Boss2MoveTimer");
if (!_MoveTimer.IsStarted) _MoveTimer.Start();
if (!SplashKit.HasTimer("Boss2Shoot")) _ShotTimer = SplashKit.CreateTimer("Boss2Shoot");
else _ShotTimer = SplashKit.CreateTimer("Boss2Shoot");
_ShotTimer.Stop();
//if player goes above this they will be killed
_playerKillThreshold = (int)(300 * gameScale);
// Set up variables for the figure 8 pattern
_time.Add((-1000)); //far left
_time.Add((0)); //middle
_time.Add(+1000); //far right
CanShoot = true;
// _BossAnimation = _BossScript.CreateAnimation("ShieldUp");
// _RotationSpeed = 0;
// _Angle = 0;
// X = gameWindow.Width / 2 - _Boss.CellWidth / 2;
// Y = -299;
// _opt = SplashKit.OptionWithAnimation(_BossAnimation);
// _shootingTime = SplashKit.CreateTimer("Boss1Shooting");
// _shootingTime.Stop();
// _shootingTime.Reset();
}
public override void Draw()
{
if (_IsDying == false)
{
foreach (Shooting s in _shots)
{
s.Draw();
}
}
}
public override void Update()
{
}
public override Tuple<String, int> HitBy(Player wasHitBy)
{