#TouhouDanmakufu[Single]
#ScriptVersion[3]

#include "./functions.txt"

timer = 75;
life = 3000;

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

	TEnemyWork;
	ObjEnemy_Render(objEnemy);
}

task TEnemyWork
{
	ObjMove_SetDestAtWeight(objEnemy,GetStgFrameWidth*0.5,GetStgFrameHeight*0.5-125,20,5);
	loop(60){yield;}
	TLife(120,20,32,100,100,false);
	
	TBottom;
	loop(240){yield;}
	TTop;
	task TTop
		{
		let a = 180;
		loop
			{
			TShot(GetStgFrameWidth*(0.5+cos(a+rand(-1,1)*30)*0.45));
			loop(75){yield;}
			a+=40;
			}
		task TShot(x)
			{
			let nA = 5-Dif*2;
			let gA = 7;
			let g = floor(rand(0,6));
			let ys = rand(25,115)+Dif*30;
			let a = floor(rand(0,2))*180+180/(ys/4);
			let xs = 10;
			let c = -1;
			ascent(t in 0..ys)
				{
				if(t%nA == 0)
					{
					TSpam(x+xs*cos(a),t,270-xs*cos(a),floor((g%gA)/(gA-1)));
					g+=1;
					}
				a+=4;
				if(t%2 == 0)
					{
					yield;
					}
				}
			let yA = 360*rand(2,4);
			let dir = 1;
			if(cos(a) < 0)
				{
				dir = -1;
				}
			let n = 9;
			ascent(t in 0..yA/n)
				{
				let s = (yA-t*n)*(24/n)/yA;
				let aA = t*n*0.5+90;
				x+=s*cos(xs*cos(a)+aA)*dir;
				ys+=s*sin(xs*cos(a)+aA);
				if(t%nA == 0)
					{
					TSpam(x+xs*cos(a),ys,270-xs*cos(a)+dir*t*n*0.5,floor((g%gA)/(gA-1)));
					g+=1;
					}
				yield;
				}
			}
		task TSpam(x,y,a,g)
			{
			let s = (rand(1.75,2.25)+Dif*0.5+g*2)*rand(1,1+1/40);
			if(g == 1)
				{
				a = rand(0,360);
				}
			let shot = CreateBulletA2(x,y,0,a,s/240,0,10,[BEAM,BALL_M][g],8,1,[SHOT_GREEN,SHOT_YELLOW][g]);
			}
		}
	task TBottom
		{
		let a = 180;
		loop
			{
			TShot(GetStgFrameWidth*(0.5+cos(a+rand(-1,1)*30)*0.45));
			loop(75){yield;}
			a+=40;
			}
		task TShot(x)
			{
			let xs = 5;
			let xA = 30+floor(rand(0,2))*180;
			let xAA = (floor(rand(0,2))*2-1)*(rand(13.25,16.75)-12);
			let ys = rand(25,55)+Dif*10;
			let n = floor(rand(0,7));
			ascent(d in 0..ys)
				{
				xA+=xAA;
				if(d%(10-Dif*2) == 0)
					{
					let s = (2-d*1/65)*(0.75+Dif*0.25)*rand(1,1+1/40);
					ascent(i in -1..xs+1)
						{
						i = i-xs*0.5+0.5+0.5*cos(xA);
						let a = 270+i*150/xs;
						let shot = CreateBulletA2(x+d*cos(a),GetStgFrameHeight-d*sin(a+180),0,a,s/240,0,s,SCALE,8,1,[SHOT_GREEN,SHOT_PURPLE][floor((n%4)/3)]);
						n+=floor(rand(0,3));
						}
					}
				yield;
				}
			}
		}
}