//#include"script/default_system/Default_ShotConst.txt"
#include".\Resources.txt"
#include".\GizmoSpriteLibrary.txt"
#include".\shot\AllStarShot_Const.txt"

let shou;
let kaguya;
let TIME = 99;
let shouX = 0;
let shouY = 0;
let kaguyaX = 0;
let kaguyaY = 0;

@Event
{
	//SetTimer(TIME);
    SetLife(471);
    SetScore(10000000);	
}

@Initialize
{
	DeleteShotAll(TYPE_ALL, TYPE_ITEM); 
	SetAutoDeleteObject(true);
	shou = ObjEnemy_Create(OBJ_ENEMY_BOSS);
	kaguya = ObjEnemy_Create(OBJ_ENEMY);
	
	ObjEnemy_Regist(shou);
	ObjEnemy_Regist(kaguya);
	
	SetForbidPlayerShot(true);
	SetForbidPlayerSpell(true);
	
	ObjEnemy_SetLife(kaguya, 471);
	BossManage;
	TMain();
}

@MainLoop
{

	yield;
}

task TMain(){
	ObjEnemy_SetDamageRate(shou,0,0);
	ObjEnemy_SetDamageRate(kaguya,0,0);
	SetPlayerSpeed(0, 0);
	Difficulty;
}

task BossManage{

	while(ObjEnemy_GetInfo(shou,INFO_LIFE)>0){
        shouX = ObjMove_GetX(shou);
        shouY = ObjMove_GetY(shou);
		kaguyaX = ObjMove_GetX(kaguya);
		kaguyaY = ObjMove_GetY(kaguya);
		
		ObjEnemy_SetIntersectionCircleToShot(shou, shouX, shouY, 40);
        ObjEnemy_SetIntersectionCircleToPlayer(shou, shouX, shouY, 30);
		ObjEnemy_SetIntersectionCircleToShot(kaguya, kaguyaX, kaguyaY, 40);
        ObjEnemy_SetIntersectionCircleToPlayer(kaguya, kaguyaX, kaguyaY, 30);
		yield;
	}
	SetCommonData("shouX",ObjMove_GetX(shou));
	SetCommonData("shouY",ObjMove_GetY(shou));
	
	Obj_Delete(shou);
	Obj_Delete(kaguya);
	
	DeleteShotAll(TYPE_ALL, TYPE_FADE);
	SetCommonData("LifebarsRemaining",GetCommonData("LifebarsRemaining",0)-1);
	SetCommonData("SpellsRemaining", GetCommonData("SpellsRemaining", 0)-1);
    CloseScript(GetOwnScriptID()); 
}


task Difficulty{

			let objText = ObjText_Create();
			Obj_SetRenderPriorityI(objText, 80);
			ObjText_SetFontType(objText, "8bitoperator JVE");
			ObjText_SetFontSize(objText, 36);
			ObjText_SetFontBorderType(objText, BORDER_FULL);
			ObjText_SetFontBorderWidth(objText, 3);
			ObjText_SetFontBorderColor(objText, 0,0,0);
			ObjText_SetFontColorTop(objText, 255,255,255);
			ObjText_SetFontColorBottom(objText, 255,0,255);
			ObjText_SetMaxWidth(objText, 500);
			ObjRender_SetPosition(objText,GetStgFrameWidth/2-177,100,0);
			ObjText_SetText(objText, "Select a difficulty:");
		
		let pArray = [];
		pArray = pArray ~ [GetCurrentScriptDirectory~"./img/d1.png"];
		pArray = pArray ~ [GetCurrentScriptDirectory~"./img/d2.png"];
		pArray = pArray ~ [GetCurrentScriptDirectory~"./img/d3.png"];
		pArray = pArray ~ [GetCurrentScriptDirectory~"./img/d4.png"];
		
		let obj = ObjPrim_Create(OBJ_SPRITE_2D);
		ObjPrim_SetTexture(obj, pArray[0]);
		ObjSprite2D_SetSourceRect(obj,0, 0, 750, 350);
		ObjRender_SetScaleXYZ(obj,0.4,0.4,0);
		Obj_SetRenderPriorityI(obj,80);
		ObjSprite2D_SetDestCenter(obj);
		ObjRender_SetPosition(obj,GetStgFrameWidth/2,GetScreenHeight/2,0);
		ObjRender_SetAlpha(obj,255);
		ObjRender_SetBlendType(obj,BLEND_ALPHA);
		
		
		let difficulty = 1;
		let angle = 0;
		let CHOSEN = false;
		
		while(!CHOSEN){
			if(GetVirtualKeyState(VK_DOWN)==KEY_PUSH){//SE_Play(Choose,100);
			difficulty--;
			if(difficulty<1){difficulty=4;}
			loop(18){angle+=5;
			ObjRender_SetAngleX(obj,angle);
			yield;}
			
			ObjPrim_SetTexture(obj, pArray[difficulty-1]);
			
			loop(18){angle-=5;
			ObjRender_SetAngleX(obj,angle);
			yield;}
			ObjRender_SetAngleX(obj,0);
			}
			
			
			else if(GetVirtualKeyState(VK_UP)==KEY_PUSH){//SE_Play(Choose,100);
			difficulty++;
			if(difficulty>4){difficulty=1;}
		
			loop(18){angle+=5;
			ObjRender_SetAngleX(obj,angle);
			yield;}
			
			ObjPrim_SetTexture(obj, pArray[difficulty-1]);
			
			loop(18){angle-=5;
			ObjRender_SetAngleX(obj,angle);
			yield;}}
			
			else if(GetVirtualKeyState(VK_SHOT)==KEY_PUSH){//SE_Play(Confirm,100);
			SetCommonData("Difficulty",difficulty);
			CHOSEN = true;}
		
		
		yield;}
		
		let alpha = 255;
		
		loop(30){
			alpha-=255/30;
			ObjRender_SetAlpha(obj,alpha);
			ObjRender_SetAlpha(objText,alpha);
		yield;}
		Obj_Delete(obj);
		Obj_Delete(objText);
		wait(30);		
		SetForbidPlayerShot(false);
		SetPlayerSpeed(4, 2);
		SetCommonData("ChoosingDifficulty", 0);
		ObjEnemy_SetLife(shou,0);
}