#TouhouDanmakufu[Single]
#ScriptVersion[3]

#include "./functions.txt"

timer = 65;

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

	TEnemyStart;
	ObjEnemy_Render; 
	TLife(270,20,20,0,0,100,67);
}

@MainLoop
{
	yield;
}

task TEnemyStart
{
	ObjMove_SetDestAtWeight(objEnemy,GetStgFrameWidth/2,GetStgFrameHeight/2-70,15,2);
	loop(60){yield;}
	CreateBossAura(0);
	loop(90)
		{
		ascent(i in 0..2)
			{
			famAngle[i] = famAngle[i]+(i*2-1)*(0.3+i*0.6)*1.5;
			}
		Obj_SetValue(objScene,"FAM_ANGLE",famAngle);
		yield;
		}
	TEnemyWork;
	ObjEnemyBossScene_SetSpellTimer(objScene,timer*60);
	TEnd(false);
	loop
		{
		ascent(i in 0..2)
			{
			famAngle[i] = famAngle[i]+(i*2-1)*(0.3+i*0.6)*1.5;
			}
		Obj_SetValue(objScene,"FAM_ANGLE",famAngle);
		yield;
		}
}

@Event
{
	alternative(GetEventType())
	case(EV_REQUEST_LIFE)
		{
		SetScriptResult(5000);
		}
	case(EV_REQUEST_TIMER)
		{
		SetScriptResult(200);
		}
	case(EV_REQUEST_SPELL_SCORE)
		{
		SetScriptResult(30000);
		}
}
task TEnemyWork
{
	TXY;
	let time = [7,12-Dif*2,2,(12-Dif*4)];
	let dir = -1;
	let counter = -1;
	let angleM1 = 0;
	let angleM2 = 0;
	let angleA = 180-120*1.5;
	let distA = 0;
	let angleP = 90;
	loop
		{
		counter+=1;	
		angleM1+=1.5;	
		if(counter > 120 && (counter-120)%360 == 0)
			{
			dir*=-1;
			}
		if(counter > 240)
			{
			if(distA < 1)
				{
				distA+=1/180;
				}
			angleA+=0.5;
			ObjMove_SetDestAtFrame(objEnemy,GetStgFrameWidth*0.5+distA*16*cos(angleA),GetStgFrameHeight*0.5-70+distA*16*sin(angleA),1);
			}
		if(counter%7 == 0)
			{
			TSound;
			}
		if(counter%5 == 0)
			{	
			ascent(i in 0..2)
				{
				i = i*2-1;
				let dir = rand(0,1);
				let x = GetStgFrameWidth*(0.5+i*dir*0.5);
				let y = rand(0,GetStgFrameHeight*(0.5+dir*0.05));
				let angle = rand(0,360);
				CreateIceDelay(x,y,angle,150,105);
				}
			}
		if(counter%(7-Dif) == 0)
			{
			ascent(i in 0..2)
				{
				i = i*2-1;
				let dir = rand(0,1);
				let x = GetStgFrameWidth*(0.5+i*dir*0.5);
				let y = rand(0,GetStgFrameHeight*(0.5+dir*0.05));
				let angle = rand(0,360);
				let shot2 = CreateBulletA2(x,y,0.25,90-i*dir*75+rand(-1,1)*3,1/(75-Dif*15),0,10,SMALL_GRAY,8,0.7);
				ObjRender_SetBlendType(shot2,BLEND_ADD_ARGB);
				let shot = CreateBulletA1(x,y,0,0,SMALL_BLUE,8,0.7);
				ObjMove_AddPatternB2(shot,1,cos(90-i*dir*90)*0.75,rand(1.25,2.25)+dir*2.5,0,-1/30,0,-5);
				ObjRender_SetBlendType(shot,BLEND_ADD_ARGB);
				}
			}
		if(counter%(17-Dif*2) == 0)
			{
			ascent(i0 in 0..2)
				{
				i0 = i0*2-1;
				let dir = rand(0,1);
				let x = GetStgFrameWidth*(0.5+i0*dir*0.5);
				let y = rand(0,GetStgFrameHeight*(0.5+dir*0.05));
				let shot = CreateBulletA2(x,y,0.25,90-i0*dir*75+rand(-1,1)*3,1/120,0,1.5,SMALL_BLUE-1,8,1);
				ObjRender_SetBlendType(shot,BLEND_ADD_ARGB);
				}
			}
		if(counter > 120 && counter%time[3] == 0)
			{
			let x = enmx+GetStgFrameWidth*dir*0.3+distA*48*cos(angleA);
			let y = enmy+distA*16*sin(angleA);
			ascent(i in 0..4)
				{
				let angle = 90+dir*angleM2+i*90;
				let shot = CreateBulletA1(x+8*cos(angle),y+8*sin(angle),1,angle,OVAL_GRAY+1.5+dir*1.5,8,1.125);
				ObjRender_SetBlendType(shot,BLEND_ADD_ARGB);
				let speed = (3.75-dir*0.75*cos(angleA))*cos(angle);
				ObjMove_AddPatternB2(shot,60,NO_CHANGE,NO_CHANGE,speed/(315-Dif*45),1/(75-Dif*15),speed,5);
				}
			angleM2+=15;
			}
		if(counter > 120 && floor(counter/time[2])%time[1] < time[0] && counter%time[2] == 0)
			{
			let x = enmx-GetStgFrameWidth*dir*0.3+distA*48*cos(angleA);
			let y = enmy+distA*16*sin(angleA);
			ascent(i in 0..3)
				{
				let angle = 90-dir*angleM1+i*120;
				let shot = CreateBulletA1(x+8*cos(angle),y+8*sin(angle),1,angle,OVAL_GRAY+1.5-dir*1.5,8,1.125);
				ObjRender_SetBlendType(shot,BLEND_ADD_ARGB);
				let speed = 3+dir*0.75*cos(angleA);
				ObjMove_AddPatternA2(shot,60,NO_CHANGE,NO_CHANGE,speed/360,0,speed);
				}
			}
		yield;
		}	
	task TSound
		{
		loop(10){yield;}
		PlaySound("se_Shot8",90);
		}


}