#include "bullet.h"
#define PI 3.1415926535897932384626433832795
void bullet::init(IDirect3DDevice8** g_pD3DDevice)
{
  this->b_img.Create(g_pD3DDevice,"d:\\media\\models\\bullet.x","d:\\");
  this->visible = false;
}

void bullet::MoveRel(float x, float y)
{
  this->b_img.MoveRel(x,y,0);
}

bool bullet::shoot(float angle, float x, float y)
{

	
	if(this->visible == true)
		return false;

	this->angle = angle;
	this->visible = true;
	 
	 x +=  ((-1*cos( angle ))*70);
     y += ((-1*sin( angle ))*70);

	this->b_img.MoveX(x);
	this->b_img.MoveY(y);
	
	return true;
}
bool bullet::render()
{
   float xpos, ypos;
   if(!this->visible)
	  return false;

   xpos = this->b_img.GetXpos();
   ypos = this->b_img.GetYpos();
      if(xpos < -704 || xpos > 708)
		 this->visible = false;

      if(ypos < -588 || ypos > 596)
		this->visible = false;

  b_img.MoveRel(-1*cos(this->angle )*5,-1*sin(this->angle)*5,0);
  this->b_img.Render(-1);
  
  return true;
}