// Enemy Effects

task EExplosion(x, y, amount){
	let angle = rand(0,360);
	ERing(x, y, 0.09, 0.09, 0.06, 1, BLEND_ADD_ARGB, rand(50,255), rand(50,255), rand(50,255));
	loop(amount){
		let angvel = [-0.2,0.2][rand_int(0,1)];
		EParticle(x, y, rand(2,7), -0.07, angle, 0.09, 0.09, 0.002, 3, angvel, BLEND_ADD_ARGB, 0, 0, 0);
		EParticle(x, y, rand(2,7), -0.07, angle, 0.09, 0.09, 0.002, 3, angvel, BLEND_ADD_ARGB, rand(50,255), rand(50,255), rand(50,255));
		angle+=360/amount;
	}
}

task EShockwave(x, y, radius){
	ERing(x, y, 0.09, 0.09, radius, 1, BLEND_ADD_ARGB, 255, 255, 255);
}

task ECharge(x, y, amount){
	let angle = rand(0,360);
	loop(amount){
		let angvel = [-0.1,0.1][rand_int(0,1)];
		EParticle(ObjMove_GetX(objBoss)+90*cos(angle), ObjMove_GetY(objBoss)+90*sin(angle), rand(-1,-3), 0.07, angle, 0.22, 0.22, 0, 0, angvel, BLEND_ADD_ARGB, rand(0,255), rand(0,255), rand(0,255));
		angle+=360/amount;
	}
}

task EParticle(x, y, speed, acceleration, angle, scaleX, scaleY, scaleinc, radius, angvelocity, blend, colorR, colorG, colorB){
	let alInc = 255;
	let scl = 0;

	let img = GetCurrentScriptDirectory ~ "../img/EParticle.png";
	let obj = ObjPrim_Create(OBJ_SPRITE_2D);
	ObjPrim_SetTexture(obj, img);
	ObjSprite2D_SetSourceRect(obj, 0,0,256,256);
	ObjSprite2D_SetDestCenter(obj);
	Obj_SetRenderPriorityI(obj, 35);
	ObjRender_SetScaleXYZ(obj, scaleX+scl, scaleY+scl, 0);
	ObjRender_SetAlpha(obj, alInc);
	ObjRender_SetBlendType(obj, blend);
	ObjRender_SetPosition(obj, x, y, 0);
	ObjRender_SetColor(obj, colorR, colorG, colorB);

	while(alInc > 0){
		alInc-=radius;
		scl+= scaleinc;

		x+=cos(angle)*speed;
		y+=sin(angle)*speed;

		angle+=angvelocity;

		ObjRender_SetPosition(obj, x, y, 0);
		ObjRender_SetAlpha(obj, alInc);
		ObjRender_SetScaleXYZ(obj, scaleX+scl, scaleY+scl, 0);

		if(speed > 1){
			speed+=acceleration;
		}
		yield;
	}
	Obj_Delete(obj);
}

task ERing(x, y, scaleX, scaleY, scaleinc, radius, blend, colorR, colorG, colorB){
	let alInc = 100;
	let scl = 0;

	let img = GetCurrentScriptDirectory ~ "../img/ERing2.png";
	let obj = ObjPrim_Create(OBJ_SPRITE_2D);
	ObjPrim_SetTexture(obj, img);
	ObjSprite2D_SetSourceRect(obj, 0,0,256,256);
	ObjSprite2D_SetDestCenter(obj);
	Obj_SetRenderPriorityI(obj, 34);
	ObjRender_SetScaleXYZ(obj, scaleX+scl, scaleY+scl, 0);
	ObjRender_SetAlpha(obj, alInc);
	ObjRender_SetBlendType(obj, blend);
	ObjRender_SetPosition(obj, x, y, 0);
	ObjRender_SetColor(obj, colorR, colorG, colorB);

	while(alInc > 0){
		alInc-=radius;
		scl+= scaleinc;

		ObjRender_SetPosition(obj, x, y, 0);
		ObjRender_SetAlpha(obj, alInc);
		ObjRender_SetScaleXYZ(obj, scaleX+scl, scaleY+scl, 0);

		yield;
	}
	Obj_Delete(obj);
}

// Shot Effects

task EffectTrail1(shot, graphic, frame, blend){
	while(!Obj_IsDeleted(shot)){
		CreateEffTrail1(shot, graphic, blend);
		wait(frame);
	}
}

task CreateEffTrail1(shot, graphic, blend){
	let rect = GetShotDataInfoA1(graphic, TARGET_ENEMY, INFO_RECT);
	let eff = ObjPrim_Create(OBJ_SPRITE_2D);
	ObjPrim_SetTexture(eff, "./resource/shot/Shot/ZUNShot.png");
	ObjSprite2D_SetSourceRect(eff, rect[0], rect[1], rect[2], rect[3]);
	ObjSprite2D_SetDestCenter(eff);
	ObjRender_SetPosition(eff, ObjMove_GetX(shot), ObjMove_GetY(shot), 0);
	ObjRender_SetAngleZ(eff, ObjMove_GetAngle(shot)+90);
	ObjRender_SetBlendType(eff, blend);

	let alpha = 100;
	while(!Obj_IsDeleted(shot)){
		ObjRender_SetAlpha(eff, alpha);
		ObjRender_SetAngleZ(eff, ObjMove_GetAngle(shot)+90);
		alpha-=5;
		if(alpha <= 0){
			Obj_Delete(eff);
		}
		yield;
	}
	Obj_Delete(eff);
}