#TouhouDanmakufu[Single]
#ScriptVersion[3]

#include"./functions.txt"

@Initialize
{
	objEnemy = ObjEnemy_Create(OBJ_ENEMY_BOSS);
	ObjEnemy_Regist(objEnemy);
	TXY;
	
	TEnemyWork;
	ObjEnemy_RenderKoi(objEnemy);
	let pos = Obj_GetValueD(objScene,"KOI_POS",[0,0]);
	ObjMove_SetPosition(objEnemy,pos[0],pos[1]);
	TEnd;
}

@Event
{
	alternative(GetEventType())
	case(EV_REQUEST_LIFE)
		{
		SetScriptResult(500);
		}
	case(EV_REQUEST_TIMER)
		{
		SetScriptResult(80);
		}
	case(EV_REQUEST_SPELL_SCORE)
		{
		SetScriptResult(30000);
		}
	case(EV_START_BOSS_SPELL)
		{
		SetScriptResult(true);
		}
}

task TEnemyWork
{
	ObjEnemy_SetDamageRate(objEnemy,0,0);
	
	yield;
	ObjMove_SetDestAtWeight(objEnemy,GetStgFrameWidth*0.5,GetStgFrameHeight*0.5-105,15,5);
	loop(120){yield;}
	
	ObjEnemy_SetRender(objEnemy,KOI_SPIN1);
	TSpellName("Rose Sign \"Boundary of Serious and Troll Scripts\"");
	ObjEnemyBossScene_StartSpell(GetEnemyBossSceneObjectID());
	loop(60){yield;}

	ObjEnemy_SetDamageRate(objEnemy,5,5);	
	loop(15){yield;}

	let spreadM = 32;

	let angleM = 90+180/5;
	let angleA = 0;
	
	let time = 75;
	let graph = [[SMALL_RED,ROSE_RED],[SMALL_GREEN,ROSE_GREEN]];
	TLife;
	loop
		{
		let spread = floor(spreadM);
		ascent(i in 0..spread)
			{
			let angle = i*360/spread+angleM;
			let shot = CreateShotA2(enmx+16*cos(angle),enmy+16*sin(angle),5,angle,-3/30,2,graph[i%2][0],8);
			ObjMove_AddPatternA2(shot,30,NO_CHANGE,NO_CHANGE,1/90,0,10);
			ObjMove_AddPatternA3(shot,52,NO_CHANGE,NO_CHANGE,1/15,0,10,graph[i%2][1]);
			ObjRender_SetBlendType(shot,BLEND_ADD_ARGB);
			}
		TSound;
		loop(floor(time)){yield;}
		if(spreadM > 5)
			{		
			spreadM = spreadM*0.85;
			}
		else
			{
			spreadM = 5;
			}
		if(time > 4)
			{		
			time = time*0.85;
			}
		else
			{
			time = 4;
			}
		angleM+=angleA;
		angleA+=0.6;
		}
	task TLife
		{
		loop(450){yield;}
		ObjEnemy_SetDamageRate(objEnemy,7.5,5);
		}
	task TSound
		{
		PlaySound("se_DeepShotHigh",20+time*25/75);
		loop(55){yield;}
		PlaySound("se_CuteShotLong",65);
		}
}	