-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathBullet.cs
More file actions
69 lines (56 loc) · 1.63 KB
/
Bullet.cs
File metadata and controls
69 lines (56 loc) · 1.63 KB
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
using System;
using System.Drawing;
using System.Drawing.Drawing2D;
namespace SpaceInvaders
{
/// <summary>
/// Represents a missile fired at the Invaders
/// </summary>
[System.Diagnostics.DebuggerDisplay("Bullet Position={Position}")]
public class Bullet : GameObject
{
const int kBulletInterval = 20;
public int BulletInterval = kBulletInterval;
private bool IsReset = false;
public Bullet(int x, int y)
{
ImageBounds.Width = 5;
ImageBounds.Height = 15;
Position.X = x;
Position.Y = y;
}
public void Reset()
{
this.IsReset = true;
if (Mainform.ActiveForm != null)
{
Mainform.ActiveForm.Paint += new System.Windows.Forms.PaintEventHandler(OnActiveFormPaint);
}
BulletInterval = kBulletInterval;
}
void OnActiveFormPaint(object sender, System.Windows.Forms.PaintEventArgs e)
{
if (Mainform.ActiveForm != null)
{
Mainform.ActiveForm.Paint -= new System.Windows.Forms.PaintEventHandler(OnActiveFormPaint);
e.Graphics.FillRectangle(Brushes.Black, this.MovingBounds);
}
}
public void Slow()
{
// BulletInterval = 3;
}
public override void Draw(Graphics g)
{
if (this.IsReset || g == null) return;
UpdateBounds();
g.FillRectangle(Brushes.Chartreuse , MovingBounds);
Position.Y -= BulletInterval;
}
public Rectangle GetCollisionBounds()
{
Rectangle rect = this.GetBounds();
return new Rectangle(new Point(rect.Location.X, rect.Location.Y - rect.Height), new Size(rect.Width, rect.Height * 2));
}
}
}