#TouhouDanmakufu[Single]
#ScriptVersion[3]

#include "./functions.txt"

timer = 65;
life = 4850;

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

	TEnemyWork;
	ObjEnemy_Render(objEnemy);
}

task TEnemyWork
{
	SetSpellBack(SHOT_X);
	ObjMove_SetDestAtWeight(objEnemy,GetStgFrameWidth*0.5,GetStgFrameHeight*0.5-105,15,5);
	loop(50){yield;}
	TLife(120,20,32,75,75,false);
	
	let spread = [20+Dif-floor(Dif/2)*2,10+Dif*6,4,4+floor(Dif/2)];
	let rate = 0.6;
	TSpam;
	let dir = 1;
	let dirM = dir;
	loop
		{	
		ObjMove_SetDestAtWeight(objEnemy,GetStgFrameWidth*(0.5+dir*0.4),GetStgFrameHeight*0.5-135,7,5);
		loop(60){yield;}
		dir*=-1;
		ObjMove_SetDestAtFrame(objEnemy,GetStgFrameWidth*(0.5),GetStgFrameHeight*0.5-100,5*(3)*16);
		let aM = rand(0,360);
		EnemyWave = true;
		ascent(t0 in 0..6)
			{
			ascent(t in 0..3+Dif*2)
				{
				let s = 1-t*1/(32+((Dif+1)%2)*64);
				if(t%2 == 1)
					{
					dirM*=-1;
					}
				PlaySound("se_Shot4",55);
				ascent(i in 0..spread[0])
					{
					if(t%2 == 1)
						{
						ascent(i1 in 0..spread[3])
							{
							let shot = CreateBulletA2(enmx,enmy,s+rand(0,1/120),(i+0.5+dirM*(0.5-(rate+t0*(1-rate)/15)+(i1+0.5+rand(-1,1)*0.075)*(rate+t0*(1-rate)/15)/(spread[3]-1)))*360/spread[0]+aM,1/60,0,10,BALL_S,8,1,SHOT_BLUE);
							Obj_SetRenderPriority(shot,0.51);
							}
						}
					let shot = CreateBulletA2(enmx,enmy,s+rand(0,1/40),i*360/spread[0]+aM,1/60,0,10,BALL_O,8,1,SHOT_BLUE);
					Obj_SetRenderPriority(shot,0.52);
					}
				loop(8){yield;}
				}
			aM+=180/spread[0];
			if(Dif == 1)
				{
				dirM*=-1;
				}
			if(t0 == 5)
				{
				EnemyWave = false;
				}
			loop(40-Dif*16){yield;}
			}
		loop(35){yield;}
		ObjMove_SetDestAtWeight(objEnemy,GetStgFrameWidth*(0.5),GetStgFrameHeight*0.5-55,30,5);
		loop(40){yield;}
		loop(10)
			{
			PlaySound("se_Shot1",75);
			let x = enmx+rand(-1,1)*60;
			let y = enmy+rand(-1,1)*60;
			ascent(i0 in 0..spread[1])
				{
				ascent(i1 in 0..spread[2])
					{
					let s2 = 1.5+i1*4.25/spread[2];
					let g = floor(rand(0,3));
					ascent(n in 0..1)
						{
						let s1 = 4.5+n*0.375+i1*0.5/spread[2];
						let a = atan2(GetPlayerY-y,GetPlayerX-x)+i0*360/spread[1];
						let shot = CreateBulletA2(x+n*1.5*sin(a),y+n*1.5*cos(a),s1,a,(s2-s1)/30,0,s2,ICE,8,1,SHOT_BLUE);
						ObjRender_SetBlendType(shot,BLEND_ADD_ARGB);
						}
					}
				}
			loop(5){yield;}
			}
		loop(20){yield;}
		EnemyWave = true;
		loop(40){yield;}
		EnemyWave = false;
		}

	task TSpam
		{
		loop(40+6*50+75+10*5+15+60){yield;}
		let spread = 3+floor(Dif/2);
		loop
			{
			ascent(i in -1..spread+1)
				{
				let s = rand(0.5,1.5);
				let shot = CreateBulletA1((i+rand(0,1))*GetStgFrameWidth/spread,rand(0,32),s,90+rand(-1,1)*10,ICE,8,1,SHOT_BLUE);
				ObjMove_AddPatternB2(shot,0,NO_CHANGE,NO_CHANGE,0,s*s/(GetStgFrameHeight*rand(0.5,0.8)),0,10);
				Obj_SetRenderPriority(shot,0.49);
				}
			PlaySound("se_Shot3",45);
			loop(50){yield;}
			}
		}
}