#include "StdAfx.h"
#include "Enemy.h"

int ENEMY::Count ;

vector<WALL>		*ENEMY::Map = NULL;
vector<BOMB>		*ENEMY::Bombs = NULL;
vector<IMAGE>		*ENEMY::BangWaves= NULL;


ENEMY::ENEMY(void)
{
	Collid.CreateImage(60,60);
	this->Collid.SetPosition(Position.x+16,Position.y+16);
	Count++;
	Rot = 2;
	Steep = 0;
	Time = GetTickCount();
	Erase = 0 ;
}
void	ENEMY::Flip(void)
{

}
void	ENEMY::Draw(void)
{
	if(Live == 0)
	{
		if(Time < GetTickCount()-150)
		{

			Time = GetTickCount();
			if(Erase <3)
				this->Pic.Texture = this->DeadRes[Erase].Texture;
			Erase++;
		}
	}
	else
	{
		if(Rot == MLEFT)
		{
			if(Time < GetTickCount()-250)
			{
				Time = GetTickCount();
				if(Steep != 4)
					Steep = 4;
				else
					Steep = 5;
				this->Pic.Texture = this->Res[Steep].Texture;
			}
		}
		else if(Rot == MUP)
		{
			if(Time < GetTickCount()-250)
			{
				Time = GetTickCount();
				if(Steep !=2)
					Steep = 2;
				else
					Steep = 3;
				this->Pic.Texture = Res[Steep].Texture;
			}
		}
			
		
		else if(Rot == MRIGHT)
		{
			if(Time < GetTickCount()-250)
			{
				Time = GetTickCount();
				if(Steep !=4)
					Steep = 4;
				else
					Steep = 5;
				this->Pic.Texture = this->Res[Steep].Texture;
			}
		}
		else if(Rot == MDOWN)
		{
			if(Time < GetTickCount()-250)
			{
				Time = GetTickCount();
				if(Steep != 0)
					Steep = 0;
				else
					Steep = 1;
				this->Pic.Texture = this->Res[Steep].Texture;
			}
		}
	}

	if(Rot != MLEFT)
		Pic.Draw();
	else
		Pic.DrawMirror();

	return;
	
}
void	ENEMY::SetPosition(float X,float Y) 
{
	if(Live)
	{
		this->Position.x = X;
		this->Position.y = Y;

		this->Pic.SetPosition(Position);
		this->Collid.SetPosition(X+2,Y+2);
	}
}

void	ENEMY::Dead(void)
{
	for(int g =0;g<(int)BangWaves->size();g++)		
		if((*BangWaves)[g].Collide(this->Pic))
			this->Live = false;
}


ENEMY::~ENEMY(void)
{
	Collid.Texture->Release();
	Count--;
}
