#include "./enemylist.txt"
function TStage
{
	let time = -1;
	loop(1){
	local
		{
		ascent(dir in 0..2)
			{
			dir = dir*2-1;
			ascent(t in 0..6)
				{
				CreateEnemyA1(GetStgFrameWidth*(0.5+dir*0.425)-dir*(t%2)*32,dir,-1);
				loop(30){yield;}
				}
			loop(60){yield;}
			}
		loop(30){yield;}
		ascent(t in 0..6)
			{
			ascent(dir in 0..2)
				{
				dir = dir*2-1;
				CreateEnemyA1(GetStgFrameWidth*(0.5+dir*0.425)-dir*(t%2)*32,dir,-1);
				}
			loop(30){yield;}
			}
		}
	loop(90){yield;}
	local
		{
		ascent(dir in 0..2)
			{
			dir = dir*2-1;
			ascent(t in 0..6)
				{
				CreateEnemyB1(dir,t%2);
				loop(16){yield;}
				}
			if(dir == -1)
				{
				loop(180){yield;}
				}
			}
		loop(180){yield;}
		ascent(t in 0..4)
			{
			ascent(dir in 0..2)
				{
				dir = dir*2-1;
				CreateEnemyA1(GetStgFrameWidth*(0.5+dir*0.425)-dir*(t%2)*32,dir,-1);
				}
			loop(45){yield;}
			}
		}
	loop(60){yield;}
	local
		{
		let obj = CreateEnemyC1;
		while(!Obj_IsDeleted(obj))
			{
			time+=1;
			yield;
			}
		}
	loop(75){yield;}
	local
		{	
		TPattern1;
		loop(time-180){yield;}
		ascent(dir in 0..2)
			{
			dir = dir*2-1;
			ascent(t in 0..4)
				{
				loop(18){yield;}
				}
			if(dir == -1)
				{
				loop(90){yield;}
				}
			}
		}}
	loop(180){yield;}
	ClearStage;
	mid = false;

	task TPattern1
		{
		let spread = [8,4,8];
		time = max(0,2340-time);
		let count = 5;
		descent(counter in 2340-time..2340)
			{
			if(counter%floor((GetStgFrameWidth-48)/(spread[0]*spread[1])) == 0)
				{
				count+=1;
				}
			}
		descent(counter in 0..time)
			{
			if(counter%floor((GetStgFrameWidth-48)/(spread[0]*spread[1])) == 0)
				{
				let dir = floor(counter*spread[1]/(GetStgFrameWidth-48))%2;
				CreateEnemyD1(dir*GetStgFrameWidth-(dir*2-1)*((counter*spread[1])%(GetStgFrameWidth-48)+24),floor((count%spread[2])/(spread[2]-1)));
				count+=1;
				}
			if(counter < 1530 && counter%270 == 0 && counter > 270)
				{
				let dir = (floor(counter*spread[1]/(GetStgFrameWidth-32))%2)*2-1;
				CreateEnemyD2(dir);
				}
			yield;
			}
		time = 0;
		
		}
}