#include "main.h"

/*
Constructor for the bullet class.
*/
BULLET::BULLET( int _x, int _y, int _va, int _color ) {
  id = ID_BULLET;
  x = _x;
  y = _y;
  va = _va;
  fx = x;
  fy = y;
  life = 50;
  xa = cos(grad360(va)) * 10;
  ya = sin(grad360(va)) * 10;
  color = _color;
  damage = 10;
  pressure = true;
  remove = false;  
}

/*
Destructor for the bullet class.
*/
BULLET::~BULLET() {
}

/*
Draws the bullet.
*/
void BULLET::draw() {
  int num = color ? 1 : 0;
  drawing_mode(DRAW_MODE_TRANS, NULL, 0, 0);
  draw_trans_sprite(buffer, (BITMAP *)gfxdata[FLARE1_BMP+2].dat, x-24, y-24);
  draw_trans_sprite(buffer, _firedata(life%10,num), x-16, y-16);
  drawing_mode(DRAW_MODE_SOLID, NULL, 0, 0);
}

/*
Performs any needed calculates.
*/
void BULLET::move() {
  fx += xa;
  fy += ya;
  x = (int)fx;
  y = (int)fy;
  if (fx > msx || fy > msy || fx < 0 || fy < 0)
    remove = true;
  if (life) life--;
    else
      remove = true;
}

/*
Returns true if the entity can be removed from the list.
*/
bool BULLET::done() {
  return remove;
}

/*
Collision detection method.
Handles any collision their might be between this entity and the given
entity.
*/
void BULLET::collide(ENTITY *other) {
  if (other != this) {
    if ( abs(other->get_x() - x) < 15 &&
         abs(other->get_y() - y) < 15 ) {
//      if () {
//        elist.add(new EXPLO(x,y,40));
//        remove = true;
//      }
      if (other->get_id() == ID_BUGGY) {
        if (color != other->get_owner()) {
          elist.add(new EXPLO(x,y,40));
          remove = true;
        }
      }
    }
  }
}

/*
Returns true if this bullet applies pressure when colliding.
*/
bool BULLET::get_pressure() {
  return pressure;
}

/*
Returns the damage done on impact.
*/
int BULLET::get_damage() {
  return damage;
}

/*
Get functions to allow access to private data inside the class.
*/
int BULLET::get_x() {
  return x;
}

int BULLET::get_y() {
  return y;
}

int BULLET::get_id() {
  return id;
}

int BULLET::get_va() {
  return va;
}

float BULLET::get_xa() {
  return xa;
}

float BULLET::get_ya() {
  return ya;
}

int BULLET::get_owner() {
  return color;
}

/* END */
