forked from thoth-tech/Asteroids
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Shooting.cs
312 lines (250 loc) · 7.98 KB
/
Shooting.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
using System;
using SplashKitSDK;
using System.Collections.Generic;
using static AsteroidsGame.Program;
public abstract class Shooting
{
private double _Angle;
protected Vector2D _Velocity;
public double X { get; protected set; }
public double Y { get; protected set; }
protected int Radius;
public Shooting()
{
SplashKit.SelectSpritePack("Shots");
}
// public Shooting(Point2D fromPT, double Angle,Player player)
// {
// Angle += 270;
// const int SPEED = 10;
// ShotByPlayer = player;
// X = ShotByPlayer.X + fromPT.X;
// Y = ShotByPlayer.Y + fromPT.Y;
// Vector2D direction = SplashKit.UnitVector(SplashKit.VectorFromAngle(Angle,10));
// _Velocity = SplashKit.VectorMultiply(direction,SPEED);
// }
public virtual void freesprite()
{
//Does nothing but allows inherited classes to free their own sprite
}
public virtual void Draw()
{
SplashKit.FillCircle(Color.White, X, Y, Radius);
}
public virtual void Update()
{
X += _Velocity.X;
Y += _Velocity.Y;
}
public virtual bool IsOffscreen(Window screen)
{
bool Offscreen = false;
if (X < -Radius | X > screen.Width | Y < -Radius | Y > screen.Height)
{
Offscreen = true;
}
return Offscreen;
}
public virtual float damage()
{
return 1; //default damage for a shot
}
public abstract bool HitCheck(Enemy enemy);
public abstract bool HitCheck(Player player);
}
public class PlayerShot : Shooting
{
public Player ShotByPlayer { get; protected set; }
public PlayerShot(Point2D fromPT, double Angle, Player player)
{
Angle += 270;
int SPEED = (int)(10 * gameScale);
Radius = (int)(4 * gameScale);
ShotByPlayer = player;
X = ShotByPlayer.X + fromPT.X;
Y = ShotByPlayer.Y + fromPT.Y;
Vector2D direction = SplashKit.UnitVector(SplashKit.VectorFromAngle(Angle, 10));
_Velocity = SplashKit.VectorMultiply(direction, SPEED);
}
public override bool HitCheck(Enemy enemy)
{
bool hit = false;
Circle tmpShot = SplashKit.CircleAt(X, Y, Radius);
foreach (Circle e in enemy.HitCircle())
{
if (SplashKit.CirclesIntersect(tmpShot, e)) hit = true;
}
// if (enemy.HitSprite() != null)
// {
// if (SplashKit.CirclesIntersect(enemy.HitSprite().CollisionCircle(), tmpShot)&&enemy) hit = true; //change this over to sprites if everything is a sprite
// }
return hit;
}
public override bool HitCheck(Player player) { return false; }
}
public class BossSmallShot : Shooting
{
private Circle _shotCircle;
public BossSmallShot(Point2D fromPT, double Angle)
{
const int SPEED = 5;
X = fromPT.X;
Y = fromPT.Y;
Vector2D direction = SplashKit.UnitVector(SplashKit.VectorFromAngle(Angle, 10));
_Velocity = SplashKit.VectorMultiply(direction, SPEED);
Radius = (int)(10 * gameScale);
_shotCircle = SplashKit.CircleAt(X, Y, Radius);
}
public override bool HitCheck(Player player)
{
bool hit = false;
if (SplashKit.BitmapCircleCollision(player.HitBMP(), player.X, player.Y, _shotCircle) && player.PlayerScore.IsDead == false)
{
hit = true;
}
return hit;
}
public override void Update()
{
X += _Velocity.X;
Y += _Velocity.Y;
_shotCircle = SplashKit.CircleAt(X, Y, Radius);
}
public override bool HitCheck(Enemy enemy) { return false; }
public override void Draw()
{
SplashKit.FillCircle(Color.Red, _shotCircle);
}
}
public class RedEnergyBall : Shooting
{
private Bitmap _EnergyBall;
private AnimationScript _EnergyBallScript;
private Sprite _EnergyBallSprite;
public RedEnergyBall(Point2D fromPT, Player player)
{
int SPEED = (int)(5 * gameScale);
X = fromPT.X;
Y = fromPT.Y;
Point2D toPT = new Point2D();
toPT.X = player.X;
toPT.Y = player.Y;
Vector2D direction = SplashKit.UnitVector(SplashKit.VectorPointToPoint(fromPT, toPT));
_Velocity = SplashKit.VectorMultiply(direction, SPEED);
if (SplashKit.HasBitmap("RedEnergyBall"))
{
_EnergyBall = SplashKit.BitmapNamed("RedEnergyBall");
}
else
{
_EnergyBall = SplashKit.LoadBitmap("RedEnergyBall", "RedEnergyBall.png");
_EnergyBall.SetCellDetails(150, 150, 3, 3, 9);
}
if (SplashKit.HasAnimationScript("RedEnergyBall"))
{
_EnergyBallScript = SplashKit.AnimationScriptNamed("RedEnergyBall");
}
else
{
_EnergyBallScript = SplashKit.LoadAnimationScript("RedEnergyBall", "RedEnergyBall.txt");
}
_EnergyBallSprite = SplashKit.CreateSprite(_EnergyBall, _EnergyBallScript);
_EnergyBallSprite.StartAnimation("Start");
_EnergyBallSprite.AnchorPoint = new Point2D() { X = _EnergyBallSprite.Width / 2, Y = _EnergyBallSprite.Height / 2 };
_EnergyBallSprite.Position = fromPT;
}
public override bool HitCheck(Player player)
{
bool hit = false;
if (SplashKit.SpriteBitmapCollision(_EnergyBallSprite, player.HitBMP(), player.X, player.Y) && player.PlayerScore.IsDead == false)
{
hit = true;
}
return hit;
}
public override bool HitCheck(Enemy enemy) { return false; }
public override void Update()
{
_EnergyBallSprite.X += Convert.ToSingle(_Velocity.X);
_EnergyBallSprite.Y += Convert.ToSingle(_Velocity.Y);
//_EnergyBallSprite.AddToVelocity(_Velocity);
}
public override bool IsOffscreen(Window screen)
{
bool Offscreen = false;
if (_EnergyBallSprite.Offscreen())
{
Offscreen = true;
}
return Offscreen;
}
public override void freesprite()
{
SplashKit.FreeSprite(_EnergyBallSprite);
}
~RedEnergyBall()
{
Console.WriteLine("RedEnergyBall is destroyed");
}
}
public class Laser : Shooting
{
private Bitmap _laserImg;
private AnimationScript _LaserScript;
private Sprite _laserSprite;
public Laser(Point2D fromPT, int Frame)
{
int SPEED = (int)(5 * gameScale);
if (SplashKit.HasBitmap("ReallySmallLaser"))
{
_laserImg = SplashKit.BitmapNamed("ReallySmallLaser");
}
else
{
_laserImg = SplashKit.LoadBitmap("ReallySmallLaser", "ReallySmallLaser.png");
_laserImg.SetCellDetails(300, 50, 1, 40, 40);
}
if (SplashKit.HasAnimationScript("LaserScript"))
{
_LaserScript = SplashKit.AnimationScriptNamed("LaserScript");
}
else
{
_LaserScript = SplashKit.LoadAnimationScript("LaserScript", "Laser40.txt");
}
_laserSprite = SplashKit.CreateSprite(_laserImg, _LaserScript);
_laserSprite.Position = fromPT;
_laserSprite.MoveTo(fromPT.X, fromPT.Y);
_laserSprite.Dy = SPEED;
_laserSprite.StartAnimation(Frame);
}
public override bool HitCheck(Player player)
{
bool hit = false;
if (SplashKit.SpriteBitmapCollision(_laserSprite, player.HitBMP(), player.X, player.Y))
{
hit = true;
}
return hit;
}
public override bool HitCheck(Enemy enemy) { return false; }
public override void Update()
{
_laserSprite.X += Convert.ToSingle(_Velocity.X);
_laserSprite.Y += Convert.ToSingle(_Velocity.Y);
Y = _laserSprite.Y;
}
public override bool IsOffscreen(Window screen)
{
bool Offscreen = false;
if (_laserSprite.Offscreen())
{
Offscreen = true;
}
return Offscreen;
}
public override void freesprite()
{
SplashKit.FreeSprite(_laserSprite);
}
}