//#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);
	
	let cx = GetStgFrameWidth() / 4;
	
	renderShouUFO(shou);
	renderKaguyaIN(kaguya);
	
	ObjMove_SetX(shou, GetStgFrameWidth());
	
	ObjMove_SetDestAtFrame(shou, cx, 100, 60);
	ObjMove_SetDestAtFrame(kaguya, GetStgFrameWidth()-cx, 100, 60);
	ObjEnemy_SetLife(kaguya, 471);
	BossManage;
	TMain();
	
	wait(60);
	Obj_SetValue(shou,"cast",1);
	Obj_SetValue(kaguya,"cast",1);
	if(GetCommonData("Difficulty",1) == 1){KFireE; SFireE;}
	else if(GetCommonData("Difficulty",1) == 2){KFireN; SFireN;}
	else if(GetCommonData("Difficulty",1) == 3){KFireH; SFireH;}
	else if(GetCommonData("Difficulty",1) == 4){KFireL; SFireL;}
}

@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,15,100);
	ObjEnemy_SetDamageRate(kaguya,15,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()); 
}
//Luna(r)tic kaguya
task KFireL(){
	/*
	wait(60);
	let angle = rand(0, 360);
	let speed = 5;
	loop{
		speed = 3;
		loop(20){
			let shot = CreateShotA1(shouX,shouY,speed,angle,DS_RICE_S_BLUE,0);
			let shot2 = CreateShotA1(kaguyaX,kaguyaY,speed,angle,DS_RICE_S_RED,0);
			angle += 360/20;
		}
		angle += rand(0,360);
		wait(20);
	}
	*/
	wait(60);
	let angle = rand(0, 360);
	let angle2 = angle;
	let angle3 = 0;
	let speed = 5;
	loop{
		speed = 5;
		loop(8){
			let shot1 = CreateShotA2(kaguyaX,kaguyaY,speed,angle, -0.1, 0,D_PELLET_RED,10);
			let shot2 = CreateShotA2(kaguyaX,kaguyaY,speed,angle2, -0.1, 0,D_PELLET_BLUE,10);
			moveShot(shot1, 1, PELLET_RED,angle3);
			moveShot(shot2, -1, PELLET_BLUE, angle3);
			angle += 0.7;
			angle2 -= 0.7;
			speed-=0.1;
			
		}
		angle3++;
		angle += 137.3/2;
		angle2 -= 137.3/2;
		wait(2);
	}
	task moveShot(shot, n, graphic, angle){
		
		while(!Obj_IsDeleted(shot)){
			if(ObjMove_GetSpeed(shot) <= 0){
				let newShot = CreateShotA1(ObjMove_GetX(shot),ObjMove_GetY(shot),3.7,ObjMove_GetAngle(shot) + (angle*n),graphic,0);
				angle += 3.7;
				
				Obj_Delete(shot);
				break;
			}
			yield;
		}
	}
}

//Hard kaguya
task KFireH(){
	/*
	wait(60);
	let angle = rand(0, 360);
	let speed = 5;
	loop{
		speed = 3;
		loop(20){
			let shot = CreateShotA1(shouX,shouY,speed,angle,DS_RICE_S_BLUE,0);
			let shot2 = CreateShotA1(kaguyaX,kaguyaY,speed,angle,DS_RICE_S_RED,0);
			angle += 360/20;
		}
		angle += rand(0,360);
		wait(20);
	}
	*/
	wait(60);
	let angle = rand(0, 360);
	let angle2 = angle;
	let angle3 = 0;
	let speed = 5;
	loop{
		speed = 5;
		loop(7){
			let shot1 = CreateShotA2(kaguyaX,kaguyaY,speed,angle, -0.1, 0,D_PELLET_RED,10);
			let shot2 = CreateShotA2(kaguyaX,kaguyaY,speed,angle2, -0.1, 0,D_PELLET_BLUE,10);
			moveShot(shot1, 1, PELLET_RED,angle3);
			moveShot(shot2, -1, PELLET_BLUE, angle3);
			angle += 1;
			angle2 -= 1;
			speed-=0.1;
			
		}
		angle3++;
		angle += 137.3/2;
		angle2 -= 137.3/2;
		wait(2);
	}
	task moveShot(shot, n, graphic, angle){
		
		while(!Obj_IsDeleted(shot)){
			if(ObjMove_GetSpeed(shot) <= 0){
				let newShot = CreateShotA1(ObjMove_GetX(shot),ObjMove_GetY(shot),3.3,ObjMove_GetAngle(shot) + (angle*n),graphic,0);
				angle += 3.7;
				
				Obj_Delete(shot);
				break;
			}
			yield;
		}
	}
}

//Normal kaguya
task KFireN(){
	/*
	wait(60);
	let angle = rand(0, 360);
	let speed = 5;
	loop{
		speed = 3;
		loop(20){
			let shot = CreateShotA1(shouX,shouY,speed,angle,DS_RICE_S_BLUE,0);
			let shot2 = CreateShotA1(kaguyaX,kaguyaY,speed,angle,DS_RICE_S_RED,0);
			angle += 360/20;
		}
		angle += rand(0,360);
		wait(20);
	}
	*/
	wait(60);
	let angle = rand(0, 360);
	let angle2 = angle;
	let angle3 = 0;
	let speed = 5;
	loop{
		speed = 5;
		loop(6){
			let shot1 = CreateShotA2(kaguyaX,kaguyaY,speed,angle, -0.1, 0,D_PELLET_RED,10);
			let shot2 = CreateShotA2(kaguyaX,kaguyaY,speed,angle2, -0.1, 0,D_PELLET_BLUE,10);
			moveShot(shot1, 1, PELLET_RED,angle3);
			moveShot(shot2, -1, PELLET_BLUE, angle3);
			angle += 1;
			angle2 -= 1;
			speed-=0.1;
			
		}
		angle3++;
		angle += 137.3/2;
		angle2 -= 137.3/2;
		wait(4);
	}
	task moveShot(shot, n, graphic, angle){
		
		while(!Obj_IsDeleted(shot)){
			if(ObjMove_GetSpeed(shot) <= 0){
				let newShot = CreateShotA1(ObjMove_GetX(shot),ObjMove_GetY(shot),3.5,ObjMove_GetAngle(shot) + (angle*n),graphic,0);
				angle += 3.7;
				
				Obj_Delete(shot);
				break;
			}
			yield;
		}
	}
}

//Easy kaguya
task KFireE(){
	/*
	wait(60);
	let angle = rand(0, 360);
	let speed = 5;
	loop{
		speed = 3;
		loop(20){
			let shot = CreateShotA1(shouX,shouY,speed,angle,DS_RICE_S_BLUE,0);
			let shot2 = CreateShotA1(kaguyaX,kaguyaY,speed,angle,DS_RICE_S_RED,0);
			angle += 360/20;
		}
		angle += rand(0,360);
		wait(20);
	}
	*/
	wait(60);
	let angle = rand(0, 360);
	let angle2 = angle;
	let angle3 = 0;
	let speed = 5;
	loop{
		speed = 5;
		loop(5){
			let shot1 = CreateShotA2(kaguyaX,kaguyaY,speed,angle, -0.1, 0,D_PELLET_RED,10);
			let shot2 = CreateShotA2(kaguyaX,kaguyaY,speed,angle2, -0.1, 0,D_PELLET_BLUE,10);
			moveShot(shot1, 1, PELLET_RED,angle3);
			moveShot(shot2, -1, PELLET_BLUE, angle3);
			angle += 1;
			angle2 -= 1;
			speed-=0.1;
			
		}
		angle3++;
		angle += 137.3/2;
		angle2 -= 137.3/2;
		wait(5);
	}
	task moveShot(shot, n, graphic, angle){
		
		while(!Obj_IsDeleted(shot)){
			if(ObjMove_GetSpeed(shot) <= 0){
				let newShot = CreateShotA1(ObjMove_GetX(shot),ObjMove_GetY(shot),3,ObjMove_GetAngle(shot) + (angle*n),graphic,0);
				angle += 3.7;
				
				Obj_Delete(shot);
				break;
			}
			yield;
		}
	}
}

//Lunatic shou
task SFireL(){
	wait(120);
	let angle = rand(0,360);;
	let angle2 = angle+180;
	loop{
			
			let cLaser = CreateCurveLaserA1(shouX, shouY, 5, angle, 30, 15, C_LASER_YELLOW, 0);
			ObjCrLaser_SetTipDecrement(cLaser, 0);
			ObjMove_SetAngularVelocity(cLaser, 3.2);
			ObjMove_SetMaxSpeed(cLaser, 0.5);
			ObjMove_SetAcceleration(cLaser, -0.1);
			moveShot(cLaser);
			
			let cLaser2 = CreateCurveLaserA1(shouX, shouY, 5, angle2, 30, 15, C_LASER_YELLOW, 0);
			ObjCrLaser_SetTipDecrement(cLaser2, 0);
			ObjMove_SetAngularVelocity(cLaser2, -3.2);
			ObjMove_SetMaxSpeed(cLaser2, 0.5);
			ObjMove_SetAcceleration(cLaser2, -0.1);
			moveShot(cLaser2);
			angle2 += 120/7+0.7;
			angle -= 90/7 + 0.7;
			wait(10);
		
	}
	
	task moveShot(shot){
		while(!Obj_IsDeleted(shot)){
			if(ObjMove_GetSpeed(shot) <= 0.5){
				ObjMove_SetAngularVelocity(shot, 0);
				ObjMove_SetAcceleration(shot, 0.15);
				ObjMove_SetMaxSpeed(shot, 20);
				break;
			}
			yield;
		}
	}
}

//Hard shou
task SFireH(){
	wait(120);
	let angle = rand(0,360);;
	let angle2 = angle+180;
	loop{
			
			let cLaser = CreateCurveLaserA1(shouX, shouY, 5, angle, 30, 15, C_LASER_YELLOW, 0);
			ObjCrLaser_SetTipDecrement(cLaser, 0);
			ObjMove_SetAngularVelocity(cLaser, 3.2);
			ObjMove_SetMaxSpeed(cLaser, 0.5);
			ObjMove_SetAcceleration(cLaser, -0.1);
			moveShot(cLaser);
			
			let cLaser2 = CreateCurveLaserA1(shouX, shouY, 5, angle2, 30, 15, C_LASER_YELLOW, 0);
			ObjCrLaser_SetTipDecrement(cLaser2, 0);
			ObjMove_SetAngularVelocity(cLaser2, -3.2);
			ObjMove_SetMaxSpeed(cLaser2, 0.5);
			ObjMove_SetAcceleration(cLaser2, -0.1);
			moveShot(cLaser2);
			angle2 += 120/6+0.7;
			angle -= 90/6 + 0.7;
			wait(11);
		
	}
	
	task moveShot(shot){
		while(!Obj_IsDeleted(shot)){
			if(ObjMove_GetSpeed(shot) <= 0.5){
				ObjMove_SetAngularVelocity(shot, 0);
				ObjMove_SetAcceleration(shot, 0.15);
				ObjMove_SetMaxSpeed(shot, 20);
				break;
			}
			yield;
		}
	}
}

//Normal shou
task SFireN(){
	wait(120);
	let angle = rand(0,360);;
	let angle2 = angle+180;
	loop{
			
			let cLaser = CreateCurveLaserA1(shouX, shouY, 5, angle, 30, 15, C_LASER_YELLOW, 0);
			ObjCrLaser_SetTipDecrement(cLaser, 0);
			ObjMove_SetAngularVelocity(cLaser, 3.2);
			ObjMove_SetMaxSpeed(cLaser, 0.5);
			ObjMove_SetAcceleration(cLaser, -0.1);
			moveShot(cLaser);
			
			let cLaser2 = CreateCurveLaserA1(shouX, shouY, 5, angle2, 30, 15, C_LASER_YELLOW, 0);
			ObjCrLaser_SetTipDecrement(cLaser2, 0);
			ObjMove_SetAngularVelocity(cLaser2, -3.2);
			ObjMove_SetMaxSpeed(cLaser2, 0.5);
			ObjMove_SetAcceleration(cLaser2, -0.1);
			moveShot(cLaser2);
			angle2 += 120/5+0.7;
			angle -= 90/5 + 0.7;
			wait(12);
		
	}
	
	task moveShot(shot){
		while(!Obj_IsDeleted(shot)){
			if(ObjMove_GetSpeed(shot) <= 0.5){
				ObjMove_SetAngularVelocity(shot, 0);
				ObjMove_SetAcceleration(shot, 0.15);
				ObjMove_SetMaxSpeed(shot, 20);
				break;
			}
			yield;
		}
	}
}

//Easy shou
task SFireE(){
	wait(120);
	let angle = rand(0,360);;
	let angle2 = angle+180;
	loop{
			
			let cLaser = CreateCurveLaserA1(shouX, shouY, 5, angle, 30, 15, C_LASER_YELLOW, 0);
			ObjCrLaser_SetTipDecrement(cLaser, 0);
			ObjMove_SetAngularVelocity(cLaser, 3.2);
			ObjMove_SetMaxSpeed(cLaser, 0.5);
			ObjMove_SetAcceleration(cLaser, -0.1);
			moveShot(cLaser);
			
			let cLaser2 = CreateCurveLaserA1(shouX, shouY, 5, angle2, 30, 15, C_LASER_YELLOW, 0);
			ObjCrLaser_SetTipDecrement(cLaser2, 0);
			ObjMove_SetAngularVelocity(cLaser2, -3.2);
			ObjMove_SetMaxSpeed(cLaser2, 0.5);
			ObjMove_SetAcceleration(cLaser2, -0.1);
			moveShot(cLaser2);
			angle2 += 120/4+0.7;
			angle -= 90/4 + 0.7;
			wait(13);
		
	}
	
	task moveShot(shot){
		while(!Obj_IsDeleted(shot)){
			if(ObjMove_GetSpeed(shot) <= 0.5){
				ObjMove_SetAngularVelocity(shot, 0);
				ObjMove_SetAcceleration(shot, 0.15);
				ObjMove_SetMaxSpeed(shot, 20);
				break;
			}
			yield;
		}
	}
}



