#include "./../../system/functions/functions_enemy.txt"

task TMain
	{
	loop(5)
		{
		descent(i in 0..5)
			{
			ascent(dir in 0..2)	
				{
				dir = dir*2-1;
				CreateEnemyA1(GetStgFrameWidth*(0.5+dir*(0.05+i*0.375/4)));
				}
			loop(30){yield;}
			}
		}
	loop(120){yield;}
	loop(3)
		{
		let d = rand(0.05,0.425);
		descent(i in 0..5)
			{
			ascent(dir in 0..2)	
				{
				dir = dir*2-1;
				CreateEnemyA2(GetStgFrameWidth*(0.5+dir*(0.05+i*0.375/4)));
				}
			loop(40){yield;}
			}
		}
	loop(120){yield;}
	loop(4)
		{
		let d = rand(0.05,0.425);
		ascent(dir in 0..2)	
			{
			dir = dir*2-1;
			CreateEnemyA3(GetStgFrameWidth*(0.5+dir*d));
			}
		loop(105){yield;}
		}
	loop(120){yield;}
	ascent(dir in 0..2)	
		{
		dir = dir*2-1;
		ascent(i in 0..16)
			{
			let d = rand(0.05,0.425);
			CreateEnemyA3(GetStgFrameWidth*(0.5+dir*(-0.45+i*0.9/16)));
			loop(10){yield;}
			}
		loop(105){yield;}
		}
	}

task CreateEnemyA1(x)
	{
	let obj = CreateBasicEnemyA1(x,-32,5.25,90,100,50,type_fairy,fairy_red,0);
	ObjMove_SetAcceleration(obj,-ObjMove_GetSpeed(obj)/60);
	ObjMove_SetMaxSpeed(obj,0);
	while(!Obj_IsDeleted(obj) && ObjMove_GetSpeed(obj) > 0){yield;}
	if(Obj_IsDeleted(obj)){return;}
	let spread = 16;
	ascent(i in 0..spread)
		{
		CreateBulletA1(ObjMove_GetX(obj),ObjMove_GetY(obj),rand(2.5,5),(i+rand(0,1))*360/spread,BALL_S,8,1,SHOT_RED);
		}
	loop(60){yield;if(Obj_IsDeleted(obj)){return;}}
	ObjMove_SetAngle(obj,270);
	ObjMove_SetSpeed(obj,1.5);
	ObjMove_SetAcceleration(obj,0);
	while(!IsBeyondClip(obj,32) && !Obj_IsDeleted(obj)){yield;}
	Obj_Delete(obj);
	}
task CreateEnemyA2(x)	
	{
	let obj = CreateBasicEnemyA1(x,-32,5.25,90,100,50,type_fairy,fairy_green,0);
	ObjMove_SetAcceleration(obj,-ObjMove_GetSpeed(obj)/60);
	ObjMove_SetMaxSpeed(obj,0);
	while(!Obj_IsDeleted(obj) && ObjMove_GetSpeed(obj) > 0){yield;}
	if(Obj_IsDeleted(obj)){return;}
	let spread = [2,24];
	let a = rand(0,360);
	ascent(i0 in 0..spread[0])
		{
		ascent(i1 in 0..spread[1])
			{
			CreateBulletA1(ObjMove_GetX(obj),ObjMove_GetY(obj),2.5+i0*0.25/(spread[0]-1),(i1+i0*0.5)*360/spread[1]+a,SPARK,0,1,SHOT_YELLOW);
			}
		}
	loop(60){yield;if(Obj_IsDeleted(obj)){return;}}
	ObjMove_SetAngle(obj,270);
	ObjMove_SetSpeed(obj,1.5);
	ObjMove_SetAcceleration(obj,0);
	while(!IsBeyondClip(obj,32) && !Obj_IsDeleted(obj)){yield;}
	Obj_Delete(obj);
	}
task CreateEnemyA3(x)	
	{
	let obj = CreateBasicEnemyA1(x,-32,5.25,90,100,50,type_fairy,fairy_blue,0);
	ObjMove_SetAcceleration(obj,-ObjMove_GetSpeed(obj)/60);
	ObjMove_SetMaxSpeed(obj,0);
	while(!Obj_IsDeleted(obj) && ObjMove_GetSpeed(obj) > 0){yield;}
	if(Obj_IsDeleted(obj)){return;}
	let a = rand(0,360);
	TSpam;
	loop(60){yield;if(Obj_IsDeleted(obj)){return;}}
	ObjMove_SetAngle(obj,270);
	ObjMove_SetSpeed(obj,1.5);
	ObjMove_SetAcceleration(obj,0);
	while(!IsBeyondClip(obj,32) && !Obj_IsDeleted(obj)){yield;}
	Obj_Delete(obj);

	task TSpam
		{
		let spread = 3;
		let x = ObjMove_GetX(obj);
		let y = ObjMove_GetY(obj);	
		let a = GetAngleToPlayer(obj);
		loop(10)
			{
			ascent(i in 0..spread)
				{
				i = i-spread*0.5+0.5;
				let shot = CreateBulletA1(x,y,8,a+i*30/spread,KUNAI,8,1,SHOT_BLUE);
				}
			loop(5){yield;}
			}
		}
	}