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

#include"./functions1.txt"

timer = 75;

@Initialize
{
	objEnemy = ObjEnemy_Create(OBJ_ENEMY_BOSS);
	ObjEnemy_Regist(objEnemy);
	ObjEnemy_SetDamageRate(objEnemy,0,0);
	
	TEnemyWork;
	TLife(objEnemy,0,20,20,0,0,15,7.5);
	ObjEnemy_Render;
	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_SetPosition(objEnemy,GetStgFrameWidth/2,130);
	SetForbidPlayerShot(false);
	SetForbidPlayerSpell(false);
	loop(90){yield;}
	let dir = 1;
	loop
		{
		loop(2)
			{
			TSpam3;
			TSpam1;
			loop(240){yield;}
			TMovement;
			loop(90){yield;}
			dir = dir*-1;
			}
		}

	task TSpam1
		{
		let spread = [8,12];	
		let angle = GetAngleToPlayer(objEnemy);
		loop(7)
			{
			ascent(i0 in 0..spread[0])
				{
				ascent(i1 in 0..spread[1])	
					{
					let obj = CreateShotOA1(objEnemy,2+i1*2/spread[1],i0*360/spread[0]+angle,DS_BALL_SS_GREEN+dir*2,15);					
					Obj_SetRenderPriorityI(obj,50);
					}
				}
			loop(26){yield;}
			angle-=dir*13;
			}
		}


	task TSpam3
		{
		let spread = [8,5];
		let angle = GetAngleToPlayer(objEnemy);
		loop(7)
			{	
			ascent(i2 in 0..2)
				{
				let dirA = dir*(i2*2-1);
				ascent(i0 in 0..spread[0])
					{
					ascent(i1 in 0..spread[1])	
						{
						let obj = CreateShotOA2(objEnemy,2,i0*360/spread[0]+dirA*(i1+dir/2)*(7.5+i2*12.5)/spread[1]+angle,0.05,3.5,DS_BALL_S_GREEN+dir*2,15);					
						Obj_SetRenderPriorityI(obj,51);
						ObjRender_SetBlendType(obj,BLEND_ADD_ARGB);
						}
					}
				PlaySound(se_DeepShotHigh,77.5);
				loop(13){yield;}
				}
			angle-=dir*13;
			}
		}
}

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