-
Notifications
You must be signed in to change notification settings - Fork 0
/
Barrier.cs
140 lines (130 loc) · 5.93 KB
/
Barrier.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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
using SquareGraphics;
namespace KosmiczniNajeźdźcy
{
internal class Barrier : Entity
{
static string graphicStr = "0\t0\t0\t0\t1\t1\t1\t1\t1\t1\t1\t1\t1\t1\t1\t1\t0\t0\t0\t0\r\n0\t0\t0\t1\t1\t1\t1\t1\t1\t1\t1\t1\t1\t1\t1\t1\t1\t0\t0\t0\r\n0\t0\t1\t1\t1\t1\t1\t1\t1\t1\t1\t1\t1\t1\t1\t1\t1\t1\t0\t0\r\n0\t1\t1\t1\t1\t1\t1\t1\t1\t1\t1\t1\t1\t1\t1\t1\t1\t1\t1\t0\r\n1\t1\t1\t1\t1\t1\t1\t1\t1\t1\t1\t1\t1\t1\t1\t1\t1\t1\t1\t1\r\n1\t1\t1\t1\t1\t1\t1\t1\t1\t1\t1\t1\t1\t1\t1\t1\t1\t1\t1\t1\r\n1\t1\t1\t1\t1\t1\t1\t1\t1\t1\t1\t1\t1\t1\t1\t1\t1\t1\t1\t1\r\n1\t1\t1\t1\t1\t1\t1\t1\t1\t1\t1\t1\t1\t1\t1\t1\t1\t1\t1\t1\r\n1\t1\t1\t1\t1\t1\t1\t1\t1\t1\t1\t1\t1\t1\t1\t1\t1\t1\t1\t1\r\n1\t1\t1\t1\t1\t1\t1\t1\t1\t1\t1\t1\t1\t1\t1\t1\t1\t1\t1\t1\r\n1\t1\t1\t1\t1\t1\t1\t1\t1\t1\t1\t1\t1\t1\t1\t1\t1\t1\t1\t1\r\n1\t1\t1\t1\t1\t1\t1\t1\t1\t1\t1\t1\t1\t1\t1\t1\t1\t1\t1\t1\r\n1\t1\t1\t1\t1\t1\t1\t0\t0\t0\t0\t0\t0\t1\t1\t1\t1\t1\t1\t1\r\n1\t1\t1\t1\t1\t1\t0\t0\t0\t0\t0\t0\t0\t0\t1\t1\t1\t1\t1\t1\r\n1\t1\t1\t1\t1\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\t1\t1\t1\t1\t1\r\n1\t1\t1\t1\t1\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\t1\t1\t1\t1\t1\r\n";
public static readonly Color color = Color.Lime;
public Barrier(Point pos, int pixelSize) : base(pos, pixelSize, false, SquareGraphic.GetFromString(graphicStr, color, pixelSize))
{
}
public override int ReciveDamage(int bulletX, int bulletY)
{
ExplodeABit(bulletX, bulletY);
return 1;
}
/// <summary>
/// Makes parts of graphics transparent to show damage to barrier
/// </summary>
/// <param name="x">X where bullet hit</param>
/// <param name="y">Y where bullet hit</param>
/// <param name="inverted">Normal is bullet from the top</param>
void ExplodeABit(int x, int y)
{
const int holeY = 5, holeX = 2;
DoUndraw = true;
bool inverted = false;
if (y > Pos.Y + 3)
{
inverted = true;
}
int squareX = 0, squareY = 0;
for (int i = 0; i < Graphic.squares.Count(); i++)
{
for (int j = 0; j < Graphic.squares[i].Count(); j++)
{
if (Graphic.squares[i][j].Color != Color.Transparent && Graphic.squares[i][j].isInBounds(x, y, Pos.X, Pos.Y))
{
squareX = j;
squareY = i;
}
}
}
Random random = new Random();
int multiplayer = 1;
if (inverted) // if inverted change sign of operations
{
multiplayer = -1;
}
for (int yDelta = -2; yDelta <= holeY; yDelta++) // iterate through standard explosion hole
{
for (int xDelta = holeX * -1; xDelta <= holeX; xDelta++)
{
DamageGraphic(squareX + (xDelta * multiplayer), squareY + (yDelta * multiplayer) + 1);
}
}
for (int yDelta = 0; yDelta <= holeY; yDelta++) // iterate through walls
{
if (random.Next(0, 100) > 30)//left wall-1
{
DamageGraphic(squareX - holeX - 1, squareY + (yDelta * multiplayer) + 1);
}
if (random.Next(0, 100) > 60)//left wall-2
{
DamageGraphic(squareX - holeX - 2, squareY + (yDelta * multiplayer) + 1);
}
if (random.Next(0, 100) > 85)//left wall-3
{
DamageGraphic(squareX - holeX - 3, squareY + (yDelta * multiplayer) + 1);
}
if (random.Next(0, 100) > 30)//right wall+1
{
DamageGraphic(squareX + holeX + 1, squareY + (yDelta * multiplayer) + 1);
}
if (random.Next(0, 100) > 60)//right wall+2
{
DamageGraphic(squareX + holeX + 2, squareY + (yDelta * multiplayer) + 1);
}
if (random.Next(0, 100) > 85)//right wall+3
{
DamageGraphic(squareX + holeX + 3, squareY + (yDelta * multiplayer) + 1);
}
}
int multiplayer2 = 1;
if (!inverted)
{
multiplayer2 = 0;
}
for (int xDelta = holeX * -1; xDelta <= holeX; xDelta++)// damage the top
{
if (random.Next(0, 100) > 30)
{
DamageGraphic(squareX + xDelta, squareY - holeY * multiplayer2 + 1 + 1 * multiplayer);
}
if (random.Next(0, 100) > 60)
{
DamageGraphic(squareX + xDelta, squareY - holeY * multiplayer2 + 1 + 2 * multiplayer);
}
if (random.Next(0, 100) > 85)
{
DamageGraphic(squareX + xDelta, squareY - holeY * multiplayer2 + 1 + 2 * multiplayer);
}
}
}
void DamageGraphic(int x, int y)
{
if (x >= 0 && x < Graphic.squares[0].Count && y >= 0 && y < Graphic.squares.Count)
{
Graphic.squares[y][x].Color = Color.Transparent;
}
}
public override bool IsAt(int x, int y)
{
if (!colliderEnabled)
{
return false;
}
for (int i = 0; i < Graphic.squares.Count(); i++)
{
for (int j = 0; j < Graphic.squares[i].Count(); j++)
{
if (Graphic.squares[i][j].Color != Color.Transparent && Graphic.squares[i][j].isInBounds(x, y, Pos.X, Pos.Y)) // if target pixel not transpartent (abscent) and is there
{
return true;
}
}
}
return false;
}
}
}