-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWeapon.cs
88 lines (76 loc) · 3.51 KB
/
Weapon.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
using System;
using System.Windows;
namespace Paratrooper2049
{
internal class Weapon : BaseObject
{
//Bullet
public Weapon(Point center, double direction, double formW, double formH)
{
_direction = direction;
_speed = 10;
_description = gameObject.Bullet;
_vertices.Add(RotateObject(new Point(center.X, center.Y - 35), center, direction));
_vertices.Add(RotateObject(new Point(center.X + 1, center.Y - 35 - 1), center, direction));
_vertices.Add(RotateObject(new Point(center.X, center.Y - 35 - 4), center, direction));
_vertices.Add(RotateObject(new Point(center.X - 1, center.Y - 35 - 1), center, direction));
_battleField.Add(new Point(-5, -5));
_battleField.Add(new Point(formW + 5, -5));
_battleField.Add(new Point(formW + 5, formH + 5));
_battleField.Add(new Point(-5, formH + 5));
}
//Laser Beam
public Weapon(Point center, double direction)
{
_direction = direction;
_speed = 255;
_description = gameObject.Laser;
_vertices.Add(RotateObject(new Point(center.X + 1, center.Y - 35), center, direction));
_vertices.Add(RotateObject(new Point(center.X + 1, center.Y - 35 - 10000), center, direction));
_vertices.Add(RotateObject(new Point(center.X - 1, center.Y - 35 - 10000), center, direction));
_vertices.Add(RotateObject(new Point(center.X - 1, center.Y - 35), center, direction));
}
//cluster bomb
public Weapon(Point center, double direction, double formW, double formH, bool missile)
{
_direction = direction;
_speed = 5;
_description = gameObject.Cluster;
_vertices.Add(RotateObject(new Point(center.X, center.Y - 35), center, direction));
_vertices.Add(RotateObject(new Point(center.X + 5, center.Y - 35 - 4), center, direction));
_vertices.Add(RotateObject(new Point(center.X, center.Y - 35 - 10), center, direction));
_vertices.Add(RotateObject(new Point(center.X - 5, center.Y - 35 - 4), center, direction));
_battleField.Add(new Point(formW / 4, formH / 4));
_battleField.Add(new Point(formW / 4 * 3, formH / 4));
_battleField.Add(new Point(formW / 4 * 3, formH + 5));
_battleField.Add(new Point(formW / 4, formH + 5));
}
public void UpdatePosition()
{
if (_description == gameObject.Bullet)
{
for (int i = 0; i < _vertices.Count; i++)
{
_vertices[i] = new Point(_vertices[i].X + _speed * Math.Sin(_direction), _vertices[i].Y - _speed * Math.Cos(_direction));
}
if (!IntersectObject(_vertices, _battleField)) _lastFrame = true;
}
else if (_description == gameObject.Laser)
{
_speed -= 15;
if (_speed < 0) _lastFrame = true;
}
else if (_description == gameObject.Cluster)
{
for (int i = 0; i < _vertices.Count; i++)
{
_vertices[i] = new Point(_vertices[i].X + _speed * Math.Sin(_direction), _vertices[i].Y - _speed * Math.Cos(_direction));
}
if (!IntersectObject(_vertices, _battleField))
{
_lastFrame = true;
}
}
}
}
}