-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathbullet.cpp
More file actions
43 lines (32 loc) · 823 Bytes
/
bullet.cpp
File metadata and controls
43 lines (32 loc) · 823 Bytes
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
#include "bullet.h"
Bullet::Bullet(int x, int y, ALLEGRO_BITMAP *texture, bool shipBullet, Rectangle bounds) {
_container.setX(x);
_container.setY(y);
_container.setW(10);
_container.setH(20);
_alive = true;
_texture = texture;
_shipBullet = shipBullet;
_bounds = bounds;
}
Bullet::~Bullet() {
}
int Bullet::move() {
if (_shipBullet) {
_container.setY(_container.getY() - _moveSpeed);
} else {
_container.setY(_container.getY() + _moveSpeed / 2);
}
return _container.getY();
}
void Bullet::update(unsigned int ticks) {
move();
if ((_container.getY() < 0 && _shipBullet) || (_container.getY() > _bounds.getY() + _bounds.getH())) {
_alive = false;
}
}
void Bullet::render() {
if (_alive) {
al_draw_bitmap(_texture, _container.getX(), _container.getY(), NULL);
}
}