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

#include"./functions1.txt"

timer = 60;

@Initialize
{
	objEnemy = ObjEnemy_Create(OBJ_ENEMY_BOSS);
	ObjEnemy_Regist(objEnemy);
	ObjEnemy_SetDamageRate(objEnemy,0,0);
	
	TEnemyWork;
	ObjEnemy_Render;
	ObjEffect_Shadow(false);
	TLife(objEnemy,120,20,20,2.5,2.5,15,7.5);
	TEnd;
}

@MainLoop
{
	timer-=1/60;
	yield;
}

@Event
{
	alternative(GetEventType())
	case(EV_REQUEST_LIFE)
		{
		SetScriptResult(500);
		}
	case(EV_REQUEST_TIMER)
		{
		SetScriptResult(timer);
		}
}

task TEnemyWork
{
	TXY;
	ObjMove_SetDestAtWeight(objEnemy,GetStgFrameWidth/2,GetStgFrameHeight/2-96,15,5);
	loop(180){yield;}
	let spread = 21;
	let spread2 = 6;
	let leg = 2.25;	
	let angleA = 270;
	let graph = 0;

	let hyp = 0.5*((leg^2)*2)^0.5;
	let h = ((leg^2)-(hyp^2))^(1/2);
	let xA = enmx;
	let yA = 0;
	let time = 165;

	loop
		{
		angleA = GetAngleToPlayer(objEnemy);
		ascent(i1 in 0..spread)
			{	
			ascent(i0 in 0..spread2)
				{		
				let angle = i0*360/spread2+i1*(360/spread2)/spread+(180/spread2)/spread;
				let speed = leg-absolute((i1-spread/2+0.5)*h*(2^0.5)/(spread));
				TShot(enmx,enmy,speed,angle,angleA);
				}
			}
		PlaySound(se_CuteShotLong,80);
		PlaySound(se_DeepShotMed,80);
		loop(time/2){yield;}
		TMovement;
		loop(time/2){yield;}
		graph+=2;
		time-=1.25;			
		}
	task TShot(x,y,speed,angle,angleA)
		{
		let obj = CreateShotA2(x,y,speed*0.75,angle-((spread2+1)%2)*(180/spread2)+180+angleA,speed/120,speed,DS_ICE_RED+graph%7*2,0);	
		ObjRender_SetBlendType(obj,BLEND_ADD_ARGB);
		while(!Obj_IsDeleted(obj) && ObjMove_GetY(obj) > -8 && ObjMove_GetX(obj) > -8 && ObjMove_GetX(obj) < GetStgFrameWidth+8){yield;}
		if(Obj_IsDeleted(obj)){return;}
		let angle2 = 0;
		if(ObjMove_GetY(obj) <= 0)
			{
			angle2 = -ObjMove_GetAngle(obj);
			}
		else
			{
			angle2 = 180-ObjMove_GetAngle(obj);
			}
		ObjMove_SetAngle(obj,angle2);
		}
		
}		

task TMovement
{
	let distM = 25;
	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(120,170),30,5);
		
}