#TouhouDanmakufu[Single]
#ScriptVersion[3]

#include "./functions.txt"

timer = 76;

@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 = [16,8,[1,1,2][Dif]];
	loop
		{
		ascent(t in 0..2)
			{	
			ascent(dirM in 0..2)
				{
				dirM = dirM*2-1;
				let angleP = GetAngleToPlayer(objEnemy);
				let angleM = 0;
				ascent(dir in 0..4)
					{
					dir = dirM*((dir%2)*2-1);
					ascent(i0 in 0..spread[0])
						{
						ascent(i1 in 0..spread[1])
							{
							ascent(i3 in 0..2)
								{
								let spreadA = 2-i3;
								let angleA = i3*2+1;
								if(t == 1)
									{
									angleA = (1-i3)*2+1;
									}
								let angle = i1*360/spread[1]+angleA*angleM+angleP;
								ascent(i2 in 0..spreadA)
									{
									i2 = i2-spreadA/2+0.5;
									let shot = CreateBulletA2(enmx,enmy,1,angle+i2*1.5,1/(60+i3*15-Dif*5),0,4,KUNAI_ORANGE,8,1.125);
									}
								}
							}
						TSound;
						loop(4-Dif){yield;}
						angleM+=dir*(180/spread[1]+((225-t*30)/spread[1])/spread[0]);
						}
					}
				loop(45+Dif*15){yield;}
				ObjEnemy_Move(objEnemy,20,3,rand(20,30),rand(75,105),150,0);	
				loop(60){yield;}
				}
			}
		}
	task TSound
		{
		PlaySound("se_Shot1",90);
		loop(10){yield;}
		PlaySound("se_Shot7",50);
		}
	
}