#TouhouDanmakufu[Single]
#ScriptVersion[3]

#include "./functions.txt"

timer = 55;

@Initialize
{
	Obj_SetValue(GetEnemyBossSceneObjectID,"INIT",false);
	objEnemy = ObjEnemy_Create(OBJ_ENEMY_BOSS);
	ObjEnemy_Regist(objEnemy);
	ObjEnemy_SetDamageRate(objEnemy,0,0);

	TEnemyStart;
	ObjEnemy_Render; 
	TLife(270,20,20,0,0,155,12.5);
}

@MainLoop
{
	yield;
}

task TEnemyStart
{
	ObjMove_SetDestAtWeight(objEnemy,GetStgFrameWidth/2,GetStgFrameHeight/2-90,15,2);
	loop(60){yield;}
	CreateBossAura(0);
	loop(65)
		{
		ascent(i in 0..2)
			{
			famAngle[i] = famAngle[i]+(i*2-1)*(0.3+i*0.6)*1.5;
			}
		Obj_SetValue(objScene,"FAM_ANGLE",famAngle);
		yield;
		}
	TEnemyWork;
	ObjEnemyBossScene_SetSpellTimer(objScene,timer*60);
	TEnd(false);
	loop
		{
		ascent(i in 0..2)
			{
			famAngle[i] = famAngle[i]+(i*2-1)*(0.3+i*0.6)*1.5;
			}
		Obj_SetValue(objScene,"FAM_ANGLE",famAngle);
		yield;
		}
}

@Event
{
	alternative(GetEventType())
	case(EV_REQUEST_LIFE)
		{
		SetScriptResult(5000);
		}
	case(EV_REQUEST_TIMER)
		{
		SetScriptResult(200);
		}
	case(EV_REQUEST_SPELL_SCORE)
		{
		SetScriptResult(30000);
		}
}
task TEnemyWork
{
	TXY;
	let spread = [12+Dif*2,44+Dif*10];
	let speedM = 1.67+Dif*0.5;
	let graph = [LEN_PURPLE,LEN_GRAY];
	let dirM = 1;
	let counter = -1;
	let angleM;
	loop
		{
		counter+=1;
		if (counter%(60-Dif*15) == 0)
			{
			TSound;
			TShot;
			}
		if(counter >= 120 && counter%120 == 0)
			{
			PlaySound("se_Shot7",40);
			PlaySound("se_Shot1",60);
			let angleM = rand(0,360);
			ascent(i in 0..spread[1])
				{
				let shot = CreateBulletA2(enmx,enmy,0.75,i*360/spread[1]+angleM,0,((i%2)*2-1)*90/180,0,SMALL_BLUE,8,1.125);
				ObjRender_SetBlendType(shot,BLEND_ADD_ARGB);
				ObjMove_AddPatternA2(shot,180,NO_CHANGE,NO_CHANGE,0,((i%2)*2-1)*90/540,0);
				}
			}
		else if(counter >= 120 && counter%(105-Dif*15) == (104-Dif*15))
			{
			PlaySound("se_Shot1",60);
			let angleM = rand(0,360);
			ascent(i in 0..spread[1])
				{
				let shot = CreateBulletA1(enmx,enmy,1.33,i*360/spread[1]+angleM,ICE_BLUE,8,1.25);
				ObjRender_SetBlendType(shot,BLEND_ADD_ARGB);
				}
			}
		yield;
		}
	task TShot
		{
		let angleM = rand(0,360);
		ascent(i in 0..spread[0])
			{
			let angle = i*360/spread[0]+angleM;
			CreateIceDelay(enmx+76*cos(angle),enmy+76*sin(angle),angle,120,150);
			}
		loop(90){yield;}
		ascent(i in 0..spread[0])
			{
			let angle=i*360/spread[0]+angleM;
			let shot = CreateBulletA2(enmx+96*cos(angle),enmy+96*sin(angle),3.5,angle+dirM*90,-2.5/60,dirM*90/60,1,graph[(dirM+1)*0.5],0,1);
			ObjMove_AddPatternA2(shot,60,NO_CHANGE,NO_CHANGE,(speedM-1)/30,dirM*90/(525-speedM*105),speedM);
			ObjRender_SetBlendType(shot,BLEND_ADD_ARGB);
			}
		dirM*=-1;
		}
	task TSound
		{
		loop(45){yield;}
		PlaySound("se_Shot8",90);
		}
}