task Concentrate(x, y, angl, num, spd, scale, type, rad, ang, color){
	ascent(i in 0..num){
	Effect(x, y, angl+i*360/num, spd, scale, type, rad, ang, color);
	}
}

task Particle(tar, spd, ang, scale, anglesprite, type, color, negate){
let obj = ObjPrim_Create(OBJ_SPRITE_2D);

let tex = GetCurrentScriptDirectory ~ "img/Effects/" ~ type ~ ".png";

let x = ObjMove_GetX(tar);
let y = ObjMove_GetY(tar);

let alpha = 255;
let count = 0;

	ObjPrim_SetTexture(obj, tex);
	Obj_SetRenderPriorityI(obj, 50);
	ObjSprite2D_SetSourceRect(obj,0,0,GetTextureWidth(tex),GetTextureHeight(tex));
	ObjSprite2D_SetDestCenter(obj);	
	ObjRender_SetScaleXYZ(obj,scale,scale,0);
	ObjRender_SetAngleXYZ(obj,0,0,rand(0,360));
	ObjRender_SetBlendType(obj, BLEND_ADD_ARGB);
	ObjRender_SetColor(obj, color[0], color[1], color[2]);
	ObjRender_SetAlpha(obj, alpha);
	ObjRender_SetPosition(obj, x, y, 0);
	
	loop{
	ObjRender_SetPosition(obj, x+count*cos(ang), y+count*sin(ang), 0);
	ObjRender_SetAlpha(obj, alpha);
	ObjRender_SetAngleZ(obj, anglesprite);
	count+=spd;
	alpha-=negate;
	if(alpha<1){Obj_Delete(obj); break;}
	yield;
	}

}

task ParticleT(x, y, spd, ang, scale, anglesprite, type, color, negate){
let obj = ObjPrim_Create(OBJ_SPRITE_2D);

let tex = GetCurrentScriptDirectory ~ "img/Effects/" ~ type ~ ".png";

let alpha = 255;
let count = 0;

	ObjPrim_SetTexture(obj, tex);
	Obj_SetRenderPriorityI(obj, 50);
	ObjSprite2D_SetSourceRect(obj,0,0,GetTextureWidth(tex),GetTextureHeight(tex));
	ObjSprite2D_SetDestCenter(obj);	
	ObjRender_SetScaleXYZ(obj,scale,scale,0);
	ObjRender_SetAngleXYZ(obj,0,0,rand(0,360));
	ObjRender_SetBlendType(obj, BLEND_ADD_ARGB);
	ObjRender_SetColor(obj, color[0], color[1], color[2]);
	ObjRender_SetAlpha(obj, alpha);
	ObjRender_SetPosition(obj, x, y, 0);
	
	loop{
	ObjRender_SetPosition(obj, x+count*cos(ang), y+count*sin(ang), 0);
	ObjRender_SetAlpha(obj, alpha);
	ObjRender_SetAngleZ(obj, anglesprite);
	count+=spd;
	alpha-=negate;
	if(alpha<1){Obj_Delete(obj); break;}
	yield;
	}

}

task Effect(x, y, num, spd, scale, type, rad, ang, color){
let obj = ObjPrim_Create(OBJ_SPRITE_2D);

let ghost = ObjEnemy_Create(OBJ_ENEMY);
ObjEnemy_Regist(ghost);


let tex = GetCurrentScriptDirectory ~ "img/Effects/" ~ type ~ ".png";
let random = rand(-2, 2);


	ObjPrim_SetTexture(obj, tex);
	Obj_SetRenderPriorityI(obj, 50);
	ObjSprite2D_SetSourceRect(obj,0,0,GetTextureWidth(tex),GetTextureHeight(tex));
	ObjSprite2D_SetDestCenter(obj);	
	ObjRender_SetScaleXYZ(obj,scale,scale,0);
	ObjRender_SetAngleXYZ(obj,0,0,rand(0,360));
	ObjRender_SetBlendType(obj, BLEND_ADD_ARGB);
	ObjRender_SetColor(obj, color[0], color[1], color[2]);
	ObjRender_SetAlpha(obj, 0);
	ObjRender_SetPosition(obj, x+rad*cos(num), y+rad*sin(num), 0);
	ObjMove_SetPosition(ghost, x,y);
	
	AlphaController(obj, spd);
	MoveEffect(obj, x,y, ghost,  num, spd, rad, random, scale, ang);
}

task AlphaController(obj, spd){
let alpha = 0;
	ascent(i in 0..10*spd){
	ObjRender_SetAlpha(obj, alpha);
	alpha+=i*10;
	yield;
	}
}

task MoveEffect(obj,x,y, tar, num, spd, rad, random, scale, ang){
let angle = ObjRender_GetAngleZ(obj);
let rotate = 0;
	while(!Obj_IsDeleted(obj)){
	let dist = GetObjectDistance(obj, tar);
	ObjRender_SetPosition(obj, x+rad*cos(num), y+rad*sin(num), 0);
	ObjRender_SetAngleZ(obj, angle+rotate);
	ObjRender_SetScaleXYZ(obj, scale, scale, 1);
	scale -= 0.0075/spd;
	rotate+=random;
	num+=ang;
	rad-=spd;
	if(rad <= 1 || scale <= 0){break;}
	yield;
	}
	Obj_Delete(obj);
}

task ExplodeCircleT(X, Y, num, nums, ssca){
let obj = ObjPrim_Create(OBJ_SPRITE_2D);
let scale = ssca;
let alpha = 255;

	Obj_SetRenderPriorityI(obj,22);
	ObjPrim_SetTexture(obj,GetCurrentScriptDirectory ~ "/img/deathcircle.png");
	ObjSprite2D_SetSourceRect(obj,0,0,64,64);
	ObjSprite2D_SetDestCenter(obj);
	ObjRender_SetScaleXYZ(obj, scale, scale, scale);
	ObjRender_SetBlendType(obj,BLEND_ADD_ARGB);
	ObjRender_SetPosition(obj, X, Y, 0);
	
	ascent(i in 0..num){
	ObjRender_SetScaleXYZ(obj, scale, scale, scale);
	ObjRender_SetAlpha(obj, alpha);
	ObjRender_SetAngleZ(obj, i*5);
	alpha-=255/num;
	scale+=0.01*nums;
	yield;
	}
	Obj_Delete(obj);
}

task ScreenShake(duration,range) {
let shake = range;
	loop(duration) {
		Set2DCameraFocusX(Get2DCameraX + rand(-shake, shake));
		Set2DCameraFocusY(Get2DCameraY + rand(-shake, shake));
		shake-=range/duration;
		yield;
		Reset2DCamera;
	}
}

task Aura(obj, color){
loop{
Particle(obj, rand(1, 2), rand(0,360), 0.5, rand(0,360), "Maple", color, 10);
wait(5);
}
}