#TouhouDanmakufu[Single]
#ScriptVersion[3]
#Title["MimaNon01"]
#Text["MimaNon01"]
#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("Mima",GetCurrentScriptDirectory~"dot_mima.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(2000);
	}
	case(EV_REQUEST_TIMER)
	{
		SetScriptResult(60);
	}
}

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

//----------------------------------------------------
task TWork
{
	ObjMove_SetPosition(objEnemy,GetStgFrameWidth*2,GetStgFrameHeight);
	yield;
	ObjMove_SetDestAtWeight(objEnemy, GetStgFrameWidth/2, 120, 10,10);
	DamageRateAtFrame(100, 50,240);
	wait(120);
	PlaySound("Charge2",100,0);
	SakuraCharge("PURPLE");
	wait(60);
	PlaySound("Eff5",100,0);
	ascent(i in 0..4)
	{
		StarCycle(i*90);
	}
}

task StarCycle(angle)
{
	let color = 270;
	if(angle%180==0){color = 269;}
	let obj = CreateShotOA1(objEnemy,0,angle,color,12);
	let r = 0;
	let count = 0;
	Trail(obj);
	ObjShot_SetSpellResist(obj,true);
	while(!Obj_IsDeleted(obj))
	{
		let px = GetEX1(GetEnemyX,r,r*2,count,angle);
		let py = GetEY1(GetEnemyY,r*2,r,count,angle);
		ObjMove_SetPosition(obj,px,py);
		if(r<60){r+=0.5;}
		if(angle%180==0){count++;}
		else{count--;}
		if(count>120 && count%8==0 && color == 269)
		{
				MiniStar;
		}
		
		if(-count>120 && -count%64==0 && color == 270)
		{
			PlaySound("Shot6",95,0);
			ascent(j in 0..6)
			{
				CreateShotOA1(obj,2.5+j/12,GetAngleToPlayer(obj),55,8);
			}
		}
		
		yield;
	}
	task MiniStar
	{	
				PlaySound("BulletWave",90,0);
				ascent(i in 0..3)
				{
					CreateShotOA1(obj,2+i/2,GetAngleToEnemy(obj)+180,165,8);
					CreateShotOA1(obj,2+i/2,GetAngleToEnemy(obj),165,8);
					wait(2);
				}
	}	
}

		task Trail(obj)
		{
			while(!Obj_IsDeleted(obj))
			{
				let dummy = CreateShotOA1(obj,0,ObjMove_GetAngle(obj),ObjShot_GetImageID(obj)+500,0);
				Shrink(dummy,35);
				ObjShot_SetDeleteFrame(dummy,35);
				ObjShot_SetIntersectionEnable(dummy,false);
				wait(3);
			}
		}
		
	task Shrink(obj,time)
	{
		ObjShot_SetSpellResist(obj,true);
		descent(i in 0..time)
		{
			ObjRender_SetScaleXYZ(obj,i/time,i/time,0);
			ObjRender_SetColor(obj,128,128,128);
			yield;
		}
		Obj_Delete(obj);
	}

//BorderMove(90,GetStgFrameWidth-90,90,150,10,90);

//----------------------------------------------------
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());
}
