
task EnemyA3(id,type,life){
	let img;
	let animA = 0;
	let animB = 0;
	let A = 0;
	let s = 0;
	let c = 0;
	let color;
	
	ObjEnemy_Regist(id);
	ObjEnemy_SetLife(id,life);
	Obj_SetRenderPriority(id, 0.41);
	
		if(type == 0){
			color = [255,60,60];
			img = GetMainStgScriptDirectory ~ "img/enemy/fairy_red.png";
			}
		if(type == 1){
			color = [60,60,255];
			img = GetMainStgScriptDirectory ~ "img/enemy/fairy_blue.png";
			}
		if(type == 2){
			color = [60,255,60];
			img = GetMainStgScriptDirectory ~ "img/enemy/fairy_green.png";
		}
		if(type == 3){
			color = [255,255,60];
			img = GetMainStgScriptDirectory ~ "img/enemy/fairy_yellow.png";
			}
		if(type == 4){
			color = [255,255,255];
			img = GetMainStgScriptDirectory ~ "img/enemy/fairy_white.png";
			}
		if(type == 5){
			color = [100,100,100];
			img = GetMainStgScriptDirectory ~ "img/enemy/fairy_black.png";
		}
		if(type == 6){
			color = [255,60,255];
			img = GetMainStgScriptDirectory ~ "img/enemy/fairy_ex1.png";
		}
		
	ObjPrim_SetTexture(id,img);
	
		while(ObjEnemy_GetInfo(id, INFO_LIFE) > 0){
			let s = ObjMove_GetSpeed(id);
			let a = ObjMove_GetAngle(id);
			
			if(s == 0){
				ObjRender_SetAngleY(id,0);
				
				if(animA%24 < 8){A=0;}
				else if(animA%24 < 16){A=1;}
				else if(animA%24 < 24){A=2;}
				
				animB = 0;
			}
			
			else if(cos(a) < 0){
				ObjRender_SetAngleY(id,180);
				if(animB < 8){A=3;}
				else if((animB-8)%24 < 8){A=4;}
				else if((animB-8)%24 < 16){A=5;}
				else if((animB-8)%24 < 24){A=6;}
			}
			
			else{
				ObjRender_SetAngleY(id,0);
				
				if(animB < 8){A=3;}
				else if((animB-8)%24 < 8){A=4;}
				else if((animB-8)%24 < 16){A=5;}
				else if((animB-8)%24 < 24){A=6;}
			}
			ObjSprite2D_SetSourceRect(id,A*64,288,(A+1)*64,352);
			ObjSprite2D_SetDestCenter(id);
			ObjEnemy_SetIntersectionCircleToShot(id,GetX(id),GetY(id),24);
			ObjEnemy_SetIntersectionCircleToPlayer(id,GetX(id),GetY(id),16);
			
			animA++;
			animB++;
			
		if(GetX(id) > GetStgFrameWidth+120 || GetX(id) < -120 || GetY(id) > GetStgFrameHeight+120 || GetY(id) < -120){
			Obj_Delete(id);
			return;
		}
			
			yield;
			
			}
		
		TExplosionA1(GetX(id), GetY(id), color, "cherry");
		Obj_Delete(id);	
}

task EnemyB1(id,life){
	let img = GetMainStgScriptDirectory ~ "img/enemy/yinyang.png";
	let color;
	let z = 0;
	
	ObjEnemy_Regist(id);
	ObjEnemy_SetLife(id,life);
	Obj_SetRenderPriority(id, 0.41);
	ObjPrim_SetTexture(id,img);
	ObjSprite2D_SetSourceRect(id,96,32,128,64);
	ObjSprite2D_SetDestRect(id,-14,-14,15,15);
	RingArooouuund(id);

	color = [255,255,255];
		
	while(ObjEnemy_GetInfo(id, INFO_LIFE) > 0){
			
		if(GetX(id) > GetStgFrameWidth+120 || GetX(id) < -120 || GetY(id) > GetStgFrameHeight+120 || GetY(id) < -120){
			Obj_Delete(id);
			return;
			}
			
		ObjRender_SetAngleZ(id,z*5);
			
		ObjEnemy_SetIntersectionCircleToShot(id,GetX(id),GetY(id),8);
		ObjEnemy_SetIntersectionCircleToPlayer(id,GetX(id),GetY(id),8);
		
		z++;
			
		yield;
	}
	
	NotifyEventAll(EV_USER_STAGE + 4,[GetX(id), GetY(id), color[0], color[1], color[2]]);
	Obj_Delete(id);	

	task RingArooouuund(obja){
		yield;

		let obj = ObjPrim_Create(OBJ_SPRITE_2D);
		ObjPrim_SetTexture(obj,img);
		Obj_SetRenderPriority(obj, 0.41);
		ObjSprite2D_SetSourceRect(obj,96,96,128,128);
		ObjSprite2D_SetDestRect(obj,-14,-14,15,15);
		ObjRender_SetScaleXYZ(obj,1.5,1.5,0);

		while(!Obj_IsDeleted(obja)){
			ObjRender_SetPosition(obj,GetX(obja),GetY(obja),0);
			ObjRender_SetAngleZ(obj,ObjRender_GetAngleZ(obj)-5);
			yield;
		}

		Obj_Delete(obj);
	}
}

task EnemyB2(id,life){
	let img = GetMainStgScriptDirectory ~ "img/enemy/hitodama.png";
	let color;
	let A = 0;
	let spa = 0;
	
	ObjEnemy_Regist(id);
	ObjEnemy_SetLife(id,life);
	Obj_SetRenderPriority(id, 0.41);
	ObjPrim_SetTexture(id,img);
	
	color = [255,255,255];

	while(ObjEnemy_GetInfo(id, INFO_LIFE) > 0){
			
		if(GetX(id) > GetStgFrameWidth+120 || GetX(id) < -120 || GetY(id) > GetStgFrameHeight+120 || GetY(id) < -120){
			Obj_Delete(id);
			return;
			}
			
		ObjEnemy_SetIntersectionCircleToShot(id,GetX(id),GetY(id),16);
		ObjEnemy_SetIntersectionCircleToPlayer(id,GetX(id),GetY(id),8);
			
		ObjSprite2D_SetSourceRect(id,(truncate(A)%8)*32,224,(truncate(A)%8+1)*32,256);
		ObjSprite2D_SetDestCenter(id);
		
		if(spa%3 == 0){AnimateSpiritTrail(id, 90+rand(-15,15), 224, 1, img);} 
		
		A+=1/3;
		spa++;
			
		yield;
		}
		
	NotifyEventAll(EV_USER_STAGE + 4,[GetX(id), GetY(id), color[0], color[1], color[2]]);
	Obj_Delete(id);	
}

task AnimateSpiritTrail(obj, a, y, s, img){//Python?
	let objs = ObjPrim_Create(OBJ_SPRITE_2D);

	Move(obj, objs, a, s);
	Obj_SetRenderPriorityI(objs, Obj_GetRenderPriorityI(obj)-1);
	ObjPrim_SetTexture(objs, img);
	ObjRender_SetBlendType(objs, BLEND_ADD_ARGB);
	ObjRender_SetPosition(objs,ObjMove_GetX(obj)+round(rand(-3,3)),ObjMove_GetY(obj),0);

	while(!Obj_IsDeleted(objs)){
		ascent(x in 0..8){
			ObjSprite2D_SetSourceRect(objs,32*x,y,32*(x+1),32+y);
			ObjSprite2D_SetDestCenter(objs);
			loop(3){yield;}
		}
		yield;
	}
	task Move(obj, objs, a, s){
		let si = s;
		let speed = 3;
		let angle = a-180;

		if(ObjMove_GetSpeed(obj) == 0){angle = 270;}

		let mx = speed*cos(angle);
		let my = speed*sin(angle);

		while(si >0){
			si-=0.07;
			if(si < 0){Obj_Delete(objs);}
			ObjRender_SetPosition(objs,ObjRender_GetX(objs)+mx,ObjRender_GetY(objs)+my,0);
				
			ObjRender_SetScaleXYZ(objs,si,si,0);
			yield;
		}
	}
}