//Most of tasks and functions in here are from TalosMistake's Star Sapphire Script's function
task SpellStart(objEnemy, text, img, x, y, scale)
{
	SetSpellName(objEnemy, text);
	CutInImage(img, x, y, scale);
	SpellCardAttackEffect;
}
task SetSpellName(objEnemy, text)
{
	let objName = ObjText_Create;
	ObjText_SetText(objName, text);

	ObjText_SetFontSize(objName, 16);
	ObjText_SetFontColorTop(objName, 255, 255, 255);
	ObjText_SetFontColorBottom(objName, 255, 255, 255);
	ObjText_SetFontBorderType(objName, BORDER_FULL);
	ObjText_SetFontBorderWidth(objName, 1);
	ObjText_SetFontBorderColor(objName, 0, 0, 0);
	ObjText_SetMaxWidth(objName, 500);
	ObjText_SetHorizontalAlignment(objName, ALIGNMENT_RIGHT);
	Obj_SetRenderPriorityI(objName, 80);
	ObjRender_SetX(objName, -118);
	ObjRender_SetY(objName, 408);
	ObjRender_SetAlpha(objName, 255);
	
	let scale = 10;
	loop(30)
	{
		scale -= 0.3;
		ObjRender_SetScaleXYZ(objName, scale, scale, scale);
		yield;
	}

	let objEffect = ObjPrim_Create(OBJ_SPRITE_2D);
	ObjRender_SetBlendType(objEffect, BLEND_ALPHA);
	Obj_SetRenderPriority(objEffect, 0.40);
	ObjPrim_SetTexture(objEffect, GetCurrentScriptDirectory() ~ "./effectSpell.png");
	ObjSprite2D_SetDestRect(objEffect, -128, -20, 128, 20);
	ObjSprite2D_SetSourceRect(objEffect, 0, 0, 256, 40);

	let alpha = 0;
	let y = 443;
	loop(15)
	{
		ObjRender_SetX(objEffect, 254);
		ObjRender_SetY(objEffect, y);
		ObjRender_SetAlpha(objEffect, alpha);

		alpha += 13;
		y -= 2;
		yield;
	}
	loop(15){yield;}
	loop(30)
	{
		ObjRender_SetY(objName, y - 5);
		ObjRender_SetY(objEffect, y);
		
		y -= 388 / 30;
		yield;
	}

	/*let objBonus = ObjText_Create;
	ObjText_SetText(objBonus, "BONUS");

	ObjText_SetFontType(objBonus,"Cabin");
	ObjText_SetFontSize(objBonus, 10);
	ObjText_SetFontColorTop(objBonus, 255, 255, 255);
	ObjText_SetFontColorBottom(objBonus, 255, 255, 255);
	ObjText_SetFontBorderType(objBonus, BORDER_FULL);
	ObjText_SetFontBorderWidth(objBonus, 1);
	ObjText_SetFontBorderColor(objBonus, 0, 0, 0);
	ObjText_SetMaxWidth(objBonus, 500);
	ObjText_SetHorizontalAlignment(objBonus, ALIGNMENT_LEFT);
	Obj_SetRenderPriorityI(objName, 80);
	ObjRender_SetX(objName, 254);
	ObjRender_SetY(objName, 24);


	let objScore = ObjText_Create;

	ObjText_SetFontType(objName,"Cabin");
	ObjText_SetFontSize(objName, 10);
	ObjText_SetFontColorTop(objName, 255, 255, 255);
	ObjText_SetFontColorBottom(objName, 255, 255, 255);
	ObjText_SetFontBorderType(objName, BORDER_FULL);
	ObjText_SetFontBorderWidth(objName, 1);
	ObjText_SetFontBorderColor(objName, 0, 0, 0);
	ObjText_SetMaxWidth(objName, 500);
	ObjText_SetHorizontalAlignment(objName, ALIGNMENT_RIGHT);
	Obj_SetRenderPriorityI(objName, 80);
	ObjRender_SetX(objName, 254);
	ObjRender_SetY(objName, 24);*/

	AlphaChange(objName);
	AlphaChange(objEffect);
	AutoDelete(objEnemy, objName);
	AutoDelete(objEnemy, objEffect);
}

task AlphaChange(obj)
{
	let alpha = 255;
	while(!Obj_IsDeleted(obj))
	{
		if(GetPlayerY < 50)
		{
			alpha -= 16;
			alpha = max(alpha, 95);
		}
		else
		{
			alpha += 16;
			alpha = min(alpha, 255);
		}
		ObjRender_SetAlpha(obj, alpha);
		yield;
	}
}

task CutInImage(img, x, y, scale)
{	
	let objCutin = ObjPrim_Create(OBJ_SPRITE_2D);
	ObjPrim_SetTexture(objCutin, img);
	ObjSprite2D_SetSourceRect(objCutin, 0, 0, x, y);
	ObjRender_SetScaleXYZ(objCutin, scale, scale, scale);
  	ObjSprite2D_SetDestCenter(objCutin);
	ObjRender_SetPosition(objCutin, 400, 120, 0);
	Obj_SetRenderPriority(objCutin, 0.50);

	loop(30)
	{
		ObjRender_SetX(objCutin, ObjRender_GetX(objCutin) - 6.6);
		ObjRender_SetY(objCutin, ObjRender_GetY(objCutin) + 3.6);
		yield;
	}
	loop(30){ yield; }
	let alpha = 255;
	loop(30)
	{
		alpha -= 8.5;
		ObjRender_SetX(objCutin, ObjRender_GetX(objCutin) - 9.9);
		ObjRender_SetY(objCutin, ObjRender_GetY(objCutin) + 4.5);
		ObjRender_SetAlpha(objCutin, alpha);
		yield;
	}
	Obj_Delete(objCutin);
}

task SpellCardAttackEffect
{
	let alpha = 1;
	ascent(i in 0..5)
	{
		LineEffect(192, 129 + 75 * ( i - 1), 1);
		LineEffect(192, 129 + 75 * ( i - 0.5), -1);
	}
	CircleEffect(384, 448, -1.15, 180, 1);
	CircleEffect(384, 448, 1.05, 240, 0);
	CircleEffect(384, 448, 1.05, 295, 0);
	CircleEffect(38.4, 44.8, 0.75, 170, 1);
	ascent(i in 0..20)
	{
		alpha = 0.1 + 7.25 *i;
		yield;
	}
	loop(50){yield;}
	descent(i in 0..20)
	{
		alpha = 7.25 *i;
		yield;
	}
	task LineEffect(x, y, dir)
	{
		let objAttack = ObjPrim_Create(OBJ_SPRITE_2D);
		ObjRender_SetBlendType(objAttack, BLEND_ALPHA);
		Obj_SetRenderPriority(objAttack, 0.75);
		ObjPrim_SetTexture(objAttack, GetCurrentScriptDirectory() ~ "./SpellCardAttack.png");
		ObjSprite2D_SetSourceRect(objAttack, 0, 0, 512, 16);
		ObjSprite2D_SetDestRect(objAttack, -256, -8, 256, 8);
		ObjRender_SetPosition(objAttack, x, y, 0);
		ObjRender_SetAngleZ(objAttack, -35);
		let sourceX = 0;
		while( alpha >0)
		{
			sourceX += dir * 1.5;
			ObjSprite2D_SetSourceRect(objAttack, sourceX, 0, 512 + sourceX, 16);
			ObjRender_SetAlpha(objAttack, alpha);
			yield;
		}
		Obj_Delete(objAttack);
	}

	task CircleEffect(x, y, sp, rad, dir)
	{	
		let NUM_VERTEX = 16;
		let listRadius = [];
		loop(NUM_VERTEX)
		{
			listRadius = listRadius ~ [0];
		}

		let objSpell = ObjPrim_Create(OBJ_PRIMITIVE_2D);
		ObjPrim_SetPrimitiveType(objSpell, PRIMITIVE_TRIANGLESTRIP);
		ObjPrim_SetVertexCount(objSpell, NUM_VERTEX);
		ObjRender_SetBlendType(objSpell, BLEND_ALPHA);
		Obj_SetRenderPriority(objSpell, 0.76);
		ObjPrim_SetTexture(objSpell, GetCurrentScriptDirectory() ~ "./SpellCardAttack.png");
	
		ascent (iVert in 0..NUM_VERTEX / 2)
		{
			let left = iVert * 128;
			let indexVert = iVert * 2;
			ObjPrim_SetVertexUVT(objSpell, indexVert + 0, left, 0);
			ObjPrim_SetVertexUVT(objSpell, indexVert + 1, left, 16);
		}			

		let frame = 0;
		let rRate = 1;
		let angle = 0;
	
		while(alpha>0)
		{
			angle += sp;
			VertexSize;
			ObjRender_SetPosition(objSpell, x, y, 0);
			ObjRender_SetAngleZ(objSpell, angle);
			ObjRender_SetAlpha(objSpell, alpha);
			frame++;
			yield;
		}
		Obj_Delete(objSpell);
		
		task VertexSize
		{	
			if(frame>=35){return;}
			ascent (iVert in 0..NUM_VERTEX / 2)
			{
				let indexVert = iVert * 2;
				let angle = (360 / (NUM_VERTEX / 2 - 1) * iVert);

				let vx1 = listRadius[indexVert] * cos(angle);
				let vy1 = listRadius[indexVert] * sin(angle);
				ObjPrim_SetVertexPosition(objSpell, indexVert + 0, vx1, vy1, 0);

				let vx2 = listRadius[indexVert + 1] * cos(angle);
				let vy2 = listRadius[indexVert + 1] * sin(angle);
				ObjPrim_SetVertexPosition(objSpell, indexVert + 1, vx2, vy2, 0);

				let dr = (rad * rRate - listRadius[indexVert]) / 16;
				listRadius[indexVert] = listRadius[indexVert] + dr;
				if(frame > dir)
				{
					listRadius[indexVert + 1] = listRadius[indexVert + 1] + dr;
				}
			}
		}
	}
}

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);
	Aura(obj, 192, 0, 0);
	MagicCircle(obj);

	ObjPrim_SetTexture(obj, GetCurrentScriptDirectory ~ "./EikaWBaWCSprite.png");
	ObjSprite2D_SetSourceRect(obj, 0, 0, 64, 80);
	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(type == -1)
			{
				     if(endframe >=  0 && endframe <  2)	{ObjSprite2D_SetSourceRect(obj, wi * 2, he * 1, wi * 3, he * 2); ObjRender_SetAngleXYZ(obj, 0, 180, 0);}
				else if(endframe >=  2 && endframe <  4)	{ObjSprite2D_SetSourceRect(obj, wi * 1, he * 1, wi * 2, he * 2); ObjRender_SetAngleXYZ(obj, 0, 180, 0);}
				else if(endframe >=  4 && endframe <  6)	{ObjSprite2D_SetSourceRect(obj, wi * 0, he * 1, wi * 1, he * 2); ObjRender_SetAngleXYZ(obj, 0, 180, 0);}

				     if	(endframe <   6){ endframe++; }
				else if	(endframe ==  6){ type = 0; idleframe = 0; endframe = 0;}
			}

			else if(type == -2)
			{
				     if(endframe >=  0 && endframe <  2)	{ObjSprite2D_SetSourceRect(obj, wi * 2, he * 1, wi * 3, he * 2); ObjRender_SetAngleXYZ(obj, 0, 0, 0);}
				else if(endframe >=  2 && endframe <  4)	{ObjSprite2D_SetSourceRect(obj, wi * 1, he * 1, wi * 2, he * 2); ObjRender_SetAngleXYZ(obj, 0, 0, 0);}
				else if(endframe >=  2 && endframe <  6)	{ObjSprite2D_SetSourceRect(obj, wi * 0, he * 1, wi * 1, he * 2); ObjRender_SetAngleXYZ(obj, 0, 0, 0);}

				     if	(endframe <   6){ endframe++; }
				else if	(endframe ==  6){ type = 0; idleframe = 0; endframe = 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){ castframe++; }
			else if(castframe == 63){ castframe = 0; }
		}

		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;}
			if(frame < -2 && frame >= -4)	{ObjSprite2D_SetSourceRect(obj, wi * 1, he * 1, wi * 2, he * 2); ObjRender_SetAngleXYZ(obj, 0, 180, 0);}
			if(frame < -4 && frame >= -6)	{ObjSprite2D_SetSourceRect(obj, wi * 2, he * 1, wi * 3, he * 2); ObjRender_SetAngleXYZ(obj, 0, 180, 0);}
			if(frame < -6 && frame >= -8)	{ObjSprite2D_SetSourceRect(obj, wi * 3, he * 1, wi * 4, he * 2); ObjRender_SetAngleXYZ(obj, 0, 180, 0);}
			if(frame >  0 && frame <=  2)	{ObjSprite2D_SetSourceRect(obj, wi * 0, he * 1, wi * 1, he * 2); ObjRender_SetAngleXYZ(obj, 0,   0, 0); type = -2;}
			if(frame >  2 && frame <=  4)	{ObjSprite2D_SetSourceRect(obj, wi * 1, he * 1, wi * 2, he * 2); ObjRender_SetAngleXYZ(obj, 0,   0, 0);}
			if(frame >  4 && frame <=  6)	{ObjSprite2D_SetSourceRect(obj, wi * 2, he * 1, wi * 3, he * 2); ObjRender_SetAngleXYZ(obj, 0,   0, 0);}
			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 ~ "./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 ~ "./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~"./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);
}

task Charge(objEnemy)
{
	LoadSound(GetCurrentScriptDirectory ~ "se/Charge2.wav");
	PlaySE(GetCurrentScriptDirectory ~ "se/Charge2.wav");
	ascent(i in 0..40)
	{
		Petal(20);
		if(i == 10){ Bubble(50); }
		yield;
	}

	task Petal(frame)
	{
		let objPetal = ObjPrim_Create(OBJ_SPRITE_2D);
		ObjPrim_SetTexture(objPetal, GetCurrentScriptDirectory ~ "./petal.png");
		ObjSprite2D_SetSourceRect(objPetal, 0, 0, 64, 64);
		ObjSprite2D_SetDestCenter(objPetal);
		ObjRender_SetBlendType(objPetal,BLEND_ADD_ARGB);
		ObjRender_SetColor(objPetal, 125, 20, 100);
		let s = rand(1.5, 0.5);
		let scale = s;
		let angle = rand(1, 360);
		let r = rand(50, 100);
		let rad = r;
		let a = 0.5;
		let angX = rand(-30,30);
		let angY = rand(-30,30);
		let angZ = rand(0,360);
		while(rad > 0 && !Obj_IsDeleted(objEnemy))
		{
			ObjRender_SetPosition(objPetal, ObjRender_GetX(objEnemy) + rad * cos(angle), ObjRender_GetY(objEnemy) + rad * sin(angle), 0);
			ObjRender_SetScaleXYZ(objPetal, scale, scale, scale);
			//ObjRender_SetScaleXYZ(objPetal, 0.6 - a / 100, 0.6 - a / 100, 0);
			ObjRender_SetAngleXYZ(objPetal, angX + a * 10, angY + a * 10, angZ);
			rad -= r / frame;
			scale -= s / frame;
			a += 0.2;
			yield;
		}
		Obj_Delete(objPetal);
	}

	task Bubble(frame)
	{
		let objBubble = ObjPrim_Create(OBJ_SPRITE_2D);
		ObjPrim_SetTexture(objBubble, GetCurrentScriptDirectory ~ "./bubble.png");
		ObjSprite2D_SetSourceRect(objBubble, 0, 0, 128, 128);
		ObjSprite2D_SetDestCenter(objBubble);
		ObjRender_SetBlendType(objBubble, BLEND_ADD_RGB);
		Scale;
		Color;
		task Scale
		{
			let scale = 5;
			while(scale > 0 && !Obj_IsDeleted(objEnemy))
			{
				ObjRender_SetPosition(objBubble, ObjRender_GetX(objEnemy), ObjRender_GetY(objEnemy), 0);
				ObjRender_SetScaleXYZ(objBubble, scale, scale, 0);
				scale -= 5 / frame;
				yield;
			}
			Obj_Delete(objBubble);
		}
		task Color
		{
			ascent(i in 0..(frame / 2))
			{
				ObjRender_SetColor(objBubble, i * 250 / 45, i * 40 / 45, i * 200 / 45);
				yield;
			}
			descent(i in 0..(frame / 2))
			{
				ObjRender_SetColor(objBubble, i * 250 / 45, i * 40 / 45, i * 200 / 45);
				yield;
			}
		}
	}
}

task MapleExplode{
	let px = ObjMove_GetX(objEnemy);
	let py = ObjMove_GetX(objEnemy);
	ascent(i in 0..90){
	Explode(rand(1,6),rand(0,359),rand(2,5));
	}
	task Explode(spd,dir,size){
	let obj=ObjPrim_Create(OBJ_SPRITE_2D);
	AutoDelete(objEnemy, obj);
	let img=GetCurrentScriptDirectory~"./eff.png";
	let r = 0;
	let angle = rand(0,359);
	let alpha = 255;
	let minus = 256/(size/0.03);
	ObjPrim_SetTexture(obj,img);
	ObjSprite2D_SetSourceRect(obj,32,226,64,254);
	ObjSprite2D_SetDestCenter(obj);
	ObjRender_SetScaleXYZ(obj,size,size,size);
	ObjRender_SetBlendType(obj,BLEND_ALPHA);
	ObjRender_SetAlpha(obj,255);
	while(size>0){
	ObjRender_SetPosition(obj,px+r*cos(dir),py+r*sin(dir),0);
	ObjRender_SetScaleXYZ(obj,size,size,size);
	ObjRender_SetAngleXYZ(obj,0,0,angle);
	ObjRender_SetAlpha(obj,alpha);
	alpha -= minus;
	angle += 2*size;
	r+= spd;
	spd -= 0.01;
	size -= 0.03;
	yield;
	}
	}
	}

task TExplosionA(x, y, dAlpha, dScale)
{
	let path = GetCurrentScriptDirectory() ~ "./Default_Effect.png";
	let obj = ObjPrim_Create(OBJ_SPRITE_2D);
	ObjPrim_SetTexture(obj, path);
	Obj_SetRenderPriority(obj, 0.65);
	ObjRender_SetBlendType(obj, BLEND_ADD_RGB);
	ObjSprite2D_SetSourceRect(obj, 1, 1, 63, 63);
	ObjSprite2D_SetDestCenter(obj);
	ObjRender_SetPosition(obj, x, y, 0);

	let scale = 0;
	let alpha = 255;
	while(alpha > 0)
	{
		ObjRender_SetColor(obj, alpha, alpha, alpha);
		ObjRender_SetScaleXYZ(obj, scale, scale, 1);

		scale += dScale;
		alpha -= dAlpha;
		yield;
	}
	Obj_Delete(obj);
}

task effbreak(shot,type){
	let obj=ObjPrim_Create(OBJ_SPRITE_2D);
	let img=GetCurrentScriptDirectory~"./effbreak.png";
	let s = rand(0.8,1.2);
	let color = [0,0,0];
	if(type=="RED"){color = [192,0,0];}
	if(type=="GREEN"){color = [0,192,0];}
	if(type=="BLUE"){color = [0,0,192];}
	if(type=="ORANGE"){color = [192,192,0];}
	if(type=="PURPLE"){color = [192,0,192];}
	if(type=="AQUA"){color = [0,192,192];}
	if(type=="GRAY"){color = [192,192,192];}
	let rect = [0,0,32,32];
	ObjPrim_SetTexture(obj,img);
	ObjSprite2D_SetSourceRect(obj,rect[0],rect[1],rect[2],rect[3]);
	ObjSprite2D_SetDestCenter(obj);
	ObjRender_SetScaleXYZ(obj,s,s,0);
	ObjRender_SetAngleXYZ(obj,0,0,rand(0,359));
	ObjRender_SetBlendType(obj,BLEND_ALPHA);
	ObjRender_SetColor(obj,color[0],color[1],color[2]);
	Obj_SetRenderPriority(obj,0.21);
	let x = ObjMove_GetX(shot);
	let y = ObjMove_GetY(shot);
	ascent(i in 0..7){
	ObjRender_SetPosition(obj,x,y,0);
	ObjSprite2D_SetSourceRect(obj,rect[0],rect[1],rect[2],rect[3]);
	rect[0] = rect[0]+32;
	rect[2] = rect[2]+32;
	loop(3){ yield };
	}
	Obj_Delete(obj);
	}


task AutoDelete(objEnemy, obj)
{
	while(!Obj_IsDeleted(objEnemy)){ yield; }
	Obj_Delete(obj);
}

task EnemyName		//from Spectral Nexus' Futo script
{
	let obj = ObjText_Create;
	let spin = 0; 
	
	ObjText_SetFontType(obj,"Helvetica");
	ObjText_SetText(obj, "Ebisu Eika");
	ObjText_SetFontSize(obj, 15);
	Obj_SetRenderPriorityI(obj,170);
	ObjText_SetHorizontalAlignment(obj,ALIGNMENT_CENTER);
	ObjText_SetMaxWidth(obj,68);
	ObjText_SetLinePitch(obj,0);
	ObjText_SetFontColorTop(obj, 255, 150, 150);
	ObjText_SetFontColorBottom(obj, 255, 150, 150);
	ObjText_SetFontBold(obj, true);
	ObjRender_SetPosition(obj,40,35,0);
	loop(128)
	{
		spin += 1;
		let p = 255 * sin(spin);
		ObjRender_SetAlpha(obj, p);
		yield;
	}
	AutoDelete(objEnemy, obj);
}