
task RedMagicCircle(ID, type,delay){
	let def			= ObjPrim_Create(OBJ_SPRITE_2D);
	let move1		= 0;
	let moveA		= 0;
	let sca1		= 0;
	let scaA		= 0;
	let alpha		= 128;
	let gpos		= [ObjMove_GetX(GetEnemyBossObjectID),ObjMove_GetY(GetEnemyBossObjectID)];
	let spin		= 0;
	let RMangle		= 0;
	
	CreateCommonDataArea("RedMagic_Angle");
	
	alternative(type)
	case( 0 ){
		SetAreaCommonData("RedMagic_Angle", "angle", 0 );
		SetAreaCommonData("RedMagic_Angle", "spin", 0 );
	}
	case( 1 ){
		RMangle	= GetAreaCommonData("RedMagic_Angle", "angle", 0 );
		spin	= GetAreaCommonData("RedMagic_Angle", "spin", 0 );
	}
	
	ObjPrim_SetTexture(def, GetCurrentScriptDirectory~"/img/enm_effect01.png");
	Obj_SetRenderPriorityI(def, 32 );
	ObjRender_SetBlendType(def, BLEND_ADD_ARGB );
	ObjRender_SetAngleXYZ(def, 0, 0, RMangle );
	ObjRender_SetScaleXYZ(def, sca1, sca1, 0 );
	ObjSprite2D_SetSourceRect(def, 0, 0, 256, 256 );
	ObjSprite2D_SetDestCenter(def);
	ObjRender_SetAlpha(def, alpha );
	
	loop( delay ){gpos	= [ObjMove_GetX(GetAllEnemyID[0]),ObjMove_GetY(GetAllEnemyID[0])];
		ObjRender_SetPosition(def, gpos[0], gpos[1], 0 );
		yield;
	}
	
	
	while( !Obj_IsDeleted(ID) ){
		if (length(GetAllEnemyID)>0){gpos	= [ObjMove_GetX(GetAllEnemyID[0]),ObjMove_GetY(GetAllEnemyID[0])];}
		
		ObjRender_SetPosition(def, gpos[0], gpos[1], 0 );
		ObjRender_SetAngleXYZ(def, 24 - 24 * cos(spin), 24 - 24 * sin(spin), RMangle - move1*180 - spin*10 );
		if( type == 0 ){
			ObjRender_SetScaleXYZ(def, sca1 + 0.1 * sin( spin*5 ), sca1 + 0.1 * sin( spin*5 ), 0 );
			if( move1 < 1 ){ moveA += 2; }
			move1 = 1 * sin( moveA );
			if( sca1 < 1 ){ scaA += 2; }
			sca1 = 1 * sin( scaA );
			if( sca1 >= 1 && move1 >= 1 ){ spin += 0.6; }
		}
		else{
			ObjRender_SetScaleXYZ(def, 1 + 0.1 * sin( spin*5 ), 1 + 0.1 * sin( spin*5 ), 0 );
			spin += 0.6;
		}
		
		SetAreaCommonData("RedMagic_Angle", "spin", RMangle - move1*180 - spin*10 );
		SetAreaCommonData("RedMagic_Angle", "spin", spin );
		
		yield;
	}
	Obj_Delete(def);
}

task SetDistortion(ID,layer){

	
	let id			= [ObjPrim_Create(OBJ_SPRITE_2D),
						ObjPrim_Create(OBJ_SPRITE_2D),
						ObjPrim_Create(OBJ_SPRITE_2D)];
	let csd			= GetCurrentScriptDirectory;
	let dis1		= 0;
	let kaku		= 8;
	let cc			= 0;
	let ang			= 0;
	let pc			= 0;
	let i			= 0;
	let i2			= 1;
	let j			= 0;
	
	let ten			= ( kaku + 1 ) * 2;

	let _rect		= [1024/kaku,256/kaku];

	let wight		= [64,0];

	let ang_plus	= 0;
	
	loop( length(id) ){
		ObjRender_SetPosition(id[i], ObjMove_GetX(ID), ObjMove_GetY(ID), 0 );
		Obj_SetRenderPriorityI(id[i], layer );
		ObjRender_SetBlendType(id[i], BLEND_ALPHA );
		ObjRender_SetScaleXYZ(id[i], 1, 1, 0 );
		ObjRender_SetAngleXYZ(id[i], 0, 0, 0 );
		ObjPrim_SetPrimitiveType(id[i], PRIMITIVE_TRIANGLESTRIP );
		ObjPrim_SetVertexCount(id[i], ten );
		i++;
	}
	i = 0;
	
	dis1 = 48;
	
	while( !Obj_IsDeleted(ID) ){
		
		let texture = GetReservedRenderTargetName(0);
		RenderToTextureA1(texture, 10, 29, true);
		loop( length(id) ){
			ObjRender_SetPosition(id[j], ObjMove_GetX(ID), ObjMove_GetY(ID), 0 );
			ObjPrim_SetTexture(id[j], texture );
			j++;
		}
		j = 0;
		
		loop( ten ){
			loop( length(id) ){
				let disxy1 = [ (dis1-48)+wight[0]*j, (dis1+wight[0]-48)+wight[0]*j ];
				let vertexX = [ (disxy1[0] + (8) * cos(cc*4)) * cos(pc+ang),
								(disxy1[1] + (8) * cos(cc*4)) * cos(pc+ang) ];
				let vertexY = [ (disxy1[0] + (4) * sin(cc*4)) * sin(pc+ang),
								(disxy1[1] + (4) * sin(cc*4)) * sin(pc+ang) ];
				
				ObjPrim_SetVertexPosition(id[j], i, vertexX[0], vertexY[0], 0 );
				ObjPrim_SetVertexPosition(id[j], i2, vertexX[1], vertexY[1], 0 );
				
				ObjPrim_SetVertexUVT(id[j], i, 32+ObjMove_GetX(ID)+(disxy1[0]) * cos(pc+ang), 16+ObjMove_GetY(ID)+(disxy1[0]) * sin(pc+ang) );
				ObjPrim_SetVertexUVT(id[j], i2, 32+ObjMove_GetX(ID)+(disxy1[1]) * cos(pc+ang), 16+ObjMove_GetY(ID)+(disxy1[1]) * sin(pc+ang) );
				j++;
			}
			j = 0;
			ObjPrim_SetVertexAlpha(id[ 0 ], i, 0 );
			ObjPrim_SetVertexAlpha(id[ 0 ], i2, 255 );
			ObjPrim_SetVertexAlpha(id[ length(id)-1 ], i, 255 );
			ObjPrim_SetVertexAlpha(id[ length(id)-1 ], i2, 0 );
			pc			+= 360/kaku;
			i			+= 2;
			i2			+= 2;
		}
		pc			= 0;
		i			= 0;
		i2			= 1;
		
		
		
		cc++;
		ang += ang_plus;
		
		yield;
	}
	loop( length(id) ){
		Obj_Delete(id[i]);
		i++;
	}
	i = 0;
}