task EnemyDrawSystem(let num)
{
	num=num%4;
	let rect=[];
	let rect_length=32;
	let min=0.4;
	let cutflame=12;
	let animecount=0;
	let alpha=255;
	let color=255;
	
	let obj=SetEffectObject(tex_enemy,2);
	ObjEffect_SetRenderState(obj,ALPHA);
	
	while(!Obj_BeDeleted(obj))
	{
		if(absolute(GetSpeed)<min||absolute((cos(GetAngle))*360)<20)
		{
			let animepattern=[0,1,2,1];
			let count=truncate(animecount/cutflame)%length(animepattern);
			
			rect=[animepattern[count]*rect_length,num*(rect_length*2)];
		}
		else
		{
			let animepattern=[0,1,2,3];
			let count=truncate(absolute(GetSpeed-min)/0.5);
			if(count>=length(animepattern)){count=length(animepattern)-1;}
			
			if(cos(GetAngle)<=0){rect=[animepattern[count]*rect_length,rect_length+num*(rect_length*2)];}
			else{rect=[length(animepattern)*rect_length+animepattern[count]*rect_length,rect_length+num*(rect_length*2)];}
		}
		SetEffectObjectRect(obj,rect[0],rect[1],rect[0]+rect_length,rect[1]+rect_length);
		Obj_SetPosition(obj,GetX,GetY);
		
		ascent(a in 0..4)
		{
			ObjEffect_SetVertexColor(obj,a,alpha,color,color,color);
		}
		if(vanishflg){Obj_Delete(obj);}
		
		animecount++;
		yield;
	}
	
	yield;
	if(GetLife<lifelimit){AddLife(-lifelimit);}
	else{VanishEnemy;}
}

task EnemyCrestDrawSystem(let u,let v)
{
	LoadGraphic(tex_crest);
	
	let obj=SetEffectObject(tex_crest,2);
	SetEffectObjectRect(obj,0,0,u,v);
	ObjEffect_SetRenderState(obj,ALPHA);
//	Effect;
	let tuning=GetCommonData("Memory_ConfigData");
	let angle=0;
	let r=1;
	if(GetX<cenX){r=-r;}
	let agp=2;
	let count=0;
	while(!vanishflg)
	{
		Obj_SetPosition(obj,GetX,GetY);
		ObjEffect_SetAngle(obj,0,0,angle);
		ObjEffect_SetScale(obj,1,1);
		ascent(a in 0..4)
		{
			let alpha=96;
			ObjEffect_SetVertexColor(obj,a,alpha,255,255,255);
		}
		if(!tuning[1])
		{
			if(!(count%2)){Aura(angle);}
		}
		angle+=agp*r;
		agp=agp*0.99;
		count++;
		yield;
	}
	Obj_Delete(obj);
	
	task Effect
	{
		let obj=SetEffectObject(tex_crest,2);
		ObjEffect_SetRenderState(obj,ADD);
		SetEffectObjectRect(obj,0,0,u,v);
		let alpha=128;
		let scale=1;
		let count=0;
		while(alpha>2)
		{
			Obj_SetPosition(obj,GetX,GetY);
			ObjEffect_SetAngle(obj,0,0,0);
			ObjEffect_SetScale(obj,scale,scale);
			ascent(a in 0..4)
			{
				ObjEffect_SetVertexColor(obj,a,alpha,255,255,255);
			}
			alpha-=4;
			scale+=0.1;
			count++;
			yield;
		}
		Obj_Delete(obj);
	}
	
	task Aura(let angle)
	{
		let obj=SetEffectObject(tex_crest,1);
		ObjEffect_SetRenderState(obj,ADD);
		SetEffectObjectRect(obj,0,0,u,v);
		let alpha=96;
		let scale=1;
		let count=0;
		while(alpha>4)
		{
			Obj_SetPosition(obj,GetX,GetY);
			ObjEffect_SetAngle(obj,0,0,angle);
			ObjEffect_SetScale(obj,scale,scale);
			ascent(a in 0..4)
			{
				ObjEffect_SetVertexColor(obj,a,alpha,128,128,128);
			alpha-=2;
			}
			scale+=0.02;
			count++;
			yield;
		}
		Obj_Delete(obj);
	}
}
