#include "main.h"

/*
Constructor for the glow class.
*/
PART::PART( int _x, int _y, int _va, float _thrust, int _color ) {
  id = ID_PART;
  life = 50;
  x = _x-5+(random()%10);
  y = _y-5+(random()%10);
  z = y;
  xa = ((random()%7)-4)*0.20;
  ya = -3+random()%3;
  color = random()%256;
  fx = x;
  fy = y;
  /*
  x = _x;
  y = _y;
  va = _va;
  thrust = _thrust;
  color = random()%256;
  fx = x;
  fy = y;
  life = 0;
  xa = cos(grad360(va)) * thrust;
  ya = sin(grad360(va)) * thrust;
  */
  remove = false;
}

/*
Destructor for the glow class.
*/
PART::~PART() {
}

/*
Draw the glow effect.
*/
void PART::draw() {
  rotate_sprite(buffer, _wheel(life%16), x-16, y-16, itofix(color));
  /*
  color_map = &trans_table[2];
  drawing_mode(DRAW_MODE_TRANS, NULL, 0, 0);
  ellipsefill(buffer, x, z+10, 6, 3, 1);
  drawing_mode(DRAW_MODE_SOLID, NULL, 0, 0);
  color_map = &flare_table;
  */
}


/*
Performs any needed calculations.
*/
void PART::move() {
  /*
  fx += xa;
  fy += ya;
  if (fx > msx || fy > msy || fx < 0 || fy < 0)
    remove = true;
  x = (int)fx;
  y = (int)fy;
  if (life < 100+random()%30) life++;
    else {
      remove = true;
      elist.add(new EXPLO(x,y,48));
    }
  */
  fx += xa;
  fy += ya;
  x = (int)fx;
  y = (int)fy;
  ya = ya + 0.3;
  if (y > z+2 && ya>0) ya = -(ya*0.6);
  xa = xa * 0.96;
  if (life) life--;
    else {
      elist.add(new EXPLO(x,y,48));
      remove = true;
    }
}

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

/*
Glow particles need not be tested for collision.
*/
void PART::collide(ENTITY *other) {
}

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

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

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

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

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

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

int PART::get_owner() {
  return -1;
}

/* END */
