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

#include "./functions2.txt"

timer = 40;

@Initialize
{
	Obj_SetValue(GetEnemyBossSceneObjectID,"INIT",false);
	objEnemy = ObjEnemy_Create(OBJ_ENEMY_BOSS);
	ObjEnemy_Regist(objEnemy);
	ObjEnemy_SetDamageRate(objEnemy,0,0);

	TEnemyWork;
	ObjEnemy_Render; 
	TLife(30,20,20,0,0,17.5,17.5);
	TEnd;
}

@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;
	ObjMove_SetDestAtWeight(objEnemy,GetStgFrameWidth/2,GetStgFrameHeight/2-115,15,2);
	loop(45){yield;}
	let spread = [4+Dif,8+Dif*4,5];
	let dir = 1;
	let counter = -1;
	let count = 135;
	loop
		{
		counter+=1;
		if(counter%count == 0)
			{
			PlaySound("se_Shot1",100);
			PlaySound("se_Shot4",40);
			ascent(i0 in 0..spread[0])
				{
				ascent(i1 in 0..spread[1])
					{
					TShot(GetAngleToPlayer(objEnemy)-dir*90/spread[1],dir,i0,i1);
					}
				}
			dir*=-1;
			if(count > 25)
				{
				count-=15;
				}
			else
				{
				count = 25;
				}
			}
		if(counter%180 == 90)
			{
			PlaySound("se_Shot3",100);
			TShot2;
			}
		if(counter%180 == 100)
			{
			ObjEnemy_Move(objEnemy,20,3,30,30,105,125,110,1);
			}
		yield;
		}
	task TShot2
		{
		descent(i2 in 0..spread[2])
			{
			let shot = CreateBulletOA2(objEnemy,1.5,GetAngleToPlayer(objEnemy),1/(45-i2*30/spread[2]),0,3.5,DS_MISSILE_PURPLE,8,1.75);
			ObjRender_SetColorHSV(shot,300,20,255);
			loop(2){yield;}
			}
		}
	task TShot(angleM,dir,i0,i1)
		{
		let angle = i1*360/spread[1];
		let time = 45+i0*30/spread[0];
		let x = GetPlayerX;
		let y = GetPlayerY;
		let shot = CreateBulletOA2(objEnemy,8,angle+angleM,-8/time,0,0,DS_MISSILE_GREEN+0.5+dir*2.5,8,1.125);
		ObjMove_SetAngularVelocity(shot,-dir*3);
		loop(time){yield;}
		ObjMove_SetAngularVelocity(shot,0);
		loop(10){yield;}
		ObjMove_AddPatternA2(shot,0,1+i0*1/spread[0],ObjMove_GetAngle(shot)+dir*90,0,0,0);
		}
}	