let imgmaple = GetCurrentScriptDirectory ~ "maple.png";
LoadGraphic(imgmaple);

task DIE
{
	yield;
	PlaySE(GetCurrentScriptDirectory~"BossExplose.wav");
	loop(10)
	{
	DeathParticle;
	loop(5){yield;}
	}
	loop(10)
	{
	loop(8)
	{
	DeathParticle;
	}
	yield;
	}
	loop(120){ yield; }
	VanishEnemy;

	task DeathParticle
	{
	let obj=Obj_Create(OBJ_EFFECT);
	ObjEffect_SetTexture(obj, imgmaple);
	Obj_SetPosition(obj, GetX, GetY);
	ObjEffect_SetLayer(obj, 6);
	ObjEffect_SetPrimitiveType(obj, PRIMITIVE_TRIANGLESTRIP);
	ObjEffect_CreateVertex(obj, 4);
	ObjEffect_SetVertexUV(obj, 0, 0, 0);
	ObjEffect_SetVertexUV(obj, 1, 32, 0);
	ObjEffect_SetVertexUV(obj, 2, 0, 32);
	ObjEffect_SetVertexUV(obj, 3, 32, 32);
	ObjEffect_SetVertexXY(obj, 0, -16, -16);
	ObjEffect_SetVertexXY(obj, 1, 16, -16);
	ObjEffect_SetVertexXY(obj, 2, -16, 16);
	ObjEffect_SetVertexXY(obj, 3, 16, 16);
	ObjEffect_SetRenderState(obj, ADD);
	let speed = rand(2, 6);
	let angle = rand(0, 360);
	let scale = rand(3, 5);
	let rotate = rand(0, 360);
	let rotatespeed = rand(-3, 3);
	let alpha = 255;
	descent(i in 0..120)
	{
	if(i > 100)
	{
	ascent(j in 0..4){ObjEffect_SetVertexColor(obj, j, alpha, 255/20*(120-i), 255/20*(120-i), 255/20*(120-i));}
	}
	Obj_SetPosition(obj, Obj_GetX(obj)+cos(angle)*speed, Obj_GetY(obj)+sin(angle)*speed);
	ObjEffect_SetAngle(obj, 0, 0, rotate);
	ObjEffect_SetScale(obj, scale, scale);
	if(i<40){alpha-=255/40;}
	if(i < 20)
	{
	ascent(j in 0..4){ObjEffect_SetVertexColor(obj, j, alpha, 255/20*(120-i), 255/20*(120-i), 255/20*(120-i));}
	}
	rotate += rotatespeed;
	yield;
	}
	}
}