script_enemy_main
{
	#include_script".\..\..\EnemySystem.txt";
	
	tex_enemy=GetCurrentScriptDirectory~"Image/Utsuho_Caution.png";
	let endflg=false;
	@Initialize
	{
		EnemyInitialize(10000);
	}
	@MainLoop{yield;}
	@Finalize{}
	
	task MainThread_Standard{MainThread;}
	task MainThread_Advanced{MainThread;}
	task MainThread_Unlimited{MainThread;}
	
	task MainThread
	{
		DrawThread;
		while(!endflg){yield;}
		VanishEnemy;
	}
	
	task DrawThread
	{
		let i=rand(0,100);
		let limit=120;
		Caution(cenX,cenY-128,0,96,512,160);
		Caution(cenX,cenY+128,0,352,512,416);
		Mark;
		task Caution(let x,let y,let rect_l,let rect_u,let rect_r,let rect_d)
		{
			let obj=SetObject(5);
			let alpha=10;
			let count=0;
			while(alpha>=4)
			{
				SetRect(obj,rect_l+i,rect_u,rect_r+i,rect_d);
				DrawObject(obj,x,y,alpha);
				if(alpha<250&&count<60){alpha+=10;}
				if(count>limit){alpha-=10;}
				else{Effect(x,y,rect_l+i,rect_u,rect_r+i,rect_d);}
				count++;
				yield;
			}
			Obj_Delete(obj);
			wait(40);
			endflg=true;
		}
		
		task Mark
		{
			let obj=SetObject(5);
			let alpha=5;
			let count=0;
			while(alpha>=4)
			{
				SetRect(obj,0-i,160,512-i,352);
				DrawObject(obj,cenX,cenY,alpha);
				if(alpha<250&&count<60){alpha+=10;}
				if(count>limit){alpha-=10;}
				else{Effect(cenX,cenY,0-i,160,512-i,352);}
				count++;
				i+=0.75;
				yield;
			}
			Obj_Delete(obj);
		}
		
		task Effect(let x,let y,let rect_l,let rect_u,let rect_r,let rect_d)
		{
			let obj=SetObject(4);
			let alpha=48;
			let size=1;
			let count=0;
			while(alpha>4)
			{
				SetRect(obj,rect_l,rect_u,rect_r,rect_d);
				ObjEffect_SetScale(obj,size,size);
				DrawObject(obj,x,y,alpha);
				alpha-=6;
				size+=0.04;
				count++;
				yield;
			}
			Obj_Delete(obj);
		}
		
		
		function SetObject(let layer)
		{
			let obj=Obj_Create(OBJ_EFFECT);
			ObjEffect_SetTexture(obj,tex_enemy);
			ObjEffect_SetLayer(obj,layer);
			ObjEffect_SetRenderState(obj,ADD);
			ObjEffect_SetPrimitiveType(obj,PRIMITIVE_TRIANGLESTRIP);
			ObjEffect_CreateVertex(obj,4);
			return obj;
		}
		
		function SetRect(let obj,let reft,let up,let right,let down)
		{
			let texture_rect=[reft+1,up+1,right-1,down-1];
			let leng_h=texture_rect[2]-texture_rect[0];
			let leng_v=texture_rect[3]-texture_rect[1];
			
			ObjEffect_SetVertexXY(obj,0,-leng_h/2,-leng_v/2);
			ObjEffect_SetVertexXY(obj,1,-leng_h/2, leng_v/2);
			ObjEffect_SetVertexXY(obj,2, leng_h/2,-leng_v/2);
			ObjEffect_SetVertexXY(obj,3, leng_h/2, leng_v/2);
			
			ObjEffect_SetVertexUV(obj,0,texture_rect[0],texture_rect[1]);
			ObjEffect_SetVertexUV(obj,1,texture_rect[0],texture_rect[3]);
			ObjEffect_SetVertexUV(obj,2,texture_rect[2],texture_rect[1]);
			ObjEffect_SetVertexUV(obj,3,texture_rect[2],texture_rect[3]);
		}
		
		function DrawObject(let obj,let x,let y,let alpha)
		{
			Obj_SetPosition(obj,x,y);
			ascent(a in 0..4)
			{
				ObjEffect_SetVertexColor(obj,a,alpha,255,255,255);
			}
		}
	}
	
	task BGTask{}
}