task Charge(objEnemy)
{
	SEPlay("Charge2", 80);
	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 ~ "../img/petal.png");
		ObjSprite2D_SetSourceRect(objPetal, 0, 0, 64, 64);
		ObjSprite2D_SetDestCenter(objPetal);
		ObjRender_SetBlendType(objPetal,BLEND_ADD_ARGB);
		ObjRender_SetColor(objPetal, 125, 125, 125);
		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 ~ "../img/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 * 40 / 45);
				yield;
			}
			descent(i in 0..(frame / 2))
			{
				ObjRender_SetColor(objBubble, i * 250 / 45, i * 40 / 45, i * 40 / 45);
				yield;
			}
		}
	}
}

task Explosion(ex, ey)
{
	loop(90)
	{
		Explode(rand(1,6),rand(0,359),rand(1,2));
	}
	task Explode(sp, ang, scale)
	{
		let objExplode = ObjPrim_Create(OBJ_SPRITE_2D);

		ObjPrim_SetTexture(objExplode, GetCurrentScriptDirectory ~ "../img/petal.png");
		ObjSprite2D_SetSourceRect(objExplode, 0, 0, 64, 64);
		ObjSprite2D_SetDestCenter(objExplode);
		ObjRender_SetScaleXYZ(objExplode, scale, scale, scale);
		ObjRender_SetBlendType(objExplode, BLEND_ALPHA);

		let rad = 0;
		let angle = rand(1, 360);
		let alpha = 255;
		let d = 256 / (scale / 0.003);

		while(scale > 0)
		{
			ObjRender_SetPosition(objExplode, ex + rad * cos(ang),ey + rad * sin(ang),0);
			ObjRender_SetScaleXYZ(objExplode, scale, scale, scale);
			ObjRender_SetAngleXYZ(objExplode, 0, 0, angle);
			ObjRender_SetAlpha(objExplode, alpha);
			alpha -= d;
			angle += 2 * scale;
			rad += sp;
			sp -= 0.01;
			scale -= 0.03;
			yield;
		}
		Obj_Delete(objExplode);
	}
}

task ExplosionCircle(x, y, dAlpha, dScale)
{
	let path = GetCurrentScriptDirectory() ~ "../img/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 Target(x, y, objEnemy)
{
	let obj = ObjPrim_Create(OBJ_SPRITE_2D);
	ObjPrim_SetTexture(obj, GetCurrentScriptDirectory() ~ "../img/heartcircle.png");
	ObjRender_SetBlendType(obj, BLEND_ADD_RGB);
	ObjRender_SetColor(obj, 255, 63, 192);
	Obj_SetRenderPriority(obj, 0.65);
	ObjSprite2D_SetSourceRect(obj, 0, 0, 256, 256);
	ObjSprite2D_SetDestCenter(obj);
	ObjRender_SetPosition(obj, x, y, 0);

	let scale = 0;
	let alpha = 255;
	while(alpha > 0)
	{
		AutoDelete(objEnemy, obj);
		ObjRender_SetAlpha(obj, alpha);
		ObjRender_SetScaleXYZ(obj, scale, scale, scale);

		scale += 0.03;
		if(alpha < 100){ ObjRender_SetBlendType(obj, BLEND_ADD_ARGB); }
		alpha -= 6;
		yield;
	}
	Obj_Delete(obj);
}