-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathExplosion.cs
74 lines (66 loc) · 2.29 KB
/
Explosion.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
using System;
using System.Drawing;
namespace Asteroids
{
/// <summary>
/// Summary description for Explosion.
/// </summary>
class Explosion : ScreenObject
{
const int NUM_EXP_POINTS = 22; // more points is more dazzling
const int EXPLOSION_LIFE = (int)FPS/2; // default life of explosion is 1/2 sec
int lifeLeft;
Point[] ptPoints;
Point[] ptPointsVelocity;
public Explosion(Point ptExplosion, double timeFactor) : base(ptExplosion)
{
lifeLeft = (int)(EXPLOSION_LIFE*timeFactor);
ptPoints = new Point[NUM_EXP_POINTS];
ptPointsVelocity = new Point[NUM_EXP_POINTS];
for (int i = 0; i<NUM_EXP_POINTS; i++)
{
ptPoints[i] = ptExplosion;
ptPointsVelocity[i] = new Point((int)((rndGen.Next(1200)-600)/FPS),
(int)((rndGen.Next(1200)-600)/FPS));
}
}
public override void InitPoints()
{
// Explosions are self-drawn
// so do not initialize points in the base class
}
public override bool Move()
{
if (lifeLeft > 0)
{
for (int i = 0; i<NUM_EXP_POINTS; i++)
{
ptPoints[i].X += ptPointsVelocity[i].X;
ptPoints[i].Y += ptPointsVelocity[i].Y;
if (ptPoints[i].X < 0)
ptPoints[i].X = iMaxX-1;
if (ptPoints[i].X >= iMaxX)
ptPoints[i].X = 0;
if (ptPoints[i].Y < 0)
ptPoints[i].Y = iMaxY-1;
if (ptPoints[i].Y >= iMaxY)
ptPoints[i].Y = 0;
}
lifeLeft -= 1;
return true;
}
else
return false;
}
public override void Draw(ScreenCanvas sc, int iPictX, int iPictY)
{
for (int i = 0; i<NUM_EXP_POINTS; i++)
{
Point ptDraw = new Point((int)(ptPoints[i].X / (double)iMaxX * iPictX),
(int)(ptPoints[i].Y / (double)iMaxY * iPictY));
Point ptDraw2 = new Point(ptDraw.X + 1, ptDraw.Y+1);
sc.AddLine(ptDraw, ptDraw2, GetRandomFireColor());
}
}
}
}