#東方弾幕風[Single]
#ScriptVersion[3]
#Title["SP5"]
#Text["FROGSLUG"]
#System["./default_system/Default_System.txt"]
#Background["./default_System/Default_Background.txt"]
#include"./default_system/Default_Index.txt"

let objBoss;
let objEn;
let objEn2;
	
let BossX;
let BossY;

@Initialize {
	SetPlayerClip(126, 12, 510, 468);
	objBoss = ObjEnemy_Create(OBJ_ENEMY_BOSS);
	ObjEnemy_Regist(objBoss);
	objEn = ObjEnemy_Create(OBJ_ENEMY);
	ObjEnemy_Regist(objEn);
	objEn2 = ObjEnemy_Create(OBJ_ENEMY);
	ObjEnemy_Regist(objEn2);
	
	ObjMove_SetPosition(objBoss, 0, 0);
	ObjMove_SetPosition(objEn2, 0, 0);
	ObjMove_SetDestAtWeight(objBoss, GetStgFrameWidth/2, GetStgFrameHeight/2-100, 5, 4);
	ObjMove_SetDestAtWeight(objEn, GetStgFrameWidth/2+150, GetStgFrameHeight/2-100, 5, 4);

	Initialization;
	Spireet;
	
	Main;
	end;
} 

task Spireet{
let obj = Spirit(GetCommonData("BossX2", 0), GetCommonData("BossY2", 0));
	ascent(i in 0..7){
	Particle(GetX(obj), GetY(obj), rand(1, 8), rand(0,360), 0.5, rand(0,360), "Cherry", [12, 255, 12], 4);
	}
wait(60);
ObjMove_SetDestAtWeight(obj, GetStgFrameWidth/2, GetStgFrameHeight/2-150, 8, 2);
wait(60*2);
	ascent(i in 0..1){
	Vortex(GetX(obj), GetY(obj), 0.1, 0.06+i/50, 255, -10, [122, 122, 255], 6+i);}
	ascent(i in 0..10){
	Particle(GetX(obj), GetY(obj), rand(1, 8), rand(0,360), 0.5, rand(0,360), "Cherry", [122, 122, 255], 4);
	}
RenderKaisen(objEn2);
ObjMove_SetPosition(objEn2, GetX(obj), GetY(obj));
Obj_Delete(obj); 
}

task Initialization{
	RenderGaraiya(objBoss);
	RenderGaraiyaNoShikigami(objBoss);
	RenderKujiru(objEn);
	//MagicRing(objBoss);
	HitSound(objBoss,60,500);
	TimerCountdown;
	SetArmor(objBoss, [90, 80], 180);
	EnemyMarker(objBoss);
	Color;
}

@Event { 
	alternative(GetEventType())
	case(EV_REQUEST_LIFE){SetScriptResult(1);}
	case(EV_REQUEST_TIMER){SetScriptResult(45);}
	case(EV_REQUEST_SPELL_SCORE){SetScriptResult(10000);}
	case(EV_REQUEST_IS_DURABLE_SPELL){SetScriptResult(true);}
	//case(EV_REQUEST_IS_LAST_SPELL){SetScriptResult(true);}
} 

@MainLoop {
	BossX = ObjMove_GetX(objBoss);
	BossY = ObjMove_GetY(objBoss);
	SetCommonData("BossX", BossX);
	SetCommonData("BossY", BossY);
	SetCommonData("BossX2", GetX(objEn));
	SetCommonData("BossY2", GetY(objEn));
	SetCommonData("BossX3", GetX(objEn2));
	SetCommonData("BossY4", GetY(objEn2));
	yield;
} 

@Finalize {
} 

task Color{
wait(180);
ascent(i in 0..64){
SetCommonData("StgFrameColor", [255, 126+i*2, 0+i*4]);
SetCommonData("StgFrameAlpha", 255-i);
SetCommonData("BossAlpha", 255-i*2);
yield;
}
}

task Main { 
wait(120);
let path = GetCurrentScriptDirectory ~ "./default_system/img/Garaiya.png";
let path2 = GetCurrentScriptDirectory ~ "./default_system/img/Garaiya.png";
SetCommonData("SP", "All");
ObjMove_SetDestAtWeight(objBoss, GetStgFrameWidth/2, GetStgFrameHeight/2, 5, 4);
ObjMove_SetDestAtWeight(objEn, GetStgFrameWidth/2, GetStgFrameHeight/2, 5, 4);
SpellCard(180, "Shikigami Card &quot;Tri-Force&quot;", [122, 122, 122], path, path2, 0, 0, 1);
wait(30);
Spears;

ascent(i in 1..4){
let obj = Enemy(BossX, BossY);
RenderKujiru(obj);
if(i == 1){SinLeft(obj); KnivesRight(obj);}
if(i == 2){SinUp(obj); KnivesDown(obj); Slugs(obj);}
if(i == 3){SinRight(obj); KnivesLeft(obj);}
}
SinDown;
KnivesUp;

wait(60*4);
	
Slugs(objEn);

	loop{
		descent(i in 0..3){
			Worm(i*4);
			wait(10);
		}
		wait(60*12);
	}
}



task KnivesUp{
wait(60*4);
	loop{
	let obje = FireShotA2(GetX(objEn), GetY(objEn), 7, 270, -0.5, -8, KNIFE_DBLUE, 10);
	PlaySound("lensmbullet", 55, 0);
	wait(12);
	}
}

task KnivesRight(obj){
wait(60*4);
	loop{
	let obje = FireShotA2(GetX(obj), GetY(obj), 7, 0, -0.5, -8, KNIFE_DBLUE, 10);
	PlaySound("lensmbullet", 55, 0);
	wait(12);
	}
}

task KnivesLeft(obj){
wait(60*4);
	loop{
	let obje = FireShotA2(GetX(obj), GetY(obj), 7, 180, -0.5, -8, KNIFE_DBLUE, 10);
	PlaySound("lensmbullet", 55, 0);
	wait(12);
	}
}

task KnivesDown(obj){
wait(60*4);
	loop{
	let obje = FireShotA2(GetX(obj), GetY(obj), 7, 90, -0.5, -8, KNIFE_DBLUE, 10);
	PlaySound("lensmbullet", 55, 0);
	wait(12);
	}
}

task SinLeft(obj){
let a = 270;
	loop{
	ObjMove_SetDestAtWeight(obj,GetStageLeft, GetCenterY+200*sin(a+180), 5, 4);
	a++;
	yield;
	}
}
task SinRight(obj){
let a = 270;
	loop{
	ObjMove_SetDestAtWeight(obj,GetStageRight, GetCenterY+200*sin(a), 5, 4);
	a++;
	yield;
	}
}
task SinUp(obj){
let a = 270;
	loop{
	ObjMove_SetDestAtWeight(obj,GetCenterX+200*sin(a+180), GetStageUp, 5, 4);
	a++;
	yield;
	}
}
task SinDown{
let a = 270;
	loop{
	ObjMove_SetDestAtWeight(objEn,GetCenterX+200*sin(a), GetStageDown, 5, 4);
	a++;
	yield;
	}
}


task Slugs(tar){
let a = 1;
wait(60*7);
	loop{
			ascent(i in -1..2){
			let obj = CreateCurveLaserA1(GetX(tar), GetY(tar), 0.5, GetAngleToPlayer(tar)+i*6, 18, 15, SLUG, 10);
			ObjCrLaser_SetTipDecrement(obj, 0);
			Waet(obj);
			a = -a;
			}
		wait(60*3.2);
	}
	
	task Waet(obj){
	wait(60);
	Pinpoint(obj);
	}
}

task Worm(a){
		ascent(i in 0..11){
			let obj = FireShotA1(GetStageRight-10, GetStageUp+a, 4, 10, DB_BULLET_GREY, 10);
			ObjRender_SetColor(obj, 255, 126, 0);
			BounceX(obj, 8);
			let obj2 = FireShotA1(GetStageLeft+10, GetStageDown-a, 4, 180+10, DB_BULLET_GREY, 10);
			ObjRender_SetColor(obj2, 255, 126, 0);
			BounceX(obj2, 8);
			wait(3);
		}
}


	task Pinpoint(obj){
		Angle(obj);
		Laser(obj);	
	}
	task Laser(obj){
	let las = CreateStraightLaserA1(GetX(obj), GetY(obj), ObjMove_GetAngle(obj), 700, 25, 0, SS_LASER_GREY, 999999);
	let a = 0;
	ObjRender_SetColor(las, 122, 122, 255);
	while(!Obj_IsDeleted(obj)){
	ObjRender_SetAlpha(las, a);
	ObjMove_SetPosition(las, GetX(obj), GetY(obj));
	ObjStLaser_SetAngle(las, ObjMove_GetAngle(obj));
	if(a < 255){a += 8;}
	yield;
	}
	ObjShot_FadeDelete(obj);
	}
	task Angle(obj){
	wait(60);
	while(!Obj_IsDeleted(obj)){
	let angl = ObjMove_GetAngle(obj);
	if(angl < GetAngleToPlayer(obj) + 3 && angl > GetAngleToPlayer(obj) - 3){Redirect(obj); break;}
	yield;
	}
	while(!Obj_IsDeleted(obj)){
	yield;
	}
	Obj_Delete(obj);
		task Redirect(obj){
		ObjMove_AddPatternA2(obj, 0, NO_CHANGE, NO_CHANGE, 0, 0, 10);
		ObjMove_AddPatternA2(obj, 15, 25, NO_CHANGE, 0.2, 0, 10);
		PlaySound("warning", 75, 0);
		PlaySound("lensmlaser", 60, 15);
		}
	}

task BounceX(obj, time){
	let count = 0;
	while(!Obj_IsDeleted(obj) && count < time){
	if(true){
		if(GetX(obj) < GetStageLeft){
		ObjMove_SetX(obj,GetStageLeft);
		let spd = 9;
		let spd2 = -1.5;
		let ang = ObjMove_GetAngle(obj);
		ObjMove_AddPatternB2(obj, 0, spd, spd2, -0.2, 0, -10, 10);
		PlaySound("spirit", 45, 0);
		count++;
		}
	}
	else{}
	if(true){
		if(GetX(obj) > GetStageRight){
		ObjMove_SetX(obj,GetStageRight);
		let spd = -9;
		let spd2 = 1.5;
		let ang = ObjMove_GetAngle(obj);
		ObjMove_AddPatternB2(obj, 0, spd, spd2, 0.2, 0, 10, 10);
		PlaySound("spirit", 45, 0);
		count++;
		}
	}
	else{}
	if(true){
		if(GetY(obj) < GetStageUp){
		ObjMove_SetY(obj,GetStageUp+1);
		let spd = 9;
		let spd2 = 1.5;
		let ang = ObjMove_GetAngle(obj);
		ObjMove_AddPatternB2(obj, 0, spd2, spd, 0, -0.2, 10, -10);
		PlaySound("spirit", 45, 0);
		count++;
		}
	}
	else{}
	if(true){
		if(GetY(obj) > GetStageDown){
		ObjMove_SetY(obj,GetStageDown-1);
		let spd = -9;
		let spd2 = -1.5;
		let ang = ObjMove_GetAngle(obj);
		ObjMove_AddPatternB2(obj, 0, spd2, spd, 0, 0.2, -10, 10);
		PlaySound("spirit", 45, 0);
		count++;
		}
	}
	else{}
	yield;
	}
}

task Spears{
ascent(j in 1..7){
	ascent(i in 0..5){
		let p = Spear(GetX(objEn2)+(25*j)*cos(i*360/5+j*24), GetY(objEn2)+(25*j)*sin(i*360/5+j*24), 0.5);
		Rotate(p, i*360/5+j*8);
		//ObjMove_SetDestAtWeight(p, GetX(objEn2)+100*cos(GetAngleToPlayer(objEn2)+180), GetY(objEn2)+100*sin(GetAngleToPlayer(objBoss)+180), 5, 4);
	}
	PlaySound("warning", 75, 0);
wait(15);
}
task Rotate(p, ang){
let a = -90;
	loop(60*2){
	Obj_SetValue(p, "Angle", ang+360*cos(a));
	if(a != 0){a+=1;}
	yield;
	}
	Obj_SetValue(p, "Angle", ang);
	ObjMove_AddPatternA2(p, 0, 0, ang, 0.1, 0, 10);
	PlaySound("lensmlaser", 66, 0);
}

}

task end{
    while(ObjEnemy_GetInfo(objBoss, INFO_LIFE) > 0){yield;}
	NotifyEvent(GetStageID, EV_USER_STAGE, [true, true, true, false, false, false]); //smexplosion, smparticles, items, bigexplosion, bigparticles, shake+slow
    Obj_Delete(objBoss);
    DeleteShotAll(TYPE_ALL, TYPE_ITEM);
    SetAutoDeleteObject(true);
    CloseScript(GetOwnScriptID());
} 