#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,25,25);
	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 = [16,8,[1,2,2][Dif],[2,2,4][Dif]];
	loop
		{	
		ascent(t in 0..2)
			{
			let angleM = 0;
			ascent(dir in 0..2)
				{
				dir = dir*2-1;
				let angleP = GetAngleToPlayer(objEnemy);
				descent(i0 in 0..spread[0])
					{
					let dist = i0*96/spread[0];
					ascent(dirA in 0..2)
						{
						let speed = 0.75+t*0.25+Dif*0.33+dirA*0.75;
						ascent(i1 in 0..spread[1])
							{
							let angle = i1*360/spread[1]+(dirA*(3+t*1)-1)*angleM+angleP;
							let speedM = 3+0.75*(1+cos(angle-angleP+180));
							let spreadA = spread[3-dirA];
							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.75-(1-dirA)*floor(Dif/2)*0.5),(-3)/60,0,0,KUNAI_ORANGE,8,1.125);
								ObjMove_AddPatternA2(shot,60,NO_CHANGE,NO_CHANGE,speed/30,0,speed);
								}
							}
						}
					if(i0 == 1)
						{
						ObjEnemy_Move(objEnemy,20,3,rand(20,30),rand(75,105),150,0);
						}
					PlaySound("se_Shot1",100);
					loop(2){yield;}
					angleM+=dir*(7-t*5);
					}
				loop(135-Dif*30){yield;}
				angleM+=180/spread[1];
				}
			}
		}
}