#TouhouDanmakufu[Single]
#ScriptVersion[3]

#include "./functions.txt"

timer = 61;

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

	TEnemyWork;
	ObjEnemy_Render; 
	TLife(180,20,20,0,0,20,20);
	TEnd;
	SetShotAutoDeleteClip(8,8,8,8);
}

@MainLoop
{
	yield;
}

@Event
{
	alternative(GetEventType())
	case(EV_REQUEST_LIFE)
		{
		SetScriptResult(500);
		}
	case(EV_REQUEST_TIMER)
		{
		SetScriptResult(timer);
		}
	case(EV_REQUEST_SPELL_SCORE)
		{
		SetScriptResult(30000);
		}
}
task TEnemyWork
{
	TXY;
	loop(60){yield;}
	ObjMove_SetDestAtWeight(objEnemy,GetStgFrameWidth/2,GetStgFrameHeight/2-90,15,2);
	loop(45){yield;}
	let spread = [10,8,2];
	loop
		{	
		ascent(dirM in 0..2)
			{
			dirM = dirM*2-1;
			ascent(t in 0..2)
				{
				let angleM = dirM*180/spread[1];
				let angleP = GetAngleToPlayer(objEnemy);
				ascent(dir in 0..4)
					{
					dir = dirM*((dir%2)*2-1);
					descent(i0 in 0..spread[0])
						{
						let dist = 0;
						ascent(dirA in 0..2)
							{
							let speed = 1+dirA*(1.5+Dif*0.25);
							ascent(i1 in 0..spread[1])
								{
								let angle = i1*360/spread[1]+angleM*(dirA*(3+t*0.5)-1)+angleP;
								let speedM = 1-dirA*0.5+0.75*(1+cos(angle-angleP+180));
								let spreadA = 1+dirA*(spread[2]-1);
								ascent(i2 in 0..spreadA)
									{
									i2 = i2-spreadA/2+0.5;
									let shot = CreateBulletA2(enmx+dist*cos(angle),enmy+dist*sin(angle),speedM,angle+i2*1.5,(speed-speedM)/60,0,speed,KUNAI_ORANGE,8,1.125);
									}
								}
							}
						if(i0 == 1 && dir == dirM)
							{
							ObjEnemy_Move(objEnemy,20,3,rand(20,30),rand(75,105),150,2);
							}
						TSound;
						loop(4-Dif){yield;}
						angleM+=dir*(99-t*60)/spread[0];
						}
					}
				loop(135-Dif*10){yield;}
				}
			}
		}
	task TSound
		{
		PlaySound("se_Shot1",90);
		loop(10){yield;}
		PlaySound("se_Shot7",50);
		}
}