//#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);
	let objScene = GetEnemyBossSceneObjectID();
	ObjEnemyBossScene_StartSpell(objScene);
	
	shou = ObjEnemy_Create(OBJ_ENEMY_BOSS);
	kaguya = ObjEnemy_Create(OBJ_ENEMY);
	
	ObjEnemy_Regist(shou);
	ObjEnemy_Regist(kaguya);
	
	ObjMove_SetPosition(shou,GetCommonData("ShouX",0),GetCommonData("ShouY",0));
	ObjMove_SetPosition(kaguya,GetCommonData("KaguyaX",0),GetCommonData("KaguyaY",0));
	let cx = GetStgFrameWidth() / 3;
	
	renderShouUFO(shou);
	renderKaguyaIN(kaguya);
	
	
	//ObjMove_SetDestAtFrame(shou, cx, 100, 60);
	//ObjMove_SetDestAtFrame(kaguya, GetStgFrameWidth()-cx, 100, 60);
	
	
	ObjEnemy_SetLife(kaguya, 471);
	BossManage;
	TMain();
	
	wait(60);
	
	Obj_SetValue(kaguya,"cast",1);
	if(GetCommonData("Difficulty",1) == 1){FireE; KFireE; spellCast("Treasured Art: \"Flash Of A Shiny Pendant\"");}
	else if(GetCommonData("Difficulty",1) == 2){FireN; KFireN;spellCast("Umm\"I Am Pretty Sure This Is Static\"");}
	else if(GetCommonData("Difficulty",1) == 3){FireH; KFireH;spellCast("Flashy Sign: \"Shiny Flash Flashing Shiny Shines\"");}
	else if(GetCommonData("Difficulty",1) == 4){FireL; KFireL;spellCast("Look..: \"It Is 3 am And I Need To Submit This Today\"");}
}

@MainLoop
{

	yield;
}

task TMain(){
	ObjEnemy_SetDamageRate(shou,0,0);
	ObjEnemy_SetDamageRate(kaguya,0,0);
	let bossHP = 471*2;
	loop(120){
		bossHP-=471*2/120;
		SetCommonData("BossHealth",bossHP);
		yield;
	}
	ObjEnemy_SetDamageRate(shou,20,100);
	ObjEnemy_SetDamageRate(kaguya,20,100);
	loop{
		if(ObjEnemy_GetInfo(kaguya, INFO_LIFE) < ObjEnemy_GetInfo(shou, INFO_LIFE)){ObjEnemy_SetLife(shou, ObjEnemy_GetInfo(kaguya, INFO_LIFE));}
		else if(ObjEnemy_GetInfo(kaguya, INFO_LIFE) > ObjEnemy_GetInfo(shou, INFO_LIFE)){ObjEnemy_SetLife(kaguya, ObjEnemy_GetInfo(shou, INFO_LIFE));}
		SetCommonData("BossHealth",471-ObjEnemy_GetInfo(shou,INFO_LIFE));
	yield;}	
}

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));
	
	SetCommonData("KaguyaX",ObjMove_GetX(kaguya));
	SetCommonData("KaguyaY",ObjMove_GetY(kaguya));
	
	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 spellCast(name){
	let objText = ObjText_Create();
			Obj_SetRenderPriorityI(objText, 80);
			ObjText_SetFontType(objText, "8bitoperator JVE");
			ObjText_SetFontSize(objText, 16);
			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,255,255);
			ObjText_SetMaxWidth(objText, 500);
			ObjRender_SetPosition(objText,GetStgFrameWidth/2-237,300,0);
			ObjText_SetText(objText, name);
			wait(60);
			let y = 300;
			let dist = 260/60;
			loop(60){
				ObjRender_SetPosition(objText,GetStgFrameWidth/2-237,y,0);
				y-= dist;
				yield;
			}
			ObjRender_SetPosition(objText,GetStgFrameWidth/2-237,40,0);
}

task KFireL{
	wait(60);
	ObjMove_SetDestAtFrame(kaguya, GetStgFrameWidth/2, GetStgFrameHeight/2, 60);
	wait(60);
	let angle = 0;
	let n = 0;
	loop{
		
		loop(2){
			let graphic = 51;
			loop(6){
				if(graphic == 64){graphic = 53;}
				if(graphic == 63){graphic = 56;}
				if(graphic == 52){graphic = 63;}
				if(graphic == 55){graphic = 62;}
				let shot = CreateShotOA1(kaguya, 3, angle, graphic, 5);
				ObjMove_SetAcceleration(shot, -0.1);
				ObjMove_SetMaxSpeed(shot, 0);
				MoveShot(shot, n);
				Reflect(shot);
				graphic++;
				angle += 360/6;
				n += 180;
			}
			n += 180;
		}
		n+=0.25;
		angle += 5;
		wait(2);
	}
	task MoveShot(shot, angle){
		while(!Obj_IsDeleted(shot)){
			if(ObjMove_GetSpeed(shot) == 0){
				ObjMove_SetAngle(shot, angle);
				ObjMove_SetAcceleration(shot, 0.1);
				ObjMove_SetMaxSpeed(shot, 3);
				break;
			}
			yield;
		}
	}
	
	task Reflect(obj){
		let GetClipMaxX = GetStgFrameWidth();
		let GetClipMaxY = GetStgFrameHeight();
		let value = 1;
		while(!Obj_IsDeleted(obj))
		{
			if(value>0){
				if(ObjMove_GetX(obj)<0||ObjMove_GetX(obj)>GetClipMaxX)
				{
					ObjMove_SetSpeed(obj, 0);
					ObjMove_SetAcceleration(obj, 0);
					wait(60*2);
					ObjMove_SetAngle(obj, ObjMove_GetAngle(obj) +180);
					ObjMove_SetSpeed(obj, 3);
					value--;
				}
				if(ObjMove_GetY(obj)<0|| ObjMove_GetY(obj)>484)
				{
					ObjMove_SetSpeed(obj, 0);
					ObjMove_SetAcceleration(obj, 0);
					wait(60*2);
					ObjMove_SetAngle(obj, ObjMove_GetAngle(obj) +180);
					ObjMove_SetSpeed(obj, 3);
					value--
				}
			}
			if(value==0){break;}
			yield;
			
		}
	}
	
}

task KFireH{
	wait(60);
	ObjMove_SetDestAtFrame(kaguya, GetStgFrameWidth/2, GetStgFrameHeight/2, 60);
	wait(60);
	let angle = 0;
	let n = 0;
	loop{
		
		loop(2){
			let graphic = 51;
			loop(6){
				if(graphic == 64){graphic = 53;}
				if(graphic == 63){graphic = 56;}
				if(graphic == 52){graphic = 63;}
				if(graphic == 55){graphic = 62;}
				let shot = CreateShotOA1(kaguya, 3, angle, graphic, 5);
				ObjMove_SetAcceleration(shot, -0.1);
				ObjMove_SetMaxSpeed(shot, 0);
				MoveShot(shot, n);
				Reflect(shot);
				graphic++;
				angle += 360/6;
				n += 180;
			}
			n += 180;
		}
		n+=0.25;
		angle += 5;
		wait(2);
	}
	task MoveShot(shot, angle){
		while(!Obj_IsDeleted(shot)){
			if(ObjMove_GetSpeed(shot) == 0){
				ObjMove_SetAngle(shot, angle);
				ObjMove_SetAcceleration(shot, 0.1);
				ObjMove_SetMaxSpeed(shot, 3);
				break;
			}
			yield;
		}
	}
	
	task Reflect(obj){
		let GetClipMaxX = GetStgFrameWidth();
		let GetClipMaxY = GetStgFrameHeight();
		let value = 1;
		while(!Obj_IsDeleted(obj))
		{
			if(value>0){
				if(ObjMove_GetX(obj)<0||ObjMove_GetX(obj)>GetClipMaxX)
				{
					ObjMove_SetSpeed(obj, 0);
					ObjMove_SetAcceleration(obj, 0);
					wait(60*2);
					ObjMove_SetAngle(obj, ObjMove_GetAngle(obj) +180);
					ObjMove_SetSpeed(obj, 3);
					value--;
				}
				if(ObjMove_GetY(obj)<0|| ObjMove_GetY(obj)>484)
				{
					ObjMove_SetSpeed(obj, 0);
					ObjMove_SetAcceleration(obj, 0);
					wait(60*2);
					ObjMove_SetAngle(obj, ObjMove_GetAngle(obj) +180);
					ObjMove_SetSpeed(obj, 3);
					value--
				}
			}
			if(value==0){break;}
			yield;
			
		}
	}
	
}

task KFireN{
	wait(60);
	ObjMove_SetDestAtFrame(kaguya, GetStgFrameWidth/2, GetStgFrameHeight/2, 60);
	wait(60);
	let angle = 0;
	let n = 0;
	loop{
		
		loop(2){
			let graphic = 51;
			loop(6){
				if(graphic == 64){graphic = 53;}
				if(graphic == 63){graphic = 56;}
				if(graphic == 52){graphic = 63;}
				if(graphic == 55){graphic = 62;}
				let shot = CreateShotOA1(kaguya, 3, angle, graphic, 5);
				ObjMove_SetAcceleration(shot, -0.1);
				ObjMove_SetMaxSpeed(shot, 0);
				MoveShot(shot, n);
				Reflect(shot);
				graphic++;
				angle += 360/6;
				n += 180;
			}
			n += 180;
		}
		n+=0.25;
		angle += 5;
		wait(2);
	}
	task MoveShot(shot, angle){
		while(!Obj_IsDeleted(shot)){
			if(ObjMove_GetSpeed(shot) == 0){
				ObjMove_SetAngle(shot, angle);
				ObjMove_SetAcceleration(shot, 0.1);
				ObjMove_SetMaxSpeed(shot, 3);
				break;
			}
			yield;
		}
	}
	
	task Reflect(obj){
		let GetClipMaxX = GetStgFrameWidth();
		let GetClipMaxY = GetStgFrameHeight();
		let value = 1;
		while(!Obj_IsDeleted(obj))
		{
			if(value>0){
				if(ObjMove_GetX(obj)<0||ObjMove_GetX(obj)>GetClipMaxX)
				{
					ObjMove_SetSpeed(obj, 0);
					ObjMove_SetAcceleration(obj, 0);
					wait(60*2);
					ObjMove_SetAngle(obj, ObjMove_GetAngle(obj) +180);
					ObjMove_SetSpeed(obj, 3);
					value--;
				}
				if(ObjMove_GetY(obj)<0|| ObjMove_GetY(obj)>484)
				{
					ObjMove_SetSpeed(obj, 0);
					ObjMove_SetAcceleration(obj, 0);
					wait(60*2);
					ObjMove_SetAngle(obj, ObjMove_GetAngle(obj) +180);
					ObjMove_SetSpeed(obj, 3);
					value--
				}
			}
			if(value==0){break;}
			yield;
			
		}
	}
	
}

task KFireE{
	wait(60);
	ObjMove_SetDestAtFrame(kaguya, GetStgFrameWidth/2, GetStgFrameHeight/2, 60);
	wait(60);
	let angle = 0;
	let n = 0;
	loop{
		
		loop(2){
			let graphic = 51;
			loop(6){
				if(graphic == 64){graphic = 53;}
				if(graphic == 63){graphic = 56;}
				if(graphic == 52){graphic = 63;}
				if(graphic == 55){graphic = 62;}
				let shot = CreateShotOA1(kaguya, 3, angle, graphic, 5);
				ObjMove_SetAcceleration(shot, -0.1);
				ObjMove_SetMaxSpeed(shot, 0);
				MoveShot(shot, n);
				Reflect(shot);
				graphic++;
				angle += 360/6;
				n += 180;
			}
			n += 180;
		}
		n+=0.25;
		angle += 5;
		wait(2);
	}
	task MoveShot(shot, angle){
		while(!Obj_IsDeleted(shot)){
			if(ObjMove_GetSpeed(shot) == 0){
				ObjMove_SetAngle(shot, angle);
				ObjMove_SetAcceleration(shot, 0.1);
				ObjMove_SetMaxSpeed(shot, 3);
				break;
			}
			yield;
		}
	}
	
	task Reflect(obj){
		let GetClipMaxX = GetStgFrameWidth();
		let GetClipMaxY = GetStgFrameHeight();
		let value = 1;
		while(!Obj_IsDeleted(obj))
		{
			if(value>0){
				if(ObjMove_GetX(obj)<0||ObjMove_GetX(obj)>GetClipMaxX)
				{
					ObjMove_SetSpeed(obj, 0);
					ObjMove_SetAcceleration(obj, 0);
					wait(60*2);
					ObjMove_SetAngle(obj, ObjMove_GetAngle(obj) +180);
					ObjMove_SetSpeed(obj, 3);
					value--;
				}
				if(ObjMove_GetY(obj)<0|| ObjMove_GetY(obj)>484)
				{
					ObjMove_SetSpeed(obj, 0);
					ObjMove_SetAcceleration(obj, 0);
					wait(60*2);
					ObjMove_SetAngle(obj, ObjMove_GetAngle(obj) +180);
					ObjMove_SetSpeed(obj, 3);
					value--
				}
			}
			if(value==0){break;}
			yield;
			
		}
	}
}

//Lunatic
task FireL(){
		wait(60);
	ObjMove_SetDestAtFrame(shou, GetStgFrameWidth/2, 200, 60);
	Obj_SetValue(shou,"cast",1);
	wait(120);
	let angle = 0;
	loop{
		let n = 1;
		loop(2){
			loop(5){
				let cLaser = CreateCurveLaserA1(shouX, shouY, 5, angle, 30, 15, C_LASER_YELLOW, 0);
				ObjCrLaser_SetTipDecrement(cLaser, 0);
				ObjMove_SetAngularVelocity(cLaser, 3.1*n);
				ObjMove_SetMaxSpeed(cLaser, 0.5);
				ObjMove_SetAcceleration(cLaser, -0.1);
				moveShot(cLaser);
				angle += 360/5
				
			}
			loop(6){
				let cLaser2 = CreateCurveLaserA1(shouX, shouY, 4, angle, 30, 15, C_LASER_RED, 0);
				ObjCrLaser_SetTipDecrement(cLaser2, 0);
				ObjMove_SetAngularVelocity(cLaser2, 5.1*n);
				ObjMove_SetMaxSpeed(cLaser2, 0.5);
				ObjMove_SetAcceleration(cLaser2, -0.1);
				moveShot(cLaser2);
				angle += 360/6
			}
			loop(6){
				let cLaser2 = CreateCurveLaserA1(shouX, shouY, 8, angle, 30, 15, C_LASER_GREEN, 0);
				ObjCrLaser_SetTipDecrement(cLaser2, 0);
				ObjMove_SetAngularVelocity(cLaser2, 10.1*n);
				ObjMove_SetMaxSpeed(cLaser2, 0.5);
				ObjMove_SetAcceleration(cLaser2, -0.1);
				moveShot(cLaser2);
				angle += 360/7
			}
			
			loop(6){
				let cLaser2 = CreateCurveLaserA1(shouX, shouY, 10, angle, 30, 15, C_LASER_PURPLE, 0);
				ObjCrLaser_SetTipDecrement(cLaser2, 0);
				ObjMove_SetAngularVelocity(cLaser2, 30.1*n);
				ObjMove_SetMaxSpeed(cLaser2, 0.5);
				ObjMove_SetAcceleration(cLaser2, -0.1);
				moveShot(cLaser2);
				angle += 360/7
			}
		n*= -1;
		}
		angle += 30;
		wait(60);
	}
	task moveShot(shot){
		while(!Obj_IsDeleted(shot)){
			if(ObjMove_GetSpeed(shot) <= 0.5){
				wait(30);
				ObjMove_SetAngularVelocity(shot, 0);
				ObjMove_SetAcceleration(shot, 0.4);
				ObjMove_SetMaxSpeed(shot, 30);
				break;
			}
			yield;
		}
	} 

}

//Hard
task FireH(){
	wait(60);
	ObjMove_SetDestAtFrame(shou, GetStgFrameWidth/2, 200, 60);
	Obj_SetValue(shou,"cast",1);
	wait(120);
	let angle = 0;
	loop{
		let n = 1;
		loop(2){
			loop(5){
				let cLaser = CreateCurveLaserA1(shouX, shouY, 5, angle, 30, 15, C_LASER_YELLOW, 0);
				ObjCrLaser_SetTipDecrement(cLaser, 0);
				ObjMove_SetAngularVelocity(cLaser, 3.1*n);
				ObjMove_SetMaxSpeed(cLaser, 0.5);
				ObjMove_SetAcceleration(cLaser, -0.1);
				moveShot(cLaser);
				angle += 360/5
				
			}
			loop(6){
				let cLaser2 = CreateCurveLaserA1(shouX, shouY, 4, angle, 30, 15, C_LASER_RED, 0);
				ObjCrLaser_SetTipDecrement(cLaser2, 0);
				ObjMove_SetAngularVelocity(cLaser2, 5.1*n);
				ObjMove_SetMaxSpeed(cLaser2, 0.5);
				ObjMove_SetAcceleration(cLaser2, -0.1);
				moveShot(cLaser2);
				angle += 360/6
			}
			loop(6){
				let cLaser2 = CreateCurveLaserA1(shouX, shouY, 8, angle, 30, 15, C_LASER_GREEN, 0);
				ObjCrLaser_SetTipDecrement(cLaser2, 0);
				ObjMove_SetAngularVelocity(cLaser2, 10.1*n);
				ObjMove_SetMaxSpeed(cLaser2, 0.5);
				ObjMove_SetAcceleration(cLaser2, -0.1);
				moveShot(cLaser2);
				angle += 360/7
			}
		n*= -1;
		}
		angle += 30;
		wait(60);
	}
	task moveShot(shot){
		while(!Obj_IsDeleted(shot)){
			if(ObjMove_GetSpeed(shot) <= 0.5){
				wait(30);
				ObjMove_SetAngularVelocity(shot, 0);
				ObjMove_SetAcceleration(shot, 0.4);
				ObjMove_SetMaxSpeed(shot, 30);
				break;
			}
			yield;
		}
	} 

}

//Normal
task FireN(){
	wait(60);
	ObjMove_SetDestAtFrame(shou, GetStgFrameWidth/2, 200, 60);
	Obj_SetValue(shou,"cast",1);
	wait(120);
	let angle = 0;
	loop{
		let n = 1;
		loop(2){
			loop(5){
				let cLaser = CreateCurveLaserA1(shouX, shouY, 5, angle, 30, 15, C_LASER_YELLOW, 0);
				ObjCrLaser_SetTipDecrement(cLaser, 0);
				ObjMove_SetAngularVelocity(cLaser, 3.1*n);
				ObjMove_SetMaxSpeed(cLaser, 0.5);
				ObjMove_SetAcceleration(cLaser, -0.1);
				moveShot(cLaser);
				angle += 360/5
				
			}
			loop(10){
				angle += 360/10;
				let cLaser2 = CreateCurveLaserA1(shouX, shouY, 5, angle, 30, 15, C_LASER_RED, 0);
				ObjCrLaser_SetTipDecrement(cLaser2, 0);
				ObjMove_SetAngularVelocity(cLaser2, 5.1*n);
				ObjMove_SetMaxSpeed(cLaser2, 0.5);
				ObjMove_SetAcceleration(cLaser2, -0.1);
				moveShot(cLaser2);
				angle += 360/10
			}
		n*= -1;
		}
		angle += 30;
		wait(60);
	}
	task moveShot(shot){
		while(!Obj_IsDeleted(shot)){
			if(ObjMove_GetSpeed(shot) <= 0.5){
				wait(30);
				ObjMove_SetAngularVelocity(shot, 0);
				ObjMove_SetAcceleration(shot, 0.4);
				ObjMove_SetMaxSpeed(shot, 30);
				break;
			}
			yield;
		}
	} 
}

//Easy
task FireE(){
	
	wait(60);
	ObjMove_SetDestAtFrame(shou, GetStgFrameWidth/2, 200, 60);
	Obj_SetValue(shou,"cast",1);
	wait(120);
	let angle = 0;
	loop{
		let n = 1;
		loop(2){
			loop(5){
				let cLaser = CreateCurveLaserA1(shouX, shouY, 5, angle, 30, 15, C_LASER_YELLOW, 0);
				ObjCrLaser_SetTipDecrement(cLaser, 0);
				ObjMove_SetAngularVelocity(cLaser, 3.1*n);
				ObjMove_SetMaxSpeed(cLaser, 0.5);
				ObjMove_SetAcceleration(cLaser, -0.1);
				moveShot(cLaser);
				angle += 360/5
			}
		n*= -1;
		}
		angle += 30;
		wait(60);
	}
	task moveShot(shot){
		while(!Obj_IsDeleted(shot)){
			if(ObjMove_GetSpeed(shot) <= 0.5){
				wait(30);
				ObjMove_SetAngularVelocity(shot, 0);
				ObjMove_SetAcceleration(shot, 0.4);
				ObjMove_SetMaxSpeed(shot, 30);
				break;
			}
			yield;
		}
	} 
}



