#TouhouDanmakufu[Single]
#ScriptVersion[3]

#include "./functions.txt"

timer = 100;
life = 3100;

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

	TEnemyWork;
	ObjEnemy_Render(objEnemy);
}

task TEnemyWork
{
	SetSpellBack(SHOT_PURPLE);
	EnemyWave = true;
	loop(5){yield;}
	EnemySpell = TYPE_GLOW;
	ObjMove_SetDestAtWeight(objEnemy,GetStgFrameWidth*0.5,GetStgFrameHeight*0.5-135,20,5);
	loop(55){yield;}

	TWall;
	loop(160){yield;}
	EnemySpell = TYPE_BASIC;
	loop(5){yield;}
	TLife(0,20,32,42.5,42.5,false);
	loop(23){yield;}
	TWave;
	loop(7){yield;}
	let spread = [11,2];
	let c = 0;
	loop
		{
		PlaySound("se_Shot1",80);
		ascent(i1 in -1..spread[1])
			{
			let spreadA = spread[0]-i1;
			let s = 0.75;
			if(i1 == -1)
				{
				spreadA = spread[0]*2+2;
				s = 2;
				}
			ascent(i0 in 0..spreadA)
				{
				i0 = i0-spread[0]*0.5+0.5+i1*0.5;
				let a = i0*165/spread[0]+GetAngleToPlayer(objEnemy);
				let shot = CreateBulletA1(enmx,enmy,(s+i1*0.5/spread[1])*rand(1,1+1/60),a,SPARK,8,1,SHOT_YELLOW);
				ObjRender_SetBlendType(shot,BLEND_ADD_ARGB);
				}
			}
		descent(t in 0..155)
			{
			c+=1;
			if(c%225 == 0)
				{
				ObjEnemy_Move(objEnemy,20,5,75,rand(125,140),125,0);
				}
			if(t == 7)
				{
				TWave;
				}
			yield;			
			}
		}
	task TWall
		{
		let spread = [20,5,16];
		let a = 0;
		let n = 0;
		let c = 0;
		let nA = floor(rand(0,31));
		let aA = 2.5-floor(Dif/2)*0.25;
		loop
			{
			let y = rand(0,1);
			ascent(i in -1..n+1)
				{		
				i+=y;
				ascent(dir in 0..2)
					{
					let s = (GetStgFrameWidth*(0.8+Dif*0.1+floor(Dif/2)*0.15)/30)*(0.575+0.425*cos(i*360/spread[0]+dir*180+a));
					dir = dir*2-1;
					let shot = CreateBulletA2(GetStgFrameWidth*(0.5+dir*0.5),i*GetStgFrameHeight/spread[0],s,90+dir*90,-s/30,0,-s,SCALE,8,1.25,[SHOT_PURPLE,SHOT_PURPLE,SHOT_YELLOW][Dif]);	
					nA+=1;
					if((nA%31 == 0 || (Dif == 1 && (nA%124 == 16 || nA%124 == 31*3+16))) && c >= 1)
						{
						PlaySound("se_Shot4",40);
						ObjMove_SetSpeed(shot,s*(0.25+floor(Dif/2)*0.4));
						ObjMove_SetAngle(shot,ObjMove_GetAngle(shot)-dir*0.5*(45+45*sin(a*0.125*2.5/aA-75)));		
						let ms = (1.5-floor(Dif/2)*0.25)*rand(1,1.75/1.5);
						ObjMove_SetMaxSpeed(shot,ms);
						ObjShot_SetGraphic(shot,KNIFE[SHOT_YELLOW]);
						ObjShot_SetScale(shot,1);
						let spam = CreateBulletA2(ObjMove_GetX(shot)-1*sin(ObjMove_GetAngle(shot)),ObjMove_GetY(shot)-1*cos(ObjMove_GetAngle(shot)),ObjMove_GetSpeed(shot),ObjMove_GetAngle(shot),-s/30,0,ms,SPARK,8,1,[SHOT_YELLOW,SHOT_YELLOW,SHOT_PURPLE][Dif]);
						ObjRender_SetAngleZ(spam,ObjMove_GetAngle(shot)-45);
						}
					}
				}
			if(n < spread[0])
				{
				n+=1;
				}
			loop(7)
				{
				if(n == spread[0])
					{
					if(c < 1)
						{
						c+=1/75;
						}
					a-=aA*c;
					}
				yield;
				}
			}
		}
	task TWave
		{
		EnemyWave = false;
		loop(25){yield;}
		EnemyWave = true;
		}
}