-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgun.h
134 lines (114 loc) · 3.72 KB
/
gun.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
#define GUN_SIZE 2
#define GUN_MIN_DIFF 12
#define GUN_MAXIMUM_PROJECTILES 120 / (GUN_SIZE + GUN_MIN_DIFF)
#define GUN_DAMAGE 1
struct GunShoot
{
public:
byte x = 0;
byte y = 0;
bool visible = false;
void reset()
{
x = 0;
y = 0;
visible = false;
}
};
struct GunShootItem
{
public:
GunShoot gunshoottop;
GunShoot gunshootbottom;
void reset()
{
gunshoottop.reset();
gunshootbottom.reset();
}
};
class Gun
{
private:
uint16_t canshoot = 0;
GunShootItem gun_shoots[GUN_MAXIMUM_PROJECTILES];
public:
void shoot(byte x, byte y)
{
if (canshoot == 0)
{
canshoot = arduboy.frameCount;
GunShootItem gunshootitem;
gunshootitem.gunshoottop.x = x;
gunshootitem.gunshoottop.y = y;
gunshootitem.gunshoottop.visible = true;
gunshootitem.gunshootbottom.x = x;
gunshootitem.gunshootbottom.y = y + 7;
gunshootitem.gunshootbottom.visible = true;
for (int i = GUN_MAXIMUM_PROJECTILES - 1; i > 0; i--)
gun_shoots[i] = gun_shoots[i - 1];
gun_shoots[0] = gunshootitem;
}
}
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;
if (gun_shoots[i].gunshoottop.x > 127)
gun_shoots[i].gunshoottop.visible = false;
}
if (gun_shoots[i].gunshootbottom.visible)
{
gun_shoots[i].gunshootbottom.x += 2;
if (gun_shoots[i].gunshootbottom.x > 127)
gun_shoots[i].gunshootbottom.visible = false;
}
}
}
void draw()
{
for (int i = 0; i < GUN_MAXIMUM_PROJECTILES; i++)
{
if (gun_shoots[i].gunshoottop.visible)
arduboy.drawFastHLine(gun_shoots[i].gunshoottop.x, gun_shoots[i].gunshoottop.y, GUN_SIZE, 1);
if (gun_shoots[i].gunshootbottom.visible)
arduboy.drawFastHLine(gun_shoots[i].gunshootbottom.x, gun_shoots[i].gunshootbottom.y, GUN_SIZE, 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].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;
}
}
}
}
}
};