-
Notifications
You must be signed in to change notification settings - Fork 1
/
Man.cs
95 lines (78 loc) · 1.54 KB
/
Man.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
using System;
using System.Drawing;
using System.Drawing.Drawing2D;
namespace SpaceInvaders
{
/// <summary>
/// Summary description for Man.
/// </summary>
public class Man : GameObject
{
private int kInterval = 5;
public bool Died = false;
public Man(): base(Images.man)
{
Position.X = 200;
Position.Y = 400;
}
public Point GetBulletStart()
{
Point theStart = new Point(
MovingBounds.Left + MovingBounds.Width/2,
MovingBounds.Top - 10);
return theStart;
}
int CountExplosion = 0;
Random RandomNumber = new Random((int)DateTime.Now.Ticks);
public void DrawExplosion(Graphics g)
{
CountExplosion++;
if (CountExplosion < 15)
{
for (int i = 0; i < 50; i++)
{
int xval = RandomNumber.Next(MovingBounds.Width);
int yval = RandomNumber.Next(MovingBounds.Height);
xval += Position.X;
yval += Position.Y;
g.DrawLine(Pens.Chartreuse, xval, yval, xval, yval+1);
}
}
}
public bool BeenHit = false;
public void MoveLeft()
{
Position.X -= kInterval;
if (Position.X < 0)
Position.X = 0;
}
public void MoveRight(int nLimit)
{
Position.X += kInterval;
if (Position.X > nLimit - Width )
Position.X = nLimit - Width;
}
public override void Draw(Graphics g)
{
if (Died)
return;
if (BeenHit == false)
{
base.Draw(g);
}
else
{
if (CountExplosion < 15)
DrawExplosion(g);
else
Died = true;
}
}
public void Reset()
{
BeenHit = false;
Died = false;
CountExplosion = 0;
}
}
}