//Oyun 

#include "mostemp.h"

//Sounds[SOUND_TOP]->Play();
void TopDraws()
{	
		
	float Velx= (top.GetVelX()*(pencere.g_ZamanSayaci))*10;
	float Vely=(top.GetVelY()*(pencere.g_ZamanSayaci))*10;

	top.SetPosX(top.GetPosX() +Velx*3);
		top.SetPosY(top.GetPosY() +Vely*3 );

		if(top.GetPosX() < 8)
		{
			Sounds[SOUND_YAN]->Play();
			top.SetVelX(top.GetVelX() - (2 * top.GetVelX()));
            top.SetPosX(9);
			
	
		}
		if(top.GetPosX() > (633 - top.en))
		{
			Sounds[SOUND_YAN]->Play();
			top.SetVelX(top.GetVelX() - (2 * top.GetVelX()));
			top.SetPosX(632 - top.en);
		}
		if(top.GetPosY() < 30)
		{
			Sounds[SOUND_UST]->Play();
			top.SetVelY(top.GetVelY() - (2 * top.GetVelY()));
			top.SetPosY(31);
		}
		if(top.GetPosY() > (480 - top.boy))
		{
		
		//pencere.g_ZamanSayaci
			top.SetVelY(top.GetVelY() - (2 * top.GetVelY()));
			top.SetPosY(479 - top.boy);
		}

		
	top.Draw(GL_SPRITE_TRANS,true,true);

}
void ResetGame()
{
	
	top.en=16;
	top.boy=16;
	top.SetPos(310,355);
	top.SetVel(4,-4);
	top.vx=4;
	top.vy=4;

	player.en = 64;	
//	player.en = 280;
	player.boy = 14;
	player.SetPos(245,435);
	player.cevirhiz =8;
	player.vx=5;
	player.vy=5;

	efek.en = 64;	
//	efek.en = 280;
	efek.boy = 14;
	efek.SetPos(245,445);
	efek.cevirhiz = 6;

	static float r,g,b;
	//sprite list
	for(int i2=0;i2 < 12;i2++)
	{
	
	for(int i=0;i < 18;i++)
	{
	 r +=0.1;
	 g += 0.1;
	 b += 0.2;
	 if(r > 1)
	 {
		 r = 0;
	 }
 if(b > 1)
	 {
		 b = 0;
	 } if(g > 1)
	 {
		 g = 0;
	 }
	 

	sprite_ekle_Duvar_renk(duvartile,TYPE_DUVAR,20+(i*33),50+(i2*18),CANLI,1,1,r,g,b);	
	
	}
	
	}	
	

		
	Ps = PS_OYUN;
}
bool reload()
{
	if(DuvarSprites.GetCount() >0)
	{
		DuvarSprites.KaldirSprite(DuvarSprites.GetFirst());
       return FALSE;
	}
	if(EfekSprites.GetCount() >0)
	{
	 EfekSprites.KaldirSprite(EfekSprites.GetFirst());
       return FALSE;
	}

	Ps= PS_MENU;
	return TRUE;
}
void OyunKlavye()
{

	if (Input.GetKeyState(CDXKEY_ESCAPE))
	{
			Ps = PS_RELOAD;
	}	

	if (Input.GetKeyState(CDXKEY_MOUSELEFT))
	{
		if(player.en < 400)
		{
			player.en +=2;
		}
		if(top.en < 120)
		{
			top.en +=1;
		}
	}
	
	if (Input.GetKeyState(CDXKEY_MOUSERIGHT))
	{
		if(player.en > 35)
		{
			player.en -=2;
		}
		if(top.en > 17)
		{
			top.en -=1;
		}
	}


}
void OyunYazi()
{
	CHAR oyuny[200];


	sprintf(oyuny,"FPS : %.0f",pencere.g_fFPS);
	font.Yaz(10,15,oyuny,1);
	sprintf(oyuny,"Duvar Kiran");
	font.YazRenk(10,30,oyuny,1,240,220,255,255);
	sprintf(oyuny,"Oyuncu 1");
	font.YazRenk(200,15,oyuny,1,240,220,255,255);
	sprintf(oyuny,"Puan = 0");
	font.YazRenk(200,30,oyuny,1,240,220,255,255);

	sprintf(oyuny,"Bolum 1");
	font.YazRenk(350,15,oyuny,1,240,220,255,255);
	


/*	sprintf(oyuny,"Getcount : %d",DuvarSprites.GetCount());
	font.YazRenk(10,60,oyuny,1,240,220,255,255);*/


}
void HakDraw()
{

	for(int f=0;f <3;f++)
	{
	sopa.en = 50;
	sopa.boy = 15;
	sopa.SetRenk(1,1,1);
	sopa.SetPos(440+(f*55),10);
	sopa.Draw(GL_SPRITE_TRANS_UV_RIGHT,true,false);
		
	lava2.en = 50;
	lava2.boy = 9;
	lava2.SetPos(440+(f*55),14);
	lava2.SetRenk(1,1,1);
	lava2.Draw(GL_SPRITE_TRANS_UV_DOWN,true); 
	}
}
void Oyun()
{
	  LONG mousex,mousey;
	//Input.GetMousePos(&mousex,&mousey);
	Input.GetMouseDeltas(&mousex, &mousey);

	arka2.SetPos(0,0);
	arka2.Draw(GL_SPRITE_NORMAL_TILE,true,false);
	
	menus.SetEnBoy(10,480);
	menus.SetPos(0,0);
	menus.Draw(GL_SPRITE_NORMAL,true,false);
	
	menus.SetEnBoy(10,480);
	menus.SetPos(630,0);
	menus.Draw(GL_SPRITE_NORMAL,true,false);

	menus.SetEnBoy(640,30);
	menus.SetPos(0,0);
	menus.Draw(GL_SPRITE_NORMAL,true,false);

	

	Sprites_Update_Duvar(GL_SPRITE_TRANS,true,true);
	Sprites_Update_Efek(GL_SPRITE_TRANS,true,2);


	top.boy=top.en;
	TopDraws();

	if(Input.HasMouse()) player.xpos += mousex;

		if( player.xpos < 10) player.xpos = 10;
	if(player.xpos > 630-player.en)  player.xpos= 630-player.en;

//	player.SetPos(245,435);
	player.cevirhiz = 8*(50*pencere.g_ZamanSayaci);
	player.Draw(GL_SPRITE_TRANS_UV_RIGHT,true,true);
		
	efek.en = player.en;
//	efek.boy = 16;
	efek.SetPos(player.GetPosX(),player.GetPosY());
	efek.cevirhiz = 6*(50*pencere.g_ZamanSayaci);
	efek.Draw(GL_SPRITE_TRANS_UV_DOWN,true,true);


	HakDraw();



     if(button.Bas(player,top,0)==TRUE)
	 {
		 Sounds[SOUND_SOPA]->Play();
		 top.SetVelY(-top.vy);
		 
	 }


}