script_enemy_main
{
	#include_script".\..\..\EnemySystem.txt";
	
	@Initialize
	{
		point=550;
		
		EnemyInitialize(180);
		MoveThread;
		EnemyDrawSystem(1);
	}
	@MainLoop{EnemyMainLoopSystem(30);yield;}
	@DrawLoop{}
	@Finalize{EnemyFinalize;}
	
	//---------------------------------------------------------------
	//---------------------------------------------------------------
	task MainThread_Standard
	{
		wait(60);
		loop(2)
		{
			let p=GetAngleToPlayer;
			let px=GetPlayerX;
			let py=GetPlayerY;
			let sp=0;
			loop(10)
			{
				local
				{
					let way=15;
					let wide=300;
					
					let speed=2+sp/5;
					let ag=p+180;
					let angle=ag-wide/2;
					let gra=68;
					let delay=5;
					while(angle<=ag+wide/2+1)
					{
						let v=20;
						let sx=GetX+v*cos(angle);
						let sy=GetY+v*sin(angle);
						SetEnemyShot01(sx,sy,speed,angle,gra,delay);
						angle+=wide/(way-1);
					}
				}
				
				local
				{
					let wide=4;
					let sx=[GetX-30,GetX+30];
					let speed=[2+sp,2.5+sp];
					let gra=81;
					let delay=10;
					ascent(a in 0..2)
					{
						let ag=atan2(py-GetY,px-sx[a]);
						let angle=ag-wide/2;
						while(angle<=ag+wide/2+1)
						{
							ascent(b in 0..length(speed))
							{
								SetEnemyShot01(sx[a],GetY,speed[b],angle,gra,delay);
							}
							angle+=wide;
						}
					}
				}
				sp+=0.4;
				wait(3);
			}
			wait(120);
		}
		enemyargument=1;
	}
	
	
	
	//---------------------------------------------------------------
	//---------------------------------------------------------------
	task MainThread_Advanced
	{
		wait(60);
		loop(3)
		{
			let sp=0;
			loop(15)
			{
				let sx=GetX+rand(-15,15);
				let sy=GetY+rand(-15,15);
				let p=atan2(GetPlayerY-sy,GetPlayerX-sx);
				let speed=3.5+sp;
				let angle=p;
				let gra=26;
				let delay=10;
				SetEnemyShot01(sx,sy,speed,angle,gra,delay);
				
				local
				{
					let wide=150;
					let way=4;
					let speed=2.5+sp;
					let gra=10;
					let angle=p-wide/2;
					while(angle<=p+wide/2+1)
					{
						SetEnemyShot01(sx,sy,speed,angle,gra,delay);
						angle+=wide/(way-1);
					}
				}
				
				sp+=0.05;
				wait(1);
			}
			wait(40);
			let p=rand(0,360);
			let sp=0;
			loop(2)
			{
				let way=30;
				let speed=3.5-sp;
				let angle=p;
				let gra=146;
				let delay=10;
				while(angle<p+360)
				{
					SetEnemyShot02(GetX,GetY,0,angle,speed/60,speed,gra,delay);
					angle+=360/way;
				}
				wait(30);
			}
			wait(40);
		}
		
		

		enemyargument=1;
	}
	
	
	//---------------------------------------------------------------
	//---------------------------------------------------------------
	task MainThread_Unlimited
	{
		wait(60);
		loop(2)
		{
			let p=GetAngleToPlayer;
			loop(3)
			{
				let wide=25;
				let gra=31;
				let delay=10;
				local
				{
					let speed=2.8;
					let angle=p-wide/2;
					while(angle<=p+wide/2+1)
					{
						SetEnemyShot01(GetX,GetY,speed,angle,gra,delay);
						angle+=3;
					}
				}
				local
				{
					let wd=120;
					let speed=1.6;
					let ag=p-wd/2;
					while(ag<=p+wd/2+1)
					{
						let angle=ag-wide/2;
						while(angle<=ag+wide/2+1)
						{
							SetEnemyShot01(GetX,GetY,speed,angle,gra,delay);
							angle+=3;
						}
						ag+=wd;
					}
				}
				wait(10);
			}
			wait(30);
			
			loop(9)
			{
				let sx=[GetX+30,GetX-30];
				ascent(a in 0..2)
				{
					let p=atan2(GetPlayerY-GetY,GetPlayerX-sx[a]);
					let gra=62;
					let delay=10;
					local
					{
						let speed=4;
						let angle=p;
						while(speed>2.5)
						{
							SetEnemyShot01(sx[a],GetY,speed,angle,gra,delay);
							speed/=1.15;
						}
					}
					local
					{
						let wide=60;
						let speed=3;
						while(speed>=2)
						{
							let angle=p-wide/2;
							while(angle<=p+wide/2+1)
							{
								SetEnemyShot01(sx[a],GetY,speed,angle,gra,delay);
								angle+=wide;
							}
							speed/=1.15;
						}
					}
					wait(6);
				}
			}
		}
		enemyargument=1;
	}
	
	
	task MoveThread
	{
		while(enemyargument==0)
		{
			SetSpeed(enemyspeed);
			if(enemyspeed>0){enemyspeed-=0.07;}
			yield;
		}
		let count=0;
		loop
		{
			SetSpeed(enemyspeed);
			if(enemyspeed<1.5){enemyspeed+=0.025;}
			count++;
			yield;
		}
	}
}