-
Notifications
You must be signed in to change notification settings - Fork 1
/
Bullet.cs
50 lines (45 loc) · 1.57 KB
/
Bullet.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
using System.Windows.Forms;
namespace SpaceInvaders
{
public class Bullet : GameEntity
{
//constructor for bullet class
public Bullet(Form Form)
{
//create picturebox for player bullet
picEntity = new PictureBox();
picEntity.Size = new System.Drawing.Size(2, 60);
picEntity.BackColor = System.Drawing.Color.Red;
picEntity.Location = new System.Drawing.Point(List.player.picEntity.Left + List.player.picEntity.Width / 2, List.player.picEntity.Top - 60);
//add player bullet to game form
this.Form = Form;
this.Form.Controls.Add(picEntity);
//set velocity of bullet to 35
Velocity = 35;
}
public override void Destroy()
{
//dispose PLAYER BULLET
picEntity.Visible = false;
picEntity.Dispose();
}
public override void Update()
{
//move player bullet
if (picEntity.Top > 0) picEntity.Top -= Velocity;
else Destroy();
//loop through each enemy to check if player bullet intersects with one of them
foreach (Enemy Invader in List.Enemies)
{
if (Invader.picEntity.Visible && this.Bounds.IntersectsWith(Invader.Bounds))
{
Destroy();
Invader.Destroy();
Sound.ChangeSound2URL("thunk.wav");
Sound.PlaySound2();
return;
}
}
}
}
}