-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgun_split.h
149 lines (124 loc) · 4.9 KB
/
gun_split.h
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
141
142
143
144
145
146
147
struct GunSplitShootItem
{
public:
GunShoot gunshoottop;
GunShoot gunshootmiddle;
GunShoot gunshootbottom;
void reset()
{
gunshoottop.reset();
gunshootmiddle.reset();
gunshootbottom.reset();
}
};
class GunSplit
{
private:
bool top = true;
uint16_t canshoot = 0;
GunSplitShootItem gun_shoots[GUN_MAXIMUM_PROJECTILES];
public:
void shoot(byte x, byte y)
{
if (canshoot == 0)
{
canshoot = arduboy.frameCount;
GunSplitShootItem gunsplitshootitem;
gunsplitshootitem.gunshoottop.x = x;
gunsplitshootitem.gunshoottop.y = y;
gunsplitshootitem.gunshoottop.visible = true;
gunsplitshootitem.gunshootmiddle.x = x;
if (top)
gunsplitshootitem.gunshootmiddle.y = y + 4;
else
gunsplitshootitem.gunshootmiddle.y = y + 3;
gunsplitshootitem.gunshootmiddle.visible = true;
top = !top;
gunsplitshootitem.gunshootbottom.x = x;
gunsplitshootitem.gunshootbottom.y = y + 7;
gunsplitshootitem.gunshootbottom.visible = true;
for (int i = GUN_MAXIMUM_PROJECTILES - 1; i > 0; i--)
gun_shoots[i] = gun_shoots[i - 1];
gun_shoots[0] = gunsplitshootitem;
}
}
void update()
{
if (canshoot != 0)
if (arduboy.frameCount - canshoot >= GUN_MIN_DIFF)
canshoot = 0;
for (int i = 0; i < GUN_MAXIMUM_PROJECTILES; i++)
{
if (gun_shoots[i].gunshoottop.visible)
{
gun_shoots[i].gunshoottop.x += 2;
gun_shoots[i].gunshoottop.y -= 1;
if (gun_shoots[i].gunshoottop.x > 128)
gun_shoots[i].gunshoottop.visible = false;
}
if (gun_shoots[i].gunshootmiddle.visible)
{
gun_shoots[i].gunshootmiddle.x += 2;
if (gun_shoots[i].gunshootmiddle.x > 128)
gun_shoots[i].gunshootmiddle.visible = false;
}
if (gun_shoots[i].gunshootbottom.visible)
{
gun_shoots[i].gunshootbottom.x += 2;
gun_shoots[i].gunshootbottom.y += 1;
if (gun_shoots[i].gunshootbottom.x > 128)
gun_shoots[i].gunshootbottom.visible = false;
}
}
}
void draw()
{
for (int i = 0; i < GUN_MAXIMUM_PROJECTILES; i++)
{
if (gun_shoots[i].gunshoottop.visible)
arduboy.drawLine(gun_shoots[i].gunshoottop.x, gun_shoots[i].gunshoottop.y, gun_shoots[i].gunshoottop.x + GUN_SIZE - 1, gun_shoots[i].gunshoottop.y - 1, 1);
if (gun_shoots[i].gunshootmiddle.visible)
arduboy.drawFastHLine(gun_shoots[i].gunshootmiddle.x, gun_shoots[i].gunshootmiddle.y, GUN_SIZE, 1);
if (gun_shoots[i].gunshootbottom.visible)
arduboy.drawLine(gun_shoots[i].gunshootbottom.x, gun_shoots[i].gunshootbottom.y, gun_shoots[i].gunshootbottom.x + GUN_SIZE - 1, gun_shoots[i].gunshootbottom.y + 1, 1);
}
}
void clr()
{
for (int i = 0; i < GUN_MAXIMUM_PROJECTILES; i++)
gun_shoots[i].reset();
}
void checkcollisions(EnemyManager &enemym, ExplosionManager &explosionm)
{
for (int i = 0; i < GUN_MAXIMUM_PROJECTILES; i++)
{
for (int j = 0; j < MAX_ENEMY_ON_STAGE; j++)
{
if ((enemym.enemies[j].enemystatus & 0b00001000) == 0b00001000)
{
if (gun_shoots[i].gunshoottop.visible)
if (checkhitbox(gun_shoots[i].gunshoottop.x, gun_shoots[i].gunshoottop.y, GUN_SIZE, 1, enemym.enemies[j].x + enemym.enemies[j].hitboxXPadding, enemym.enemies[j].y + enemym.enemies[j].hitboxYPadding, enemym.enemies[j].hitboxWidth, enemym.enemies[j].hitboxHeight))
{
byte damage = 1;
enemym.damageenemy(enemym.enemies[j], damage, explosionm);
gun_shoots[i].gunshoottop.visible = false;
}
if (gun_shoots[i].gunshootmiddle.visible)
if (checkhitbox(gun_shoots[i].gunshootmiddle.x, gun_shoots[i].gunshootmiddle.y, GUN_SIZE, 1, enemym.enemies[j].x + enemym.enemies[j].hitboxXPadding, enemym.enemies[j].y + enemym.enemies[j].hitboxYPadding, enemym.enemies[j].hitboxWidth, enemym.enemies[j].hitboxHeight))
{
byte damage = 1;
enemym.damageenemy(enemym.enemies[j], damage, explosionm);
gun_shoots[i].gunshootmiddle.visible = false;
}
if (gun_shoots[i].gunshootbottom.visible)
if (checkhitbox(gun_shoots[i].gunshootbottom.x, gun_shoots[i].gunshootbottom.y, GUN_SIZE, 1, enemym.enemies[j].x + enemym.enemies[j].hitboxXPadding, enemym.enemies[j].y + enemym.enemies[j].hitboxYPadding, enemym.enemies[j].hitboxWidth, enemym.enemies[j].hitboxHeight))
{
byte damage = 1;
enemym.damageenemy(enemym.enemies[j], damage, explosionm);
gun_shoots[i].gunshootbottom.visible = false;
}
}
}
}
}
};