#include "StdAfx.h"
#include "PLAYER.h"


PLAYER::PLAYER(char Pla)
{
	Spirit = false;
	Erase	=	false;
	Live = true;
	Bomb = 1;
	Wave = 1;
	Col	=	new	IMAGE;
	Col->CreateImage(60,60);

	BombCol	=	new	IMAGE;
	BombCol->CreateImage(32,32);

	ImageDraw	=	new	IMAGE;

	if(Pla == 0)
	{
		Body	=	new	IMAGE[14];

		Body[0].LoadImageFromFile(L"Texture/Man/white_1.png");
		Body[1].LoadImageFromFile(L"Texture/Man/white_2.png");
		Body[2].LoadImageFromFile(L"Texture/Man/white_3.png");

		Body[3].LoadImageFromFile(L"Texture/Man/white_b_1.png");
		Body[4].LoadImageFromFile(L"Texture/Man/white_b_2.png");
		Body[5].LoadImageFromFile(L"Texture/Man/white_b_3.png");

		Body[6].LoadImageFromFile(L"Texture/Man/white_s_1.png");
		Body[7].LoadImageFromFile(L"Texture/Man/white_s_2.png");
		Body[8].LoadImageFromFile(L"Texture/Man/white_s_3.png");

		Body[9].LoadImageFromFile(L"Texture/Man/white_d_1.png");
		Body[10].LoadImageFromFile(L"Texture/Man/white_d_2.png");
		Body[11].LoadImageFromFile(L"Texture/Man/white_d_3.png");
		Body[12].LoadImageFromFile(L"Texture/Man/white_d_4.png");

	}

	if(Pla == 1)
	{
		Body	=	new	IMAGE[14];

		Body[0].LoadImageFromFile(L"Texture/Man/black_1.png");
		Body[1].LoadImageFromFile(L"Texture/Man/black_2.png");
		Body[2].LoadImageFromFile(L"Texture/Man/black_3.png");

		Body[3].LoadImageFromFile(L"Texture/Man/black_b_1.png");
		Body[4].LoadImageFromFile(L"Texture/Man/black_b_2.png");
		Body[5].LoadImageFromFile(L"Texture/Man/black_b_3.png");

		Body[6].LoadImageFromFile(L"Texture/Man/black_s_1.png");
		Body[7].LoadImageFromFile(L"Texture/Man/black_s_2.png");
		Body[8].LoadImageFromFile(L"Texture/Man/black_s_3.png");

		Body[9].LoadImageFromFile(L"Texture/Man/black_d_1.png");
		Body[10].LoadImageFromFile(L"Texture/Man/black_d_2.png");
		Body[11].LoadImageFromFile(L"Texture/Man/black_d_3.png");
		Body[12].LoadImageFromFile(L"Texture/Man/black_d_4.png");
	}

	(*ImageDraw) = (*Body);


	Imag = 0;
	Time = GetTickCount();
	Steep = 1;
	Speed = 2.5;
	MoveSpeed = 150;
}


PLAYER::~PLAYER(void)
{
}
void PLAYER::Draw(void)
{
	static int Steep1 = 0;

	if(Live)
	{
		if(Rot==2)
			ImageDraw->DrawMirror();
		else
			ImageDraw->Draw();
	}
	else
	{
		if(GetTickCount() > Time+MoveSpeed )
		{
			if(Steep1 > 3)
			{
				Erase = true;
				Steep1 = 0;
				ImageDraw->Texture = this->Body[0].Texture;
				return;
			}
			Time = GetTickCount();
			ImageDraw->Texture = this->Body[9+Steep1].Texture;
			Steep1++;

		}
		ImageDraw->Draw();
	}
}	


void PLAYER::SetPosition(float x,float y)
{
	Position.x = x;
	Position.y = y;
	ImageDraw->SetPosition(Position);

	Col->SetPosition(Position.x+1,Position.y+1);
	BombCol->SetPosition(Position.x+16,Position.y+16);
}	
bool	PLAYER::Collide(IMAGE	&Imag)
{
	 if(Col->Collide(Imag))
		 return true;
	 else
		 return false;

}

bool	PLAYER::BombCollide(IMAGE	&Imag)
{
	 if(BombCol->Collide(Imag))
		 return true;
	 else
		 return false;

}


void PLAYER::Move(MOVE Move)
{
	switch (Move)
	{
	case MLEFT:		
		if(Rot!=0)
			Imag = 6;

		if(GetTickCount() > Time+MoveSpeed ) 
		{
			Time = GetTickCount();
			if(Imag == 6)
				Steep = 1;

			if(Imag == 8)
				Steep = -1;

			Imag += Steep;
		}
		SetPosition(Position.x-Speed,Position.y);
		Rot = 0;		
		break;
	case MUP:
		if(Rot!=1)
			Imag = 3;

		if(GetTickCount() > Time+MoveSpeed ) 
		{
			Time = GetTickCount();
			if(Imag == 3)
				Steep = 1;

			if(Imag == 5)
				Steep = -1;

			Imag += Steep;
		}
		SetPosition(Position.x,Position.y-Speed);
		Rot =1;
		break;
	case MRIGHT:
		if(Rot!=2)
			Imag = 6;

		if(GetTickCount() > Time+MoveSpeed ) 
		{
			Time = GetTickCount();
			if(Imag == 6)
				Steep = 1;

			if(Imag == 8)
				Steep = -1;

			Imag += Steep;
		}

		SetPosition(Position.x+Speed,Position.y);
		Rot = 2;
		break;
	case MDOWN:
		if(Rot!=3)
			Imag = 0;

		if(GetTickCount() > Time+MoveSpeed ) 
		{
			Time = GetTickCount();
			if(Imag == 0)
				Steep = 1;

			if(Imag == 2)
				Steep = -1;

			Imag += Steep;
		}
		SetPosition(Position.x,Position.y+Speed);
		Rot = 3;
		break;
	}	
	ImageDraw->Texture = Body[Imag].Texture;
}