#TouhouDanmakufu[Single]
#ScriptVersion[3]
#Title["BaseML"]

#include"./functions2.txt"

timer = 45;

@Initialize
{
	objEnemy = ObjEnemy_Create(OBJ_ENEMY_BOSS);
	ObjEnemy_Regist(objEnemy);
	ObjEnemy_SetDamageRate(objEnemy,0,0);
	
	TEnemyWork;
	ObjEnemy_Render;
	TLife(objEnemy,60,20,20,2.5,2.5,30,30);
	TEnd;
}

@MainLoop
{
	timer-=1/60;
	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;
	ObjMove_SetDestAtWeight(objEnemy,GetStgFrameWidth/2,GetStgFrameHeight/2-75,15,5);
	SetForbidPlayerShot(false);
	SetForbidPlayerSpell(false);
	EnemySpell = true;
	loop(90){yield;}
	let spread = [12,12];
	let dir = 1;
	loop
		{
		loop(2)
			{
			ascent(i0 in 0..spread[0])
				{
				ascent(i1 in 0..spread[1])
					{
					TShot(i0,i1);
					}
				}
			PlaySound(se_DeepShotHigh,80);
			loop(75){yield;}
			dir *= -1;
			}
		TMovement;
		}
	task TShot(i0,i1)
		{
		let obj = CreateShotOA2(objEnemy,8,(i0+0.5)*360/spread[0]+dir*(i1*(360/spread[0])/spread[1])+GetAngleToPlayer(objEnemy),-0.5,2+i1*1.25/spread[1],DS_BILL_GREEN-(i1%3%2)*2,16);
		if(i1%3%2 != 0)
			{
			while(!Obj_IsDeleted(obj) && ObjMove_GetX(obj) <= GetStgFrameWidth && ObjMove_GetX(obj) >= 0 && ObjMove_GetY(obj) >= 0){yield;}
			if(Obj_IsDeleted(obj)){return;}	
			let angle2 = 180-ObjMove_GetAngle(obj);
			if(ObjMove_GetY(obj) < 0)
				{
				angle2 = -ObjMove_GetAngle(obj);
				}
			PlaySound(se_CuteShotLong,80);
			CreateShotOA1(obj,1.5,angle2,DS_BILL_ORANGE,16);
			}
		}
}
			

task TMovement
{
	let distM = 50;
	let distm =distM/2;
	let numb = round(rand(0,1))*2-1;
		if(ObjMove_GetX(objEnemy) < 175)
			{
			numb =1;	
			}
		else if (ObjMove_GetX(objEnemy) > GetStgFrameWidth-175)
			{	
			numb = -1;
			}
	ObjMove_SetDestAtWeight(objEnemy,ObjMove_GetX(objEnemy)+numb*rand(distm,distM),rand(90,180),30,5);
		
}