#TouhouDanmakufu[Single]
#ScriptVersion[3]

#include "./functions.txt"

timer = 60;
life = 12000;

@Initialize
{
	objEnemy = ObjEnemy_Create(OBJ_ENEMY_BOSS);
	ObjEnemy_Regist(objEnemy);

	TEnemyWork;
	ResetSTime;
	TTime;
	ObjEnemy_Render(objEnemy);
}
task TEnemyWork
{
	SetBossAura(3,1,1,40);
	loop(30){yield;}
	ObjMove_SetDestAtWeight(objEnemy,GetStgFrameWidth*0.5,GetStgFrameHeight*0.5-150,20,5);
	TLife(0,12,12,60,60,false);
	loop(45){yield;}
	let timeM = [[3,4,5,6][Dif],[13,13,10,10][Dif],3];
	let spreadM = [8,[2,5,7,11][Dif],[15,2.5,7.5,10][Dif]];;
	let sM = [1.75,1.75,2.75,2.75][Dif];
	let bturn = 1.25;

	TWind;
	loop(timeM[1]*timeM[2]*spreadM+75){yield;}	
	let dir = 1;
	loop(1)
		{
		TWall(dir);
		loop(270){yield;}
		dir*=-1;	
		}
	task TWall(dir)
		{
		let t = 0;
		let a1 = 270;
		loop
			{
			
			t+=1;	
			a1+=dir*35.33*0.25;
			if(t%3 == 0)
				{
				TShot(a1,dir);
				}
			if(t%255 == 0)
				{
				t = 0;
				dir*=-1;
				}
			yield;
			}
		task TShot(a1,dir)
			{
			descent(i in 0..spreadM[1])
				{		
				let a = a1+dir*i*spreadM[2]/spreadM[1];
				let shot = CreateBulletA1(GetStgFrameWidth*0.5+64*cos(a),32+16*sin(a),3.25*(0.875+i*0.125/spreadM[1]),a,ICE,6,1.125,[SHOT_ORANGE,SHOT_BLUE][(-dir+1)*0.5]);
				Obj_SetRenderPriority(shot,0.49);	
				loop(1){yield;}
				}
			}
		}
	task TWind
		{
		let spread = 1;
		let c = -1;	
		let c2 = -1;	
		loop
			{
			c+=1;
			c2+=1;
			if(floor(c2/timeM[2]) == timeM[1] && spread < spreadM[0])
				{
				c2 = -1;
				spread+=2;
				}
			else if(spread > spreadM[0])
				{
				spread = spreadM[0];
				}
			ascent(i in 0..spread)
				{
				let cA = c+floor((floor(i/2)%2)*timeM[2]*timeM[1]*0.75)+i;
				if(floor(cA/timeM[2])%timeM[1] < timeM[0] && cA%timeM[2] == 0)
					{
					TShot(c*bturn+i*(GetStgFrameHeight*1.5)/spreadM[0],(i%2)*2-1);
					}
				}
			yield;
			}
		task TShot(n,dir)
			{
			n = 16+n%(GetStgFrameHeight*1.5);
			let x = 1;
			let y = 1;
			let dA = 90;	
			let tA = 0;
			while(x > 0 && y > 0 && x < GetStgFrameWidth)
				{
				dA+=dir*1;
				x = GetStgFrameWidth*0.5+n*cos(dA);
				y = n*sin(dA);
				}
			let dC = pi*n;
			let aA = -dir*180/(dC/sM);
			let dAb = dA;
			while(dAb > 0 && dAb < 180)
				{
				dAb-=aA;
				tA+=1;
				}
			loop(tA){yield;}
			let shot = CreateBulletA2(x,y,sM,dA-dir*90,0,aA,0,SCALE,6,1.125,SHOT_BLUE);
			ObjShot_SetGraphic(shot,SCALE[SHOT_BLUE]-1);
			ObjMove_AddPatternA2(shot,dC/sM-tA,NO_CHANGE,NO_CHANGE,0,0,0);
			}
		}
}            