#TouhouDanmakufu[Single]
#ScriptVersion[3]

#include "./functions.txt"

timer = 89;
life = 12000/3;

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

	TEnemyWork;
	TTime;
	ObjEnemy_Render(objEnemy);
}

task TEnemyWork
{
	loop(15){yield;}
	if(Dif <= 1)
		{
		TSpellName("\"Sudden Onset of Masculinity\"");
		}		
	else
		{
		TSpellName("\"Gathering All to Mount Oyama\"");
		}
	SetBossAura(5,1,1,40);
	ObjMove_SetDestAtWeight(objEnemy,GetStgFrameWidth*0.5,GetStgFrameHeight*0.5-90,20,5);
	loop(90){yield;}
	TLife(0,12,12,75/3,0,false);
	let spread = [[5,6,5,6][Dif],[24,24,20,20][Dif],   [5,9,12,14][Dif],   [73,73,33,33][Dif],[1,2,2,2][Dif],    23,[3,3,1,1][Dif],   [6,8,16,24][Dif]];
	let sM = [[9,9,0.75,0.33][Dif],[0,0,7.5,12.5][Dif],   [1.5,1.5,1.5,1.5][Dif],   [0.8,0.8,1.15,1.15][Dif],   [1.75,1.75,1.875,1.875][Dif],];
	let aM = [1.33,[20,20,40,40][Dif]   ,[2,2,1,1][Dif],30];
	let tM = [48,4,6];
	let DifA = floor(Dif/2);
	let g = [[MAMI[SHOT_BLUE],MAMI[SHOT_PURPLE]][DifA],[SCALE[SHOT_AQUA],SCALE[SHOT_GREEN]][DifA],[SCALE[SHOT_BLUE]-1,SCALE[SHOT_RED]-1][DifA]];
	TBolt;
	loop(105){yield;}
	TMen;
	loop(525){yield;}
	TWall1;
	loop(975+DifA*300){yield;}
	TWall2;
	loop(3000){yield;}
	TMen2;

	task TMen2
		{
		let n = 0;
		loop	
			{		
			ascent(i in 0..spread[7])
				{
				i = (i+n+0.5)%spread[7];
				let a = 90-(i-spread[7]*0.5+0.5)*90/spread[7];
				CreateBulletA2(i*(GetStgFrameWidth)*0.5/spread[7]+GetStgFrameWidth*0.25,-32,sM[2]*3,a,-sM[2]/120,0,sM[2]*2,MAMI,0,1.125,SHOT_YELLOW);
				}
			n+=0.725;
			loop(tM[0]){yield;}
			}
		}
	task TWall2
		{
		let xA = 0;
		let n = 0;
		loop
			{	
			ascent(i in 0..spread[4])
				{
				let x = xA+i*GetStgFrameWidth/spread[4];
				if(x > GetStgFrameWidth)
					{
					x = x%GetStgFrameWidth;
					}		
				let a = atan2(GetStgFrameHeight,x-GetStgFrameWidth*0.5);
				let y = 100*sin((a-90)*3+90)-60;
				let shot = CreateBulletA2(x,y,sM[4]*2,a,-sM[4]/40,0,sM[4],SCALE,6,1.125,SHOT_BLUE);
				ObjShot_SetGraphic(shot,g[2]);
				}
			loop(tM[2])
				{
				n+=1;
				if(n%spread[5] != 0)
					{
					xA+=aM[2];
					}
				else
					{
					xA+=aM[3];
					}
				yield;
				}
			}
		}
	task TWall1
		{
		let xA = 0;
		let n = 0;
		loop
			{	
			ascent(i in 0..spread[4])
				{
				let x = xA+i*GetStgFrameWidth/spread[4];
				if(x > GetStgFrameWidth)
					{
					x = x%GetStgFrameWidth;
					}		
				x = GetStgFrameWidth-x;
				let a = atan2(GetStgFrameHeight,x-GetStgFrameWidth*0.5);
				let y = 100*sin((a-90)*3+90)-60;
				let shot = CreateBulletA2(x,y,sM[3]*2,a,-sM[3]/40,0,sM[3],SCALE,6,1.125,SHOT_GREEN);
				ObjShot_SetGraphic(shot,g[1]);
				}
			loop(tM[1])
				{
				n+=1;
				if(n%spread[3] != 0)
					{
					xA+=aM[0];
					}
				else
					{
					xA+=aM[1];
					}
				yield;
				}
			}
		}
	task TMen
		{
		let n = 0;
		loop	
			{	
			PlaySound("se_Shot3",100);	
			ascent(i in 0..spread[2])
				{
				i = (i+n+0.5)%spread[2];
				let a = 90-(i-spread[2]*0.5+0.5)*90/spread[2];
				let shot = CreateBulletA2(i*(GetStgFrameWidth)/spread[2],-32,sM[2]*1.33,a,-sM[2]*0.33/120,0,sM[2],MAMI,0,1.125,SHOT_BLUE);
				}
			n+=0.425;
			loop(tM[0]){yield;}
			}
		}
	task TBolt
		{
		loop
			{	
			TSound;
			ascent(i in 0..spread[0])
				{
				i+=0.5;
				ascent(dir in 0..2)
					{
					dir = dir*2-1;
					TBoltA(GetStgFrameWidth*(0.5+dir*0.5*i/spread[0]),90-dir*i*15/spread[0]);
					}
				loop(4){yield;}	
				}
			loop(300-spread[0]*4){yield;}
			}
		task TBoltA(x,a)
			{
			let shot = CreateLaserA2(x,-6,14,a,GetStgFrameHeight*1.6,10,18,C_LASER,75,SHOT_YELLOW);
			loop(45){yield;}
			ascent(i in 0..spread[1])
				{
				let d = i*16/spread[1];
				CreateBulletA1(x+d*cos(a+180),-6+d*sin(a+180),12-(12-sM[0])*(i+i*rand(0,1)/spread[1])/spread[1],a+((i/spread[1])^4)*rand(-1,1)*sM[1],SCALE,6,1.125,SHOT_ORANGE);
				loop(2){yield;}
				}
			}
		task TSound
			{
			PlaySound("se_LaserDelay",90);
			loop(45){yield;}
			PlaySound("se_Laser",50);
			loop(spread[1])
				{
				PlaySound("se_Shot1",70);
				loop(2){yield;}
				}

			}
		}
}