script_enemy_main
{
	#include_script".\..\..\EnemySystem.txt";
	
	@Initialize
	{
		point=1000;
		pflg=true;
		EnemyInitialize(590);
		MoveThread;
		EnemyDrawSystem(3);
	}
	@MainLoop{EnemyMainLoopSystem(30);yield;}
	@DrawLoop{}
	@Finalize{EnemyFinalize;}
	
	//---------------------------------------------------------------
	//---------------------------------------------------------------
	task MainThread_Standard
	{
		let r=1;
		if(GetX<cenX){r=-r;}
		loop(2)
		{
			wait(60);
			loop(2)
			{
				let px=GetPlayerX;
				let py=GetPlayerY;
				let ex=[GetX-30,GetX+30];
				let ey=GetY;
				loop(9)
				{
					let wide=180;
					let way=17;
					let sx=[GetX-30,GetX+30];
					let gra=87;
					let delay=10;
					ascent(a in 0..2)
					{
						let p=atan2(py-ey,px-ex[a]);
						let lp=0;
						let speed=[2,3];
						let angle=p-wide/2;
						while(angle<=p+wide/2+1)
						{
							SetEnemyShot01(sx[a],GetY,speed[lp%length(speed)],angle,gra,delay);
							lp++;
							angle+=wide/(way-1);
						}
					}
					wait(3);
				}
				wait(30);
			}
			
			let sp=0;
			let wd=180;
			while(wd<=500)
			{
				let p=90;
				let wide=150;
				let way=5;
				
				let speed=3+sp;
				let ag=p-wd/2;
				let gra=81;
				let delay=5;
				while(ag<=p+wd/2+1)
				{
					let angle=ag-wide/2;
					while(angle<=ag+wide/2+1)
					{
						let v=18;
						let sx=GetX+v*cos(angle);
						let sy=GetY+v*sin(angle);
						SetEnemyShot01(sx,sy,speed,angle,gra,delay);
						angle+=wide/(way-1);
					}
					ag+=wd;
				}
				wd+=3;
				wait(1);
			}
			loop(4)
			{
				let i=GetAngleToPlayer-20*r;
				let speed=1;
				loop(20)
				{
					let angle=i;
					let gra=147;
					let delay=10;
					SetEnemyShot01(GetX,GetY,speed,angle,gra,delay);
					i+=7*r;
					speed*=1.15;
				}
				wait(15);
				r=-r;
			}
		}
	}
	
	
	
	//---------------------------------------------------------------
	//---------------------------------------------------------------
	task MainThread_Advanced
	{
		wait(60);
		loop(2)
		{
			let lp=0;
			loop(10)
			{
				ascent(a in 0..2)
				{
					SetShot(a);
				}
				SetShot2(lp%2);
				lp++;
				wait(20);
				task SetShot(let a)
				{
					let i=60;
					let sp=0;
					loop(16)
					{
						let p=[90+i,90-i];
						let sx=[GetX-30,GetX+30];
						let speed=3+sp;
						let angle=p[a];
						let gra=87;
						let delay=10;
						SetEnemyShot01(sx[a],GetY,speed,angle,gra,delay);
						i+=-3;
						sp+=0.1;
						wait(3);
					}
				}
				task SetShot2(let a)
				{
					local
					{
						let sx=[GetX-30,GetX+30];
						let wide=2;
						let gra=25;
						let delay=10;
						let p=atan2(GetPlayerY-GetY,GetPlayerX-sx[a]);
						local
						{
							let speed=3.1;
							let angle=p;
							SetEnemyShot02(sx[a],GetY,0,angle,speed/100,speed,gra,delay);
						}
						local
						{
							let speed=3;
							let angle=p-wide/2;
							while(angle<=p+wide/2+1)
							{
								SetEnemyShot02(sx[a],GetY,0,angle,speed/100,speed,gra,delay);
								angle+=wide;
							}
						}
					}
				}
			}
			
			let lp=0;
			let sp=0;
			loop(8)
			{
				let wide=150;
				let way=12;
				let p=GetAngleToPlayer;
				let sx=[GetX-30,GetX+30];
				let speed=3+sp;
				let angle=p-wide/2;
				let gra=145;
				let delay=10;
				while(angle<=p+wide/2+1)
				{
					SetEnemyShot02(sx[lp%2],GetY,0,angle,speed/60,speed,gra,delay);
					angle+=wide/(way-1);
				}
				lp++;
				sp+=0.1;
				wait(10);
			}
			
			let px=GetPlayerX;
			let py=GetPlayerY;
			let sp=0;
			loop(30)
			{
				let wide=7;
				let way=3;
				
				let sx=[GetX-30,GetX+30];
				let speed=2+sp;
				let gra=82;
				let delay=10;
				ascent(a in 0..2)
				{
					let p=atan2(py-GetY,px-sx[a]);
					let angle=p-wide/2;
					while(angle<=p+wide/2+1)
					{
						SetEnemyShot01(sx[a],GetY,speed,angle,gra,delay);
						angle+=wide/(way-1);
					}
				}
				sp+=0.15;
				wait(3);
			}
		}
	}
	
	
	//---------------------------------------------------------------
	//---------------------------------------------------------------
	task MainThread_Unlimited
	{
		wait(60);
		loop(2)
		{
			Sub;
			task Sub
			{
				let lp=0;
				loop(7)
				{
					let sx=[GetX+40,GetX-40];
					SetShot(sx[lp%2],GetY);
					lp++;
					wait(40);
				}
				
				task SetShot(let ex,let ey)
				{
					let sx=ex;
					let sy=ey;
					loop(15)
					{
						let wide=40;
						let way=3;
						let gra=107;
						let delay=10;
						local
						{
							let p=90;
							local
							{
								let speed=4;
								let angle=p;
								SetEnemyShot02(sx,sy,0,angle,speed/90,speed,gra,delay);
							}
							local
							{
								let speed=3;
								let angle=p-wide/2;
								while(angle<=p+wide/2+1)
								{
									SetEnemyShot02(sx,sy,0,angle,speed/90,speed,gra,delay);
									angle+=wide;
								}
							}
						}
						wait(3);
					}
					
				}
			}
			let L=5;
			loop(3)
			{
				let p=GetAngleToPlayer;
				let lp=0;
				loop(L)
				{
					let way=10+lp%2;
					let wide=way*15;
					let speed=3.5;
					let angle=p-wide/2;
					let gra=25;
					let delay=10;
					while(angle<=p+wide/2+1)
					{
						let v=15;
						let sx=GetX+v*cos(angle);
						let sy=GetY+v*sin(angle);
						SetEnemyShot02(sx,sy,0,angle,speed/60,speed,gra,delay);
						angle+=wide/(way-1);
					}
					wait(8);
					lp++;
				}
				wait(45);
				L+=3;
			}
			wait(50);
		}
	}
	
	
	task MoveThread
	{
		let r=1;
		if(GetX>cenX){r=-r;}
		
		let wt=300;
		let mx=cenX+120*r;
		let my=minY+100;
		SetMovePositionHermite(mx,my,0,0,0,0,wt);
		
		wait(wt);
		
		let wt=300;
		let mx=cenX-90*r;
		let my=minY+170;
		SetMovePositionHermite(mx,my,0,0,0,0,wt);
		wait(wt);
		
		let wt=300;
		let mx=cenX-40*r;
		let my=minY-150;
		SetMovePositionHermite(mx,my,0,0,0,0,wt);
	}
}