#include "StdAfx.h"
#include "PLAY.h"

extern int STATUS;

using namespace std;
PLAY::PLAY(INPUT_DX *Input,DIRECTX *Direct)
{
	sample=BASS_SampleLoad(FALSE,L"Music/Bang.ogg",NULL,FALSE,1,BASS_SAMPLE_SOFTWARE);

	ch = BASS_SampleGetChannel(sample,TRUE);

//	BASS_ChannelSetAttribute(ch,BASS_ATTRIB_VOL,0.1f);

	Exit	=	new	BONUS;

	Exit->LoadImageFromFile(L"Texture/teleport.png");


	Level = 1;

	ENEMY::BangWaves = &(this->BangWaves);
	ENEMY::Map	=	&(this->Map);
	ENEMY::Bombs =	&(this->Bombs);


	EnemyC	=	new	ENEMYCREAT();

	this->Direct  = Direct;
	Screen	=	new	IMAGE();

	Screen->CreateImage(5000,5000);
	Screen->SoursBlend = 3;
	BangWave	=	new	IMAGE();
	BangWave->CreateImage(56,56);
	Player	=	new	PLAYER(0);


	Bang	=	new	BANG;


	Bomb	=	new	BOMB;

	BackRes	=	new	IMAGE[12];
	BackRes[0].LoadImageFromFile(L"Texture/Tile/gras_1.png");
	BackRes[1].LoadImageFromFile(L"Texture/Tile/gras_2.png");
	BackRes[2].LoadImageFromFile(L"Texture/Tile/gras_3.png");
	BackRes[3].LoadImageFromFile(L"Texture/Tile/gras_4.png");


	BackRes[4].LoadImageFromFile(L"Texture/Tile/ground_1.png");
	BackRes[5].LoadImageFromFile(L"Texture/Tile/ground_2.png");
	BackRes[6].LoadImageFromFile(L"Texture/Tile/ground_3.png");
	BackRes[7].LoadImageFromFile(L"Texture/Tile/ground_4.png");

	BackRes[8].LoadImageFromFile(L"Texture/Tile/metall_1.png");
	BackRes[9].LoadImageFromFile(L"Texture/Tile/metall_2.png");
	BackRes[10].LoadImageFromFile(L"Texture/Tile/metall_3.png");
	BackRes[11].LoadImageFromFile(L"Texture/Tile/metall_4.png");

	ResBon	=	new	BONUS[5];

	ResBon[0].LoadImageFromFile(L"Texture/Bonus/bonus_bomb.png");
	ResBon[0].Type = 1;

	ResBon[1].LoadImageFromFile(L"Texture/Bonus/bonus_fire.png");
	ResBon[1].Type = 2;

	ResBon[2].LoadImageFromFile(L"Texture/Bonus/bonus_spide.png");
	ResBon[2].Type = 3;

	ResBon[3].LoadImageFromFile(L"Texture/Bonus/bonus_go.png");
	ResBon[3].Type = 4;

	ResBon[4].LoadImageFromFile(L"Texture/Bonus/bonus_pult.png");
	ResBon[4].Type = 5;

	this->Input = Input;
	Res	=	new	WALL[6];

	Res[0].LoadImageFromFile(L"Texture/Tile/box_2.png");
	Res[0].Type = 1;
	Res[1].LoadImageFromFile(L"Texture/Tile/box.png");
	Res[1].Type = 0;

	Res[2].LoadImageFromFile(L"Texture/Tile/rock_2.png");
	Res[2].Type = 1;
	Res[3].LoadImageFromFile(L"Texture/Tile/tern.png");
	Res[3].Type = 0;

	Res[4].LoadImageFromFile(L"Texture/Tile/rock.png");
	Res[4].Type = 1;
	Res[5].LoadImageFromFile(L"Texture/Tile/plant.png");
	Res[5].Type = 0;


	ResBreak	=	new	IMAGE[12];
	ResBreak[0].LoadImageFromFile(L"Texture/Break/tern_b1.png");
	ResBreak[1].LoadImageFromFile(L"Texture/Break/tern_b2.png");
	ResBreak[2].LoadImageFromFile(L"Texture/Break/tern_b3.png");
	ResBreak[3].LoadImageFromFile(L"Texture/Break/tern_b4.png");

	ResBreak[4].LoadImageFromFile(L"Texture/Break/plant_b1.png");
	ResBreak[5].LoadImageFromFile(L"Texture/Break/plant_b2.png");
	ResBreak[6].LoadImageFromFile(L"Texture/Break/plant_b3.png");
	ResBreak[7].LoadImageFromFile(L"Texture/Break/plant_b4.png");

	ResBreak[8].LoadImageFromFile(L"Texture/Break/box_b1.png");
	ResBreak[9].LoadImageFromFile(L"Texture/Break/box_b2.png");
	ResBreak[10].LoadImageFromFile(L"Texture/Break/box_b3.png");
	ResBreak[11].LoadImageFromFile(L"Texture/Break/box_b4.png");

	ptrBreak	=	new	BREAK;

	Screen->Texture->GetSurfaceLevel(0,&ScreenS);

	Direct->pDevice->GetBackBuffer(0,0,D3DBACKBUFFER_TYPE_MONO,&BackBuffer);

}


void	PLAY::LoadMap(char Level)
{
	this->Level = Level;
	IMAGE	*BackRes =	new	IMAGE;
	WALL	*Res	 =	new	WALL;
	Map.clear();

	for(int i = 0;i<Enemies.size();i++)
		delete Enemies[i];

	Enemies.clear();
	
	BangWaves.clear();
	Bonuse.clear();
	Back.clear();
	LMap.clear();
	Bombs.clear();

	ifstream ifs;
	switch (Level)
	{
	case 1:

		ifs.open(L"Map/level_1.dat", ios::binary);
		Res = this->Res+2;
		BackRes = this->BackRes+4;

		ptrBreak->Res = ResBreak;
	break;
	case 2:

		ifs.open(L"Map/level_2.dat",ios::binary);
		Res = this->Res+4;
		BackRes = this->BackRes;

		ptrBreak->Res = ResBreak+4;
	break;
	case 3:

		ifs.open(L"Map/level_3.dat",ios::binary);
		Res = this->Res;
		BackRes = this->BackRes+8;

		ptrBreak->Res = ResBreak+8;

	break;
	case 4:

		ifs.open(L"Map/level_4.dat",ios::binary);
		Res = this->Res+4;
		BackRes = this->BackRes;

		ptrBreak->Res = ResBreak+4;
	break;
	case 5:

		ifs.open(L"Map/level_5.dat",ios::binary);
		Res = this->Res;
		BackRes = this->BackRes+8;

		ptrBreak->Res = ResBreak+8;
	break;
	case 6:

		ifs.open(L"Map/level_6.dat", ios::binary);
		Res = this->Res+2;
		BackRes = this->BackRes+4;

		ptrBreak->Res = ResBreak;
	break;
	case 7:

		ifs.open(L"Map/level_7.dat",ios::binary);
		Res = this->Res+4;
		BackRes = this->BackRes;

		ptrBreak->Res = ResBreak+4;
	break;
	case 8:

		ifs.open(L"Map/level_8.dat",ios::binary);
		Res = this->Res;
		BackRes = this->BackRes+8;

		ptrBreak->Res = ResBreak+8;

	break;
	case 9:

		ifs.open(L"Map/level_9.dat",ios::binary);
		Res = this->Res+4;
		BackRes = this->BackRes;

		ptrBreak->Res = ResBreak+4;
	break;
	case 10:

		ifs.open(L"Map/level_10.dat",ios::binary);
		Res = this->Res;
		BackRes = this->BackRes+8;

		ptrBreak->Res = ResBreak+8;
	break;
	}

	Obj	Ob;

	float MaxX=5000,MaxY=5000;

	while(!ifs.eof())
	{
		ifs.read((char*)&Ob,sizeof(Ob));
		LMap.push_back(Ob);
	}

	for(int i = 0 ;i<LMap.size();i++)
	{
		if(LMap[i].x < MaxX)
			MaxX = LMap[i].x;
		if(LMap[i].y <MaxY)
			MaxY = LMap[i].y;

	}

	for(int i = 0 ;i<LMap.size();i++)
	{

		LMap[i].x-=MaxX;
		LMap[i].y-=MaxY;
		Ob = LMap[i];
		if(Ob.Type == 0)
		{
			
			Res[0].SetPosition(Ob.x,Ob.y);
			Map.push_back(Res[0]);
		}
		if(Ob.Type == 1)
		{
			Res[1].SetPosition(Ob.x,Ob.y);
			Map.push_back(Res[1]);
		}
		if(Ob.Type == 2)
		{
			Player->SetPosition(Ob.x,Ob.y);

		}
		if(Ob.Type == 3)
		{
			Enemies.push_back((EnemyC->CreateBall(Ob.x,Ob.y)));
		}
		if(Ob.Type == 4)
		{
			Enemies.push_back((EnemyC->CreateDroid(Ob.x,Ob.y)));
		}
		if(Ob.Type == 5)
		{
			Enemies.push_back((EnemyC->CreateCube(Ob.x,Ob.y)));
		}

	}

	int Rand = 0;
	while(Map[Rand].Type)
	{
		Rand = rand()%((int)(Map.size()));
	}
	Exit->Position = Map[Rand].Position;



	if(Level == 1)
	{

		int Rand = 0;
		while(Map[Rand].Type)
		{
			Rand = rand()%((int)(Map.size()));
		}
		ResBon[0].Position = Map[Rand].Position;
		Bonuse.push_back(ResBon[0]);

		Rand = 0;
		while(Map[Rand].Type)
		{
			Rand = rand()%((int)(Map.size()));
		}
		ResBon[1].Position = Map[Rand].Position;
		Bonuse.push_back(ResBon[1]);

	}

	if(Level == 2)
	{

		int Rand = 0;
		while(Map[Rand].Type)
		{
			Rand = rand()%((int)(Map.size()));
		}
		ResBon[0].Position = Map[Rand].Position;
		Bonuse.push_back(ResBon[0]);

		Rand = 0;
		while(Map[Rand].Type)
		{
			Rand = rand()%((int)(Map.size()));
		}
		ResBon[2].Position = Map[Rand].Position;
		Bonuse.push_back(ResBon[2]);

	}

	if(Level == 3)
	{

		int Rand = 0;
		while(Map[Rand].Type)
		{
			Rand = rand()%((int)(Map.size()));
		}
		ResBon[4].Position = Map[Rand].Position;
		Bonuse.push_back(ResBon[4]);

		Rand = 0;
		while(Map[Rand].Type)
		{
			Rand = rand()%((int)(Map.size()));
		}
		ResBon[1].Position = Map[Rand].Position;
		Bonuse.push_back(ResBon[1]);

	}

	if(Level == 4)
	{

		int Rand = 0;
		while(Map[Rand].Type)
		{
			Rand = rand()%((int)(Map.size()));
		}
		ResBon[3].Position = Map[Rand].Position;
		Bonuse.push_back(ResBon[3]);

		Rand = 0;
		while(Map[Rand].Type)
		{
			Rand = rand()%((int)(Map.size()));
		}
		ResBon[0].Position = Map[Rand].Position;
		Bonuse.push_back(ResBon[0]);

	}

	if(Level == 5)
	{

		int Rand = 0;
		while(Map[Rand].Type)
		{
			Rand = rand()%((int)(Map.size()));
		}
		ResBon[0].Position = Map[Rand].Position;
		Bonuse.push_back(ResBon[0]);

		Rand = 0;
		while(Map[Rand].Type)
		{
			Rand = rand()%((int)(Map.size()));
		}
		ResBon[1].Position = Map[Rand].Position;
		Bonuse.push_back(ResBon[1]);

	}

	if(Level == 6)
	{

		int Rand = 0;
		while(Map[Rand].Type)
		{
			Rand = rand()%((int)(Map.size()));
		}
		ResBon[0].Position = Map[Rand].Position;
		Bonuse.push_back(ResBon[0]);

		Rand = 0;
		while(Map[Rand].Type)
		{
			Rand = rand()%((int)(Map.size()));
		}
		ResBon[1].Position = Map[Rand].Position;
		Bonuse.push_back(ResBon[1]);

	}

	if(Level == 7)
	{

		int Rand = 0;
		while(Map[Rand].Type)
		{
			Rand = rand()%((int)(Map.size()));
		}
		ResBon[0].Position = Map[Rand].Position;
		Bonuse.push_back(ResBon[0]);

		Rand = 0;
		while(Map[Rand].Type)
		{
			Rand = rand()%((int)(Map.size()));
		}
		ResBon[2].Position = Map[Rand].Position;
		Bonuse.push_back(ResBon[2]);

	}

	if(Level == 8)
	{

		int Rand = 0;
		while(Map[Rand].Type)
		{
			Rand = rand()%((int)(Map.size()));
		}
		ResBon[0].Position = Map[Rand].Position;
		Bonuse.push_back(ResBon[0]);

		Rand = 0;
		while(Map[Rand].Type)
		{
			Rand = rand()%((int)(Map.size()));
		}
		ResBon[1].Position = Map[Rand].Position;
		Bonuse.push_back(ResBon[1]);

	}

	if(Level == 9)
	{

		int Rand = 0;
		while(Map[Rand].Type)
		{
			Rand = rand()%((int)(Map.size()));
		}
		ResBon[1].Position = Map[Rand].Position;
		Bonuse.push_back(ResBon[1]);

		Rand = 0;
		while(Map[Rand].Type)
		{
			Rand = rand()%((int)(Map.size()));
		}
		ResBon[0].Position = Map[Rand].Position;
		Bonuse.push_back(ResBon[0]);

	}

	if(Level == 10)
	{

		int Rand = 0;
		while(Map[Rand].Type)
		{
			Rand = rand()%((int)(Map.size()));
		}
		ResBon[0].Position = Map[Rand].Position;
		Bonuse.push_back(ResBon[0]);

		Rand = 0;
		while(Map[Rand].Type)
		{
			Rand = rand()%((int)(Map.size()));
		}
		ResBon[1].Position = Map[Rand].Position;
		Bonuse.push_back(ResBon[1]);

	}

	LMap.clear();
	ifs.close();

	for(int x = 0;x<30;x++)
		for(int y = 0; y<30;y++)
		{
			char Index = rand()%4;
			BackRes[Index].SetPosition((float)x*64,(float)y*64);
			Back.push_back(BackRes[Index]);
		}
}
void	PLAY::Draw(void)
{
	

	Direct->pDevice->SetRenderTarget(0,ScreenS);

	for(int i =0;i<(int)Back.size();i++)
		Back[i].Draw();

	for(int i =0;i<(int)Bonuse.size();i++)
		Bonuse[i].Draw();

	for(int i =0;i<(int)Map.size();i++)
		Map[i].Draw();

	for(int i =0;i<(int)Bombs.size();i++)
		Bombs[i].Draw();

	for(int i =0;i<(int)Breaks.size();i++)
		Breaks[i].Draw();

	

	for(int i =0;i<(int)Enemies.size();i++)
		Enemies[i]->Draw();



	Bang->Draw();

	Player->Draw();
	Exit->Draw();
	Direct->pDevice->SetRenderTarget(0,BackBuffer);

	Screen->Draw();

	if(Player->Erase)
	{
		Level = 1;
		STATUS	= 0;
		Player->Bomb = 1;
		Player->Wave = 1;
		Player->Speed = 2.5f;
		Player->Live =  1;
		Player->Erase = false;
		Player->Spirit = false;
		LoadMap(1);
	}

}
void	PLAY::Flip(void)
{
	KeyDown();
	Detonation();

	Wave();

	Camera();

	VisibleBonus();

	for(int i =0;i<(int)Enemies.size();i++)
	{
		Enemies[i]->Dead();
		Enemies[i]->Flip();
		if(Enemies[i]->Erase > 3)
		{
			delete Enemies[i];
			Enemies.erase(Enemies.begin()+i);
			i--;
		}
	}

	for(int i =0;i<(int)Bonuse.size();i++)
	{
		if(Bonuse[i].Collide(*Player->Col))
		{
			if(Bonuse[i].Type == 1)
				Player->Bomb++;

			if(Bonuse[i].Type == 2)
				Player->Wave++;

			if(Bonuse[i].Type == 3)
				Player->Speed+=0.5f;

			if(Bonuse[i].Type == 4)
				Player->Speed++;

			Bonuse.erase(Bonuse.begin()+i);
		}
	}


	if(TimeReleas <GetTickCount()-10)
		BangWaves.clear();

	for(int i =0;i<(int)Enemies.size();i++)
	{
		if(Player->BombCollide(Enemies[i]->Collid))
			Player->Live = false;
	}

	for(int i =0;i<(int)this->BangWaves.size();i++)
	{
		if(Player->BombCollide(BangWaves[i]))
			Player->Live = false;
	}

	for(int i =0;i<(int)Breaks.size();i++)
	{
		if(Breaks[i].Steep > 3)
		Breaks.erase(Breaks.begin()+i);
	}

	if(Exit->Collide(*Player->BombCol) & Enemies.empty())
	{
		Level++;
		LoadMap(Level);
	}

}

void	PLAY::Camera(void)
{
	if(Player->Position.x < 640 )
		Screen->SetPosition(0,Screen->Position.y);
	else
		Screen->SetPosition(-(Player->Position.x-640),Screen->Position.y);

	if(Player->Position.y <  348 )
		Screen->SetPosition(Screen->Position.x,0);
	else
		Screen->SetPosition(Screen->Position.x,-(Player->Position.y-348));

	if(Player->Position.x > 1216)
		Screen->SetPosition(-576,Screen->Position.y);
	if(Player->Position.y > 716)
		Screen->SetPosition(Screen->Position.x,-366);

}

void	PLAY::Wave(void)
{
	for(int i =0;i<(int)Map.size();i++)
		for(int g =0;g<(int)BangWaves.size();g++)
			if(BangWaves[g].Collide(Map[i]))
			{
				if(Map[i].Type == 0)
				{
					ptrBreak->Position = Map[i].Position;
					Breaks.push_back(*ptrBreak);

					Map.erase(Map.begin()+i);
					i--;
				}
			}
}

void	PLAY::Detonation(void)
{
	for(int i =0;i<(int)Bombs.size();i++)
		if(Bombs[i].Boom)
		{
			//BASS_ChannelPlay(sample,TRUE);
			BangWave->Position.x = Bombs[i].Position.x+4;
			BangWave->Position.y = Bombs[i].Position.y+4;
			BangWaves.push_back(*BangWave);

			D3DXVECTOR2 Pos;

			Pos.x = Bombs[i].Position.x+2;
			Pos.y = Bombs[i].Position.y+2;

			Bombs.erase(Bombs.begin()+i);
			i--;
			TimeReleas = GetTickCount();
			Bang->AddBoom(Pos.x-2,Pos.y-2,FuncWave(Pos,0,MUP),MUP);
			Bang->AddBoom(Pos.x-2,Pos.y-2,FuncWave(Pos,0,MRIGHT),MRIGHT);
			Bang->AddBoom(Pos.x-2,Pos.y-2,FuncWave(Pos,0,MDOWN),MDOWN);
			Bang->AddBoom(Pos.x-2,Pos.y-2,FuncWave(Pos,0,MLEFT),MLEFT);
			Bang->AddBoom(Pos.x-2,Pos.y-2,0,MLEFT);



		}
}


void	PLAY::KeyDown(void)
{
	if(Input->JoystickDown(START))
	{
		STATUS = 0;
		LoadMap(1);
		Sleep(300);
	}

	if(Input->KeyDown(DIK_ESCAPE))
	{
		STATUS = 0;
		LoadMap(1);
		Sleep(300);
	}


	if(Input->KeyDown(DIK_S) | Input->JoystickPOV(DOWN) | Input->JoystickPOV(DOWNRIGHT))
	{
		bool Triger = 0;
		Player->Move(MDOWN);
		for(int i = 0;i < (int)Map.size();i++)
		{
			if(Player->Collide(Map[i]))
			{
				Triger = 1;
				if(Player->ImageDraw->Position.x > Map[i].Position.x)
				//	Player->Move(MRIGHT);
					Player->SetPosition(Player->Position.x+Player->Speed,Player->Position.y);
				if(Player->ImageDraw->Position.x < Map[i].Position.x)
					Player->SetPosition(Player->Position.x-Player->Speed,Player->Position.y);
				//	Player->Move(MLEFT);
			}
		}
		for(int i = 0;i < (int)Bombs.size();i++)
		{
			if(Player->Collide(Bombs[i].DrawImage)& Bombs[i].Collide)
			{
				Triger = 1;
				if(Player->ImageDraw->Position.x > Bombs[i].Position.x)
				//	Player->Move(MRIGHT);
					Player->SetPosition(Player->Position.x+Player->Speed,Player->Position.y);
				if(Player->ImageDraw->Position.x < Bombs[i].Position.x)
					Player->SetPosition(Player->Position.x-Player->Speed,Player->Position.y);
				//	Player->Move(MLEFT);
			}
			if(!Player->Collide(Bombs[i].DrawImage))
			{
				Bombs[i].Collide = !(Player->Spirit);
			}
		}

		if(Triger)
			Player->SetPosition(Player->Position.x,Player->Position.y-Player->Speed);

				
	}
	else if(Input->KeyDown(DIK_A) | Input->JoystickPOV(LEFT) | Input->JoystickPOV(DOWNLEFT))
	{
		Player->Move(MLEFT);
		bool Triger = 0;
		for(int i = 0;i < (int)Map.size();i++)
		{
			if(Player->Collide(Map[i]))
			{	
				Triger = 1;
				if(Player->ImageDraw->Position.y > Map[i].Position.y)
					Player->SetPosition(Player->Position.x,Player->Position.y+Player->Speed);
				//	Player->Move(MDOWN);
				if(Player->ImageDraw->Position.y < Map[i].Position.y)
					Player->SetPosition(Player->Position.x,Player->Position.y-Player->Speed);
					//Player->Move(MUP);
			}
		}
		for(int i = 0;i < (int)Bombs.size();i++)
		{
			if(Player->Collide(Bombs[i].DrawImage)& Bombs[i].Collide)
			{	
				Triger = 1;
				if(Player->ImageDraw->Position.y > Bombs[i].Position.y)
					Player->SetPosition(Player->Position.x,Player->Position.y+Player->Speed);
				//	Player->Move(MDOWN);
				if(Player->ImageDraw->Position.y < Bombs[i].Position.y)
					Player->SetPosition(Player->Position.x,Player->Position.y-Player->Speed);
					//Player->Move(MUP);
			}
			if(!Player->Collide(Bombs[i].DrawImage))
				Bombs[i].Collide = true;
		}
		if(Triger)
			Player->SetPosition(Player->Position.x+Player->Speed,Player->Position.y);
		
	}

	else if(Input->KeyDown(DIK_W) | Input->JoystickPOV(UP) | Input->JoystickPOV(UPLEFT))
	{
		bool Triger = 0;
		Player->Move(MUP);
		for(int i = 0;i < (int)Map.size();i++)
		{
			if(Player->Collide(Map[i]))
			{
				Triger = 1;
				if(Player->ImageDraw->Position.x > Map[i].Position.x)
					//Player->Move(MRIGHT);
					Player->SetPosition(Player->Position.x+Player->Speed,Player->Position.y);
				if(Player->ImageDraw->Position.x < Map[i].Position.x)
					Player->SetPosition(Player->Position.x-Player->Speed,Player->Position.y);
					//Player->Move(MLEFT);
			}
		}
		for(int i = 0;i < (int)Bombs.size();i++)
		{
			if(Player->Collide(Bombs[i].DrawImage)& Bombs[i].Collide)
			{
				Triger = 1;
				if(Player->ImageDraw->Position.x > Bombs[i].Position.x )
					//Player->Move(MRIGHT);
					Player->SetPosition(Player->Position.x+Player->Speed,Player->Position.y);
				if(Player->ImageDraw->Position.x < Bombs[i].Position.x)
					Player->SetPosition(Player->Position.x-Player->Speed,Player->Position.y);
					//Player->Move(MLEFT);
			}
			if(!Player->Collide(Bombs[i].DrawImage))
				Bombs[i].Collide = true;
		}

		if(Triger)
			Player->SetPosition(Player->Position.x,Player->Position.y+Player->Speed);
	}

	else if(Input->KeyDown(DIK_D) | Input->JoystickPOV(RIGHT) | Input->JoystickPOV(UPRIGHT))
	{
		bool Triger = 0;
		Player->Move(MRIGHT);
		for(int i = 0;i < (int)Map.size();i++)
		{
			if(Player->Collide(Map[i]))
			{
				Triger = 1;
				if(Player->ImageDraw->Position.y > Map[i].Position.y)
					Player->SetPosition(Player->Position.x,Player->Position.y+Player->Speed);
					//Player->Move(MDOWN);
				if(Player->ImageDraw->Position.y < Map[i].Position.y)
					Player->SetPosition(Player->Position.x,Player->Position.y-Player->Speed);
					//Player->Move(MUP);
			}
		}
		for(int i = 0;i < (int)Bombs.size();i++)
		{
			if(Player->Collide(Bombs[i].DrawImage) & Bombs[i].Collide)
			{
				Triger = 1;
				if(Player->ImageDraw->Position.y > Bombs[i].Position.y)
					Player->SetPosition(Player->Position.x,Player->Position.y+Player->Speed);
					//Player->Move(MDOWN);
				if(Player->ImageDraw->Position.y < Bombs[i].Position.y)
					Player->SetPosition(Player->Position.x,Player->Position.y-Player->Speed);
					//Player->Move(MUP);
			}
			if(!Player->Collide(Bombs[i].DrawImage))
				Bombs[i].Collide = true;
		}
		if(Triger)
			Player->SetPosition(Player->Position.x-Player->Speed,Player->Position.y);
	}

	if((Input->KeyDown(DIK_SPACE) | Input->JoystickDown(A)) & (Bombs.size() < Player->Bomb))
	{
		Bomb->SetPosition((int)(Player->Position.x+32)/64*64,(int)(Player->Position.y+32)/64*64);
		Bomb->TimeLive = GetTickCount();

		bool	Triger = 1;
		for(int i =0;i<(int)Bombs.size();i++)
			if(Bombs[i].Position == Bomb->Position)
				Triger = 0;
		if(Triger)
			Bombs.push_back(*Bomb);
	}


}

int	PLAY::FuncWave(D3DXVECTOR2 Pos,int Lenght,int Rot)
{
	
	BangWave->Position.x = Pos.x;
	BangWave->Position.y = Pos.y;

	BangWaves.push_back(*BangWave);

	for(int ho = 0;ho<(int)Map.size();ho++)
	{
		if(Map[ho].Collide(*BangWave))
		{
			Lenght--;
			return Lenght;
		}
	}

	for(int ho = 0;ho<(int)Bombs.size();ho++)
	{
		if(Bombs[ho].DrawImage.Collide(*BangWave))
		{
			Lenght--;
			Bombs[ho].Boom = true;
			return Lenght;
		}
	}

	Lenght++;

	if(Lenght > Player->Wave)
	{
		Lenght--;
		return Lenght;
	}

	if(Rot	== MUP)
	{
		Pos.y-=64;
		FuncWave(Pos,Lenght,MUP);
	}
	if(Rot	== MDOWN)
	{
		Pos.y+=64;
		FuncWave(Pos,Lenght,MDOWN);
	}
	if(Rot	== MLEFT)
	{
		Pos.x-=64;
		FuncWave(Pos,Lenght,MLEFT);
	}
	if(Rot	== MRIGHT)
	{
		Pos.x+=64;
		FuncWave(Pos,Lenght,MRIGHT);
	}
//	return Lenght;

}
PLAY::~PLAY(void)
{
}

void	PLAY::VisibleBonus(void)
{
	for(int m = 0;m <(int)Bonuse.size();m++)
	{
		bool Triger = true;
		for(int b = 0;b<(int)Map.size();b++)
		{
			if(Map[b].Position == Bonuse[m].Position)
				Triger = false;
		}
		Bonuse[m].Visible = Triger;
	}

	bool Triger = true;
		for(int b = 0;b<(int)Map.size();b++)
		{
			if(Map[b].Position == Exit->Position)
				Triger = false;
		}
	Exit->Visible = Triger;

}