script_enemy_main
{
	#include_script".\..\..\EnemySystem.txt";
	
	@Initialize
	{
		point=0;
		EnemyInitialize(90);
		MoveThread;
	}
	@MainLoop{EnemyMainLoopSystem(10);yield;}
	@DrawLoop{}
	@Finalize{EnemyFinalize;}
	
	//---------------------------------------------------------------
	//---------------------------------------------------------------
	task MainThread_Standard
	{
		State;
		if(enemyargument==0){Shot1;}
		else{Shot2;}
		
		task Shot1
		{
			wait(60+trunc((absolute(enemyangle)%360)/4));
			loop
			{
				let s=0;
				loop(12)
				{
					let wide=100;
					let way=3;
					let p=GetAngleToPlayer;
					let speed=2.5;
					let angle=p;
					let gra=10;
					let delay=0;
//					while(angle<=p+wide/2+1)
//					{
						CreateShot02(GetX,GetY,0,angle,speed/60,speed,gra,delay);
//						angle+=wide/(way-1);
//					}
					wait(2);
					s+=0.1;
				}
				wait(60);
			}
		}
		
		task Shot2
		{
			wait(60);
			loop(4)
			{
				local
				{
					let p=GetAngleToPlayer;
					let wide=40;
					let way=3;
					let speed=[2,2.4];
					let angle=p-wide/2;
					let gra=145;
					let delay=5;
					while(angle<=p+wide/2+1)
					{
						ascent(a in 0..length(speed))
						{
							CreateShot02(GetX,GetY,0,angle,speed[a]/60,speed[a],gra,delay);
						}
						angle+=wide/(way-1);
					}
				}
				wait(80);
			}
		}
		
		task State
		{
			wait(420);
			local
			{
				let p=GetAngleToPlayer;
				let wide=40;
				let way=3;
				let speed=[2,2.4];
				let angle=p-wide/2;
				let gra=145;
				let delay=20;
				while(angle<=p+wide/2+1)
				{
					ascent(a in 0..length(speed))
					{
						CreateShot02(GetX,GetY,0,angle,speed[a]/60,speed[a],gra,delay);
					}
					angle+=wide/(way-1);
				}
			}
			yield;
			vanishflg=true;
			VanishEnemy;
		}
	}
	
	//---------------------------------------------------------------
	//---------------------------------------------------------------
	task MainThread_Advanced{}
	
	
	//---------------------------------------------------------------
	//---------------------------------------------------------------
	task MainThread_Unlimited{}
	
	
	task MoveThread
	{
		SetSpeed(0);SetAngle(0);
		let r=1;
		if(enemyangle<0){r=-r;}
		let lp=0;
		let limit=140;
		while(!vanishflg)
		{
			local
			{
				let gra=1;
				let delay=4;
				CreateShotA(1,GetX,GetY,delay);
				SetShotDataA(1,0,0,0,0,0,0,gra);
				SetShotKillTime(1,0);
				FireShot(1);
			}
			SetX(GetEnemyX+enemyspeed*cos(enemyangle+lp));
			SetY(GetEnemyY+enemyspeed*sin(enemyangle+lp/2));
			
			enemyangle+=1.5*cos(180+lp)*r;
			if(enemyspeed<=limit){enemyspeed+=limit/50;}
			lp++;
			yield;
		}
		if(GetLife<lifelimit){AddLife(-lifelimit);}
		else{VanishEnemy;}
	}
}