task renderEikaWBaWC(obj)
{
	let dir;
	let speed;
	let whichway 	=  0;
	let frame 	=  0;
	let idleframe 	=  0;
	let castframe 	=  0;
	let endframe 	=  0;
	let type 	=  0;
	let wi 		= 64;
	let he 		= 80;
	Obj_SetValue(obj, "cast", 0);
	if(GetCommonData("dia", 0) == 0)
	{
		Aura(obj, 192, 63, 63);
		MagicCircle(obj);
	}
	EnemyName(obj, "Ebisu Eika");

	ObjPrim_SetTexture(obj, GetCurrentScriptDirectory ~ "../img/EikaWBaWCSprite.png");
	ObjSprite2D_SetSourceRect(obj, 0, 0, wi, he);
	ObjSprite2D_SetDestCenter(obj);
	ObjRender_SetScaleXYZ(obj, 1, 1, 0);
	ObjRender_SetAngleXYZ(obj, 0, 0, 0);
	
	while(!Obj_IsDeleted(obj) && GetCommonData("dia", 0) == 0)
	{
		dir   = ObjMove_GetAngle(obj);
		speed = ObjMove_GetSpeed(obj);

		     if	(speed == 0 && frame >  0){ whichway = -1; }
		else if	(speed == 0 && frame <  0){ whichway =  1; }
		else if	(speed == 0 && frame == 0){ whichway =  0; }

		else if	(cos(dir) < 0){ whichway= -1; }
		else if	(cos(dir) > 0){ whichway=  1; }
		
		
		if(Obj_GetValueD(obj, "cast", 0) == 0 && speed == 0 && frame == 0)
		{
			castframe = 0;
			frame = 0;

			     if	(idleframe >=  0 && idleframe <  7)	{ObjSprite2D_SetSourceRect(obj, wi * 0, he * 0, wi * 1, he * 1);}
			else if	(idleframe >=  7 && idleframe < 14)	{ObjSprite2D_SetSourceRect(obj, wi * 1, he * 0, wi * 2, he * 1);}
			else if	(idleframe >= 14 && idleframe < 21)	{ObjSprite2D_SetSourceRect(obj, wi * 2, he * 0, wi * 3, he * 1);}
			else if	(idleframe >= 21 && idleframe < 28)	{ObjSprite2D_SetSourceRect(obj, wi * 3, he * 0, wi * 4, he * 1);}
			else if	(idleframe >= 28 && idleframe < 35)	{ObjSprite2D_SetSourceRect(obj, wi * 4, he * 0, wi * 5, he * 1);}
			else if	(idleframe >= 35 && idleframe < 42)	{ObjSprite2D_SetSourceRect(obj, wi * 5, he * 0, wi * 6, he * 1);}
			
			     if	(idleframe <  42){idleframe++;}
			else if	(idleframe == 42){idleframe=0;}
			
		}
		
		else if(Obj_GetValueD(obj, "cast", 0) == 1 && speed == 0 && frame == 0)
		{
			frame	= 0;
			type	= 1;

			     if(castframe >=  0 && castframe <  7)	{ObjSprite2D_SetSourceRect(obj, wi * 4, he * 1, wi * 5, he * 2);}
			else if(castframe >=  7 && castframe < 14)	{ObjSprite2D_SetSourceRect(obj, wi * 0, he * 2, wi * 1, he * 3);}
			else if(castframe >= 14 && castframe < 21)	{ObjSprite2D_SetSourceRect(obj, wi * 1, he * 2, wi * 2, he * 3);}
			else if(castframe >= 21 && castframe < 28)	{ObjSprite2D_SetSourceRect(obj, wi * 2, he * 2, wi * 3, he * 3);}
			else if(castframe >= 28 && castframe < 35)	{ObjSprite2D_SetSourceRect(obj, wi * 3, he * 2, wi * 4, he * 3);}
			else if(castframe >= 35 && castframe < 42)	{ObjSprite2D_SetSourceRect(obj, wi * 4, he * 2, wi * 5, he * 3);}
			else if(castframe >= 42 && castframe < 49)	{ObjSprite2D_SetSourceRect(obj, wi * 5, he * 2, wi * 6, he * 3);}
			else if(castframe >= 49 && castframe < 56)	{ObjSprite2D_SetSourceRect(obj, wi * 6, he * 2, wi * 7, he * 3);}
			else if(castframe >= 56 && castframe < 63)	{ObjSprite2D_SetSourceRect(obj, wi * 7, he * 2, wi * 8, he * 3);}

			     if(castframe <= 63 && Obj_GetValueD(obj, "cast", 0) <  2){ castframe++; }
			else if(castframe >  63 && Obj_GetValueD(obj, "cast", 0) <  2){ castframe = 0; }
		}

		else if(speed != 0 || frame != 0)
		{
			
			     if(frame <   0 && frame >= - 7)	{ObjSprite2D_SetSourceRect(obj, wi * 0, he * 1, wi * 1, he * 2); ObjRender_SetAngleXYZ(obj, 0, 180, 0); type = -1;}
			else if(frame < - 7 && frame >= -14)	{ObjSprite2D_SetSourceRect(obj, wi * 1, he * 1, wi * 2, he * 2); ObjRender_SetAngleXYZ(obj, 0, 180, 0);}
			else if(frame < -14 && frame >= -21)	{ObjSprite2D_SetSourceRect(obj, wi * 2, he * 1, wi * 3, he * 2); ObjRender_SetAngleXYZ(obj, 0, 180, 0);}
			else if(frame < -21 && frame >= -22)	{ObjSprite2D_SetSourceRect(obj, wi * 3, he * 1, wi * 4, he * 2); ObjRender_SetAngleXYZ(obj, 0, 180, 0);}
			else if(frame >   0 && frame <=   7)	{ObjSprite2D_SetSourceRect(obj, wi * 0, he * 1, wi * 1, he * 2); ObjRender_SetAngleXYZ(obj, 0,   0, 0); type = -2;}
			else if(frame >   7 && frame <=  14)	{ObjSprite2D_SetSourceRect(obj, wi * 1, he * 1, wi * 2, he * 2); ObjRender_SetAngleXYZ(obj, 0,   0, 0);}
			else if(frame <  14 && frame <=  21)	{ObjSprite2D_SetSourceRect(obj, wi * 2, he * 1, wi * 3, he * 2); ObjRender_SetAngleXYZ(obj, 0,   0, 0);}
			else if(frame <  21 && frame <=  22)	{ObjSprite2D_SetSourceRect(obj, wi * 3, he * 1, wi * 4, he * 2); ObjRender_SetAngleXYZ(obj, 0,   0, 0);}
		}

		frame = frame + whichway;

		if(frame >  21){ frame =  21; }
		if(frame < -21){ frame = -21; }
		yield;
	}
	while(!Obj_IsDeleted(obj) && GetCommonData("dia", 0) == 1)
	{
		     if	(idleframe >=  0 && idleframe <  7)	{ObjSprite2D_SetSourceRect(obj, wi * 0, he * 3, wi * 1, he * 4);}
		else if	(idleframe >=  7 && idleframe < 14)	{ObjSprite2D_SetSourceRect(obj, wi * 1, he * 3, wi * 2, he * 4);}
		else if	(idleframe >= 14 && idleframe < 21)	{ObjSprite2D_SetSourceRect(obj, wi * 2, he * 3, wi * 3, he * 4);}
		else if	(idleframe >= 21 && idleframe < 28)	{ObjSprite2D_SetSourceRect(obj, wi * 3, he * 3, wi * 4, he * 4);}
		else if	(idleframe >= 28 && idleframe < 35)	{ObjSprite2D_SetSourceRect(obj, wi * 4, he * 3, wi * 5, he * 4);}
		else if	(idleframe >= 35 && idleframe < 42)	{ObjSprite2D_SetSourceRect(obj, wi * 5, he * 3, wi * 6, he * 4);}
			
		     if	(idleframe <  42){idleframe++;}
		else if	(idleframe == 42){idleframe=0;}

		yield;
	}
}

task renderKoishiSA(obj)
{
	let dir;
	let speed;
	let whichway 	=  0;
	let frame 	=  0;
	let idleframe 	=  0;
	let castframe 	=  0;
	let endframe 	=  0;
	let type 	=  0;
	let wi 		= 64;
	let he 		= 64;
	Obj_SetValue(obj, "cast", 0);
	if(GetCommonData("dia", 0) == 0)
	{
		Aura(obj, 192, 0, 0);
		MagicCircle(obj);
	}
	EnemyName(obj, "Komeiji Koishi");

	ObjPrim_SetTexture(obj, GetCurrentScriptDirectory ~ "../img/KoishiSASprite.png");
	ObjSprite2D_SetSourceRect(obj, 0, 0, 64, 64);
	ObjSprite2D_SetDestCenter(obj);
	ObjRender_SetScaleXYZ(obj, 1, 1, 0);
	ObjRender_SetAngleXYZ(obj, 0, 0, 0);
	
	while(!Obj_IsDeleted(obj))
	{
		dir   = ObjMove_GetAngle(obj);
		speed = ObjMove_GetSpeed(obj);

		     if	(speed == 0 && frame >  0){ whichway = -1; }
		else if	(speed == 0 && frame <  0){ whichway =  1; }
		else if	(speed == 0 && frame == 0){ whichway =  0; }

		else if	(cos(dir) < 0){ whichway= -1; }
		else if	(cos(dir) > 0){ whichway=  1; }
		
		if(Obj_GetValueD(obj, "cast", 0) == 0 && speed == 0 && frame == 0)
		{
			castframe = 0;

			     if	(idleframe >=  0 && idleframe <  7)	{ObjSprite2D_SetSourceRect(obj, wi * 0, he * 0, wi * 1, he * 1);}
			else if	(idleframe >=  7 && idleframe < 14)	{ObjSprite2D_SetSourceRect(obj, wi * 1, he * 0, wi * 2, he * 1);}
			else if	(idleframe >= 14 && idleframe < 21)	{ObjSprite2D_SetSourceRect(obj, wi * 2, he * 0, wi * 3, he * 1);}
			else if	(idleframe >= 21 && idleframe < 28)	{ObjSprite2D_SetSourceRect(obj, wi * 3, he * 0, wi * 4, he * 1);}
			else if	(idleframe >= 28 && idleframe < 35)	{ObjSprite2D_SetSourceRect(obj, wi * 2, he * 0, wi * 3, he * 1);}
			else if	(idleframe >= 35 && idleframe < 42)	{ObjSprite2D_SetSourceRect(obj, wi * 1, he * 0, wi * 2, he * 1);}
			
			     if	(idleframe <  42){ idleframe++; }
			else if	(idleframe == 42){ idleframe = 0; }
			
		}
		
		else if(Obj_GetValueD(obj, "cast", 0) == 1 && speed == 0 && frame == 0)
		{
			frame	= 0;
			type	= 1;

			     if(castframe >=  0 && castframe <  5)	{ObjSprite2D_SetSourceRect(obj, wi * 0, he * 2, wi * 1, he * 3);}
			else if(castframe >=  5 && castframe < 10)	{ObjSprite2D_SetSourceRect(obj, wi * 1, he * 2, wi * 2, he * 3);}
			else if(castframe >= 10 && castframe < 15)	{ObjSprite2D_SetSourceRect(obj, wi * 2, he * 2, wi * 3, he * 3);}
			else if(castframe >= 15 && castframe < 20)	{ObjSprite2D_SetSourceRect(obj, wi * 3, he * 2, wi * 4, he * 3);}

			     if(castframe <= 20){ castframe++; }
			else if(castframe == 20){ castframe++; }
		}

		else if(speed != 0 || frame != 0)
		{
			
			     if(frame <  0 && frame >= -2)	{ObjSprite2D_SetSourceRect(obj, wi * 0, he * 1, wi * 1, he * 2); ObjRender_SetAngleXYZ(obj, 0, 180, 0); type = -1;}
			else if(frame < -2 && frame >= -4)	{ObjSprite2D_SetSourceRect(obj, wi * 1, he * 1, wi * 2, he * 2); ObjRender_SetAngleXYZ(obj, 0, 180, 0);}
			else if(frame < -4 && frame >= -6)	{ObjSprite2D_SetSourceRect(obj, wi * 2, he * 1, wi * 3, he * 2); ObjRender_SetAngleXYZ(obj, 0, 180, 0);}
			else if(frame < -6 && frame >= -8)	{ObjSprite2D_SetSourceRect(obj, wi * 3, he * 1, wi * 4, he * 2); ObjRender_SetAngleXYZ(obj, 0, 180, 0);}
			else if(frame >  0 && frame <=  2)	{ObjSprite2D_SetSourceRect(obj, wi * 0, he * 1, wi * 1, he * 2); ObjRender_SetAngleXYZ(obj, 0,   0, 0); type = -2;}
			else if(frame >  2 && frame <=  4)	{ObjSprite2D_SetSourceRect(obj, wi * 1, he * 1, wi * 2, he * 2); ObjRender_SetAngleXYZ(obj, 0,   0, 0);}
			else if(frame >  4 && frame <=  6)	{ObjSprite2D_SetSourceRect(obj, wi * 2, he * 1, wi * 3, he * 2); ObjRender_SetAngleXYZ(obj, 0,   0, 0);}
			else if(frame >  6 && frame <=  8)	{ObjSprite2D_SetSourceRect(obj, wi * 3, he * 1, wi * 4, he * 2); ObjRender_SetAngleXYZ(obj, 0,   0, 0);}
		}

		frame = frame + whichway;

		if(frame >  8){ frame =  8; }
		if(frame < -8){ frame = -8; }
		yield;
	}
}

task MagicCircle(objE)
{
	let obj = ObjPrim_Create(OBJ_SPRITE_2D);
	ObjPrim_SetTexture(obj, GetCurrentScriptDirectory ~ "../img/magiccircle.png");
	Obj_SetRenderPriorityI(obj, 24);
	ObjSprite2D_SetSourceRect(obj, 0, 0, 256, 256);
	ObjSprite2D_SetDestCenter(obj);
	ObjRender_SetScaleXYZ(obj, 0, 0, 0);

	let scale = 0;
	let scale1 = 1.4;
	let scaleA = 0;
	let angle = 0;
	let angle1 = 3.6;
	let speed = 0;
	let speed1 = 0;
	let speed2 = 0;
	let speed3 = 0;

	while(!Obj_IsDeleted(objE))
	{
		ObjRender_SetAlpha(obj, 132);
		ObjRender_SetPosition(obj, ObjMove_GetX(objE), ObjMove_GetY(objE), 1);
		if(scale < scale1)
		{
			scale += scale1 / 28;
			angle -= angle1;
			angle1 += 0.02;
			ObjRender_SetScaleXYZ(obj, scale, scale, 0);
			ObjRender_SetAngleXYZ(obj, 25 - 25 * cos(speed), 2 + 27 * sin(speed), angle);
		}

		ObjRender_SetAngleXYZ(obj, -21 - 21 * cos(speed*1.3), 2 + 25 * sin(speed*1.3), angle - speed3*15 - speed*1.3 );
		ObjRender_SetScaleXYZ(obj, scale1 - 0.1 * sin( speed*0 ), scale1 - 0.1 * sin( speed*0 ), 0 );
		if(speed1 < 1){ speed2 += 2; }
		speed1 = 1 * sin( speed2 );
		if(scale1 < 1){ scaleA += 2; }
		scale1 = 1 * sin( scaleA );
		if(scale1 >= 1 && speed1 >= 1){ speed += 0.6; }

		if(ObjRender_GetAngleX(obj) == 0 && ObjRender_GetAngleZ(obj) == 0) { ObjSprite3D_SetBillboard(obj, true); }
		else { ObjSprite3D_SetBillboard(obj, false); }

		yield;
	}
	Obj_Delete(obj);
}

task Aura(objE, r, g, b)
{
	let ang = rand(1, 360);
	while(!Obj_IsDeleted(objE))
	{
		aura1(objE, r, g, b);
		aura2(objE, r, g, b, ang);
		ang += rand(45, 90);
		loop(10){ yield; }
	}
}

task aura1(objE, r, g, b)
{
	let alp = 255;
	let X = 1;
	let Y = 1 / 3;

	let obj = ObjPrim_Create(OBJ_SPRITE_2D);
	ObjPrim_SetTexture(obj, GetCurrentScriptDirectory ~ "../img/boss_aura.png");
	ObjSprite2D_SetSourceRect(obj, 0, 0, 64, 64);
	ObjRender_SetScaleXYZ(obj, X, Y, 1);
	Obj_SetRenderPriorityI(obj, 25);
	ObjSprite2D_SetDestRect(obj, -32, -64, 32, 0);
	ObjRender_SetBlendType(obj, BLEND_ADD_ARGB);
	ObjRender_SetPosition(obj, ObjRender_GetX(objE),ObjRender_GetY(objE),0);
	ObjRender_SetAngleXYZ(obj, 0, 0, rand(-5,5));
	ObjRender_SetColor(obj, r, g, b);

	loop(30)
	{
		if(Obj_IsDeleted(objE)){ Obj_Delete(obj); }
		ObjRender_SetScaleXYZ(obj, X, Y, 1);
		ObjRender_SetAlpha(obj, alp);
		ObjRender_SetPosition(obj, ObjMove_GetX(objE), ObjMove_GetY(objE) + 20, 0);
		alp -= 255/30;
		X += 0.0125;
		Y += 0.1;
		yield;
	}
	Obj_Delete(obj);
}

task aura2(objE, r, g, b, a)
{
	let alp = 255;
	let X = 1 / 3;
	let Y = 1 / 3;

	let obj = ObjPrim_Create(OBJ_SPRITE_2D);
	ObjPrim_SetTexture(obj, GetCurrentScriptDirectory~"../img/boss_aura.png");
	ObjSprite2D_SetSourceRect(obj, 64, 0, 128, 64);
	ObjRender_SetScaleXYZ(obj, X, Y, 1);
	Obj_SetRenderPriorityI(obj, 25);
	ObjSprite2D_SetDestCenter(obj);
	ObjRender_SetBlendType(obj, BLEND_ADD_ARGB);
	ObjRender_SetPosition(obj, ObjRender_GetX(objE),ObjRender_GetY(objE),0);
	ObjRender_SetAngleXYZ(obj, 0, 0, a);
	ObjRender_SetColor(obj, r, g, b);

	loop(30)
	{
		if(Obj_IsDeleted(objE)){ Obj_Delete(obj); }
		ObjRender_SetScaleXYZ(obj, X, Y, 1);
		ObjRender_SetAlpha(obj, alp);
		ObjRender_SetPosition(obj, ObjRender_GetX(objE), ObjRender_GetY(objE) + 20, 0);
		alp -= 255/30;
		X += 0.05;
		Y += 0.05;
		yield;
	}
	Obj_Delete(obj);
}