#TouhouDanmakufu[Single]
#ScriptVersion[3]
#Title["AkyuNon01"]
#Text["AkyuNon01"]
#Background["./NoobSystem/Default_Background_IceMountain.txt"]
#BGM["./Novum.mp3"]
#System["./NoobSystem/Default_System2.txt"]
#Player[DEFAULT]

#include"./Shot/AllStarShot_Const.dnh"
#include"./NoobSystem/Default_Effect.txt"
#include"./Function/Basic.txt"
#include"./Function/SoundFunctions.txt"
#include"./Function/EffectFunctions.txt"
#include"./Animations.txt"

let objEnemy;
let cx = GetStgFrameWidth/2;
let ct = GetStgFrameHeight/2;
@Initialize
{
	objEnemy = ObjEnemy_Create(OBJ_ENEMY_BOSS);
	ObjEnemy_Regist(objEnemy);
	ObjEnemy_SetDamageRate(objEnemy, 0, 0);
	TWork;
	TAnimate("Akyu",GetCurrentScriptDirectory~"dot_akyu.png");
	TEnd;
	DeleteShotAll(TYPE_ALL, TYPE_ITEM);
}

@MainLoop
{
	ObjEnemy_SetIntersectionCircleToPlayer(objEnemy,ObjMove_GetX(objEnemy),ObjMove_GetY(objEnemy),18);
	ObjEnemy_SetIntersectionCircleToShot(objEnemy,ObjMove_GetX(objEnemy),ObjMove_GetY(objEnemy),24);
	yield;
}

@Event
{
	alternative(GetEventType())
	case(EV_REQUEST_LIFE)
	{
		SetScriptResult(2250);
	}
	case(EV_REQUEST_TIMER)
	{
		SetScriptResult(60);
	}
}

//----------------------------------------------------

task TWork
{
	ObjMove_SetPosition(objEnemy,-GetStgFrameWidth,GetStgFrameHeight);
	yield;
	ObjMove_SetDestAtWeight(objEnemy, GetStgFrameWidth/2, 135, 10,10);
	DamageRateAtFrame(100, 50,240);
	wait(120);
	while(ObjEnemy_GetInfo(objEnemy, INFO_LIFE) > 0)
	{
	PlaySound("Charge2",100,0);
	SakuraCharge("ORANGE");
	wait(60);
	SplitAmulet("ORANGE",15);
	wait(75);
	SplitAmulet("GREEN",0);
	wait(45);
	SplitAmulet("GREEN",18);
	wait(45);
	SplitAmulet("GREEN",0);
	wait(45);
	BorderMove(120,GetStgFrameWidth-120,90,150,10,10);
	wait(45);
	PlaySound("Charge2",100,0);
	SakuraCharge("ORANGE");
	wait(60);
	SplitAmulet("BLUE",0);
	wait(75);
	SplitAmulet("RED",0);
	wait(45);
	SplitAmulet("RED",45);
	wait(45);
	SplitAmulet("RED",0);
	wait(60);
	BorderMove(120,GetStgFrameWidth-120,90,150,10,10);
	wait(60);
	}
}

task SplitAmulet(color,pangle)
{
	PlaySound("Shot1",100,0);
	PlaySound("Eff1",100,75);
	if(color=="ORANGE")
	{
		ascent(i in 0..12)
		{
			OrangeAmulet(i*30+pangle);
		}
		task OrangeAmulet(angle)
		{
			let obj = CreateShotA2(GetEnemyX,GetEnemyY,4,angle,-4/75,0.5,611,8);
			ObjRender_SetScaleXYZ(obj,2,2,2);
			wait(75);
			ascent(i in -3..4)
			{
				if(!Obj_IsDeleted(obj))
				{
					ascent(j in 0..2)
					{
						CreateShotA2(ObjMove_GetX(obj),ObjMove_GetY(obj),3.5+j,180+ObjMove_GetAngle(obj)+i*30,(-3.5-j)/60,1.5+j/2,111,8);
					}
				}
			}
			Obj_Delete(obj);
		}
	}
	if(color=="GREEN")
	{
		ascent(i in 0..10)
		{
			GreenAmulet(i*36+pangle+GetAngleToPlayer(objEnemy));
		}
		task GreenAmulet(angle)
		{
			let obj = CreateShotA2(GetEnemyX,GetEnemyY,3,angle,-3/75,0.5,607,8);
			ObjRender_SetScaleXYZ(obj,2,2,2);
			wait(75);
			ascent(i in -1..2)
			{
				if(!Obj_IsDeleted(obj))
				{
					ascent(j in 0..2)
					{
						CreateShotA2(ObjMove_GetX(obj),ObjMove_GetY(obj),3+j,ObjMove_GetAngle(obj)+i*5,(-3-j)/60,1.5+j/2,107,8);
					}
				}
			}
			Obj_Delete(obj);
		}
	}
	if(color=="BLUE")
	{
		ascent(i in 0..24)
		{
			BlueAmulet(i*15+pangle,2+2*(i%2));
		}
		task BlueAmulet(angle,v)
		{
			let obj = CreateShotA2(GetEnemyX,GetEnemyY,v,angle,-v/75,0.5,603,8);
			let way = 1;
			if(v>3){way=-1;}
			ObjRender_SetScaleXYZ(obj,2,2,2);
			wait(75);
			ascent(i in -1..2)
			{
				if(!Obj_IsDeleted(obj))
				{
					ascent(j in 0..2)
					{
						CreateShotA2(ObjMove_GetX(obj),ObjMove_GetY(obj),2+j*2,ObjMove_GetAngle(obj)+i*15,(-2-j*2)/60,1.5+j/1.5,103,8);
						CreateShotA2(ObjMove_GetX(obj),ObjMove_GetY(obj),2+j*2,ObjMove_GetAngle(obj)+i*15+180,(-2-j*2)/60,1.5+j/1.5,103,8);
					}
				}
			}
			Obj_Delete(obj);
		}
	}
	if(color=="RED")
	{
		ascent(i in 0..8)
		{
			RedAmulet(i*45+pangle+GetAngleToPlayer(objEnemy));
		}
		task RedAmulet(angle)
		{
			let obj = CreateShotA2(GetEnemyX,GetEnemyY,3,angle,-3/75,0.5,599,8);
			ObjRender_SetScaleXYZ(obj,2,2,2);
			wait(75);
			ascent(i in -1..2)
			{
				if(!Obj_IsDeleted(obj))
				{
					ascent(j in 0..2)
					{
						CreateShotA2(ObjMove_GetX(obj),ObjMove_GetY(obj),3+j,GetAngleToPlayer(obj)+i*5,(-3-j)/60,1.5+j/2,99,8);
					}
				}
			}
			Obj_Delete(obj);
		}
	}
}


//----------------------------------------------------
task TEnd
{
	while(ObjEnemy_GetInfo(objEnemy, INFO_LIFE) > 0)
	{
		yield;
	}

	let ex = ObjMove_GetX(objEnemy);
	let ey = ObjMove_GetY(objEnemy);
	TExplosionA(ex, ey, 10, 0.6);
	DeleteShotAll(TYPE_ALL, TYPE_ITEM);
	Obj_Delete(objEnemy);

	loop(30)
	{
		DeleteShotAll(TYPE_ALL, TYPE_IMMEDIATE);
		yield;
	}

	CloseScript(GetOwnScriptID());
}
