You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
57 lines
952 B
C++
57 lines
952 B
C++
6 years ago
|
#include "bullet.h"
|
||
|
|
||
6 years ago
|
Bullet::Bullet(Behavior _behavior) {
|
||
|
behavior = _behavior;
|
||
6 years ago
|
//Build properties based on behavior
|
||
6 years ago
|
switch (behavior) {
|
||
|
case Enemy:
|
||
|
speed = 1.0;
|
||
|
height = 20;
|
||
|
width = 5;
|
||
|
break;
|
||
|
default:
|
||
|
speed = 1.0;
|
||
|
height = 20;
|
||
|
width = 5;
|
||
|
break;
|
||
|
}
|
||
|
|
||
6 years ago
|
oob = false;
|
||
6 years ago
|
}
|
||
|
|
||
|
void Bullet::reset_pos(float x, float y) {
|
||
|
x_pos = x;
|
||
|
y_pos = y;
|
||
|
}
|
||
|
|
||
|
void Bullet::draw() {
|
||
6 years ago
|
if (!oob) {
|
||
6 years ago
|
al_draw_filled_rectangle(x_pos, y_pos, x_pos + width, y_pos + height, al_map_rgb(255, 255, 255));
|
||
6 years ago
|
}
|
||
6 years ago
|
}
|
||
|
|
||
|
void Bullet::move(Direction dir) {
|
||
6 years ago
|
switch (dir) {
|
||
|
case U:
|
||
|
y_pos -= 6;
|
||
|
break;
|
||
|
case D:
|
||
|
y_pos += 6;
|
||
|
break;
|
||
|
}
|
||
6 years ago
|
//Only player bullets are used currently so only player bullet bound is checked
|
||
6 years ago
|
if (y_pos < 0 - height) {
|
||
|
oob = true;
|
||
|
}
|
||
6 years ago
|
}
|
||
|
|
||
|
Hitbox Bullet::get_hitbox()
|
||
|
{
|
||
|
Hitbox hitbox;
|
||
|
hitbox.x = x_pos;
|
||
|
hitbox.y = y_pos;
|
||
|
hitbox.width = width;
|
||
|
hitbox.height = height;
|
||
|
return hitbox;
|
||
|
}
|