-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbullet.cpp
67 lines (63 loc) · 1.52 KB
/
bullet.cpp
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
#include <cstdlib>
#include <raylib.h>
#include "bullet.h"
Bullet::Bullet(int _y, int _x, Direction _dir){
y = _y;
x = _x;
speed = 8;
dir = _dir;
collision = false;
}
void Bullet::update(Level & lvl){
switch (dir){
case STOP:
break;
case LEFT:
if (lvl[y/64][(x - radius)/64] != 0 || x - radius <= 0) {
collision = true;
}
else{
collision = false;
x -= speed;
}
break;
case RIGHT:
if (lvl[y/64][(x + radius)/64] != 0) {
collision = true;
}
else{
collision = false;
x += speed;
}
break;
case UP:
if (lvl[(y - radius)/64][x/64] != 0){
collision = true;
}
else{
collision = false;
y -= speed;
}
break;
case DOWN:
if (lvl[(y + radius)/64][x/64] != 0){
collision = true;
}
else{
collision = false;
y += speed;
}
break;
}
if (!collision){
DrawCircle(x, y, radius, BROWN);
}
}
void BulletList::update(Level &lvl){
while(bullet_l.begin()->get_collision() == true){
bullet_l.pop_front();
}
for (std::list<Bullet>::iterator it = bullet_l.begin(); it != bullet_l.end(); it ++){
(*it).update(lvl);
}
}