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

#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(true);
	TLife(objEnemy,120,20,20,2.5,2.5,20,10);
	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-90,15,5);
	loop(90){yield;}
	let graph = [DS_RICE_S_D_SKY,DS_FIRE_RED];
	let spread = [2,21,12];
	let distM = [125,100];
	let angleM = 0;
	let dirM = -1;
	let time = 60;
	loop
		{		
		descent(iG in 0..2)
			{
			let time = round(rand(0,30));
			ascent(i0 in 0..spread[0])
				{
				let x = enmx+distM[(dirM+1)/2]*cos(i0*360/spread[0]+angleM);
				let y = enmy+distM[(dirM+1)/2]*sin(i0*360/spread[0]+angleM);
				let angle = atan2(GetPlayerY-y,GetPlayerX-x);
				if(iG == 1)
					{
					angle = rand(0,360);
					}
				ascent(i1 in 0..spread[iG+1])
					{	
					let bulletObj = CreateShotA2(x,y,1,i1*360/spread[iG+1]+angle,-1/(105-iG*75),0,graph[0],30);
					TShot(bulletObj,120-iG*60,time);
					}
				}
			loop(45){yield;}
			angleM+=45;
			dirM = dirM*-1;
			}
		dirM = dirM*-1;
		TMovement;
		}
	task TShot(target,time,time2)
		{
		loop(time){yield;}
		ObjMove_AddPatternA2(target,0,NO_CHANGE,ObjMove_GetAngle(target)+180,0.033,0,3);
		loop(175-time-time2){yield;}
		PlaySound(se_CuteShotMed,80);
		ObjShot_SetGraphic(target,graph[1]);
		ObjShot_SetSpellResist(target,true);
		}
}		

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);
		
}