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++
#include "bullet.h"
|
|
|
|
Bullet::Bullet(Behavior _behavior) {
|
|
behavior = _behavior;
|
|
//Build properties based on behavior
|
|
switch (behavior) {
|
|
case Enemy:
|
|
speed = 1.0;
|
|
height = 20;
|
|
width = 5;
|
|
break;
|
|
default:
|
|
speed = 1.0;
|
|
height = 20;
|
|
width = 5;
|
|
break;
|
|
}
|
|
|
|
oob = false;
|
|
}
|
|
|
|
void Bullet::reset_pos(float x, float y) {
|
|
x_pos = x;
|
|
y_pos = y;
|
|
}
|
|
|
|
void Bullet::draw() {
|
|
if (!oob) {
|
|
al_draw_filled_rectangle(x_pos, y_pos, x_pos + width, y_pos + height, al_map_rgb(255, 255, 255));
|
|
}
|
|
}
|
|
|
|
void Bullet::move(Direction dir) {
|
|
switch (dir) {
|
|
case U:
|
|
y_pos -= 6;
|
|
break;
|
|
case D:
|
|
y_pos += 6;
|
|
break;
|
|
}
|
|
//Only player bullets are used currently so only player bullet bound is checked
|
|
if (y_pos < 0 - height) {
|
|
oob = true;
|
|
}
|
|
}
|
|
|
|
Hitbox Bullet::get_hitbox()
|
|
{
|
|
Hitbox hitbox;
|
|
hitbox.x = x_pos;
|
|
hitbox.y = y_pos;
|
|
hitbox.width = width;
|
|
hitbox.height = height;
|
|
return hitbox;
|
|
}
|