let gcsd = GetCurrentScriptDirectory;
let flower = gcsd ~ "./img/effects/flower.png";
let heart = gcsd ~ "./img/effects/heart.png";
let magic = gcsd ~ "./img/effects/magic.png";
let maple = gcsd ~ "./img/effects/maple.png";
let note = gcsd ~ "./img/effects/note.png";
let sakura = gcsd ~ "./img/effects/sakura.png";
let snow = gcsd ~ "./img/effects/snow.png";
let star = gcsd ~ "./img/effects/star.png";
let moon = gcsd ~ "./img/effects/moon.png";
let cogwheel = gcsd ~ "./img/effects/cogwheel.png";
let ban = gcsd ~ "./img/effects/ban.png";
let circle = gcsd ~ "./img/effects/circle.png";
let pentagon = gcsd ~ "./img/effects/pentagon.png";
let hexagon = gcsd ~ "./img/effects/hexagon.png";

let charge = gcsd ~ "./img/effects/charge.png";

task MakeExplosionA1(obj,type,r,g,b){
	CircleExplosion(ObjRender_GetX(obj),ObjRender_GetY(obj),r,g,b);
	ScreenShake(2);
	loop(5){
		ascent(i in 0..15){
			Explosion(type,ObjMove_GetX(obj),ObjMove_GetY(obj),rand(0,180)*2,rand(4,10),r,g,b);
		}
	yield;
	}
}

task MakeExplosionA2(x,y,type,r,g,b){
	CircleExplosion(x,y,r,g,b);
	ScreenShake(2);
	loop(5){
		ascent(i in 0..15){
			Explosion(type,x,y,rand(0,180)*2,rand(3,10),r,g,b);
		}
	yield;
	}
}

task Explosion(type,xpos,ypos,angle,speed,r,g,b){
	let a = 0;
	let xangle = cos(angle);
	let yangle = sin(angle);
	let alpha = 0;
	let scale = 3;
	let angleX = rand(0,60);
	let angleY = rand(0,60);
	let angleZ = rand(0,60);
	let Xrot = rand(-2,2);
	let Yrot = rand(-2,2);
	let Zrot = rand(-2,2);
		
	let obj = ObjPrim_Create(OBJ_SPRITE_2D);
	if(type=="FLOWER"){ObjPrim_SetTexture(obj,flower);}
	if(type=="HEART"){ObjPrim_SetTexture(obj,heart);}
	if(type=="MAGIC"){ObjPrim_SetTexture(obj,magic);}
	if(type=="MAPLE"){ObjPrim_SetTexture(obj,maple);}
	if(type=="NOTE"){ObjPrim_SetTexture(obj,note);}
	if(type=="SAKURA"){ObjPrim_SetTexture(obj,sakura);}
	if(type=="SNOW"){ObjPrim_SetTexture(obj,snow);}
	if(type=="STAR"){ObjPrim_SetTexture(obj,star);}
	if(type=="MOON"){ObjPrim_SetTexture(obj,moon);}
	if(type=="COGWHEEL"){ObjPrim_SetTexture(obj,cogwheel);}
	if(type=="BAN"){ObjPrim_SetTexture(obj,ban);}
	if(type=="CIRCLE"){ObjPrim_SetTexture(obj,circle);}
	if(type=="PENTAGON"){ObjPrim_SetTexture(obj,pentagon);}
	if(type=="HEXAGON"){ObjPrim_SetTexture(obj,hexagon);}
	ObjSprite2D_SetSourceRect(obj,0, 0, 64, 64);
	Obj_SetRenderPriorityI(obj,41);
	ObjRender_SetBlendType(obj,BLEND_ADD_ARGB);
	ObjSprite2D_SetDestCenter(obj);
	ObjRender_SetPosition(obj,xpos,ypos,0);
	ObjRender_SetColor(obj,r,g,b);
	loop(80){
		if(GetCommonData("EFFECT",0) == 1){break;}
		let mx = (speed+a)*xangle;
		let my = (speed+a)*yangle;
		ObjRender_SetAlpha(obj,alpha);
		ObjRender_SetScaleXYZ(obj,scale,scale,scale);
		ObjRender_SetAngleXYZ(obj,angleX,angleY,angleZ);
		ObjRender_SetPosition(obj,ObjRender_GetX(obj)+mx,ObjRender_GetY(obj)+my,0);

		a-=0.06;
		angleX+=Xrot;
		angleY+=Yrot;
		angleZ+=Zrot;
		alpha+=3;
		scale-=0.04;
		yield;}
	Obj_Delete(obj);
	return;}


task CircleExplosion(x,y,r,g,b){
	let alpha = 0;
	let scale = 0;
	let obj = ObjPrim_Create(OBJ_SPRITE_2D);
	ObjPrim_SetTexture(obj,charge);
	ObjSprite2D_SetSourceRect(obj,0,0,128,128);
	ObjSprite2D_SetDestCenter(obj);
	ObjRender_SetPosition(obj,x,y,0);
	ObjRender_SetBlendType(obj,BLEND_ALPHA);
	ObjRender_SetAlpha(obj,150);
	Obj_SetRenderPriorityI(obj,40);
	ObjRender_SetColor(obj,r,g,b);
		loop(64){
			if(GetCommonData("EFFECT",0) == 1){break;}
			ObjRender_SetAlpha(obj,alpha);
			ObjRender_SetScaleXYZ(obj,scale,scale,0);
			scale+=0.2;
			alpha+=2;
			yield;
		}
		loop(64){
			if(GetCommonData("EFFECT",0) == 1){break;}
			ObjRender_SetAlpha(obj,alpha);
			ObjRender_SetScaleXYZ(obj,scale,scale,0);
			scale+=0.2;
			alpha-=2;
			yield;
		}
		Obj_Delete(obj);
	return;
}

task MakeConcentrationA1(obj,type,rc,gc,bc,frames){
	let dir = rand(0,180)*2;let move = 0;
	CircleCharge(ObjRender_GetX(obj),ObjRender_GetY(obj),rc,gc,bc,frames);
	loop(frames){
		loop(2){
			let r = 200 + rand(-50,50);
			Charge(type,ObjRender_GetX(obj)+200*cos(dir+move),ObjRender_GetY(obj)+200*sin(dir+move),
							dir+move,-5,rc,gc,bc,0.02,0.04,60,false);
			dir+=360/5;
		}
	move+=rand(0,80);
	yield;
	}
}

task MakeConcentrationA2(x,y,type,r,g,b,frames){
	let dir = rand(0,180)*2;let move = 0;
	CircleCharge(x,y,r,g,b,frames);
	loop(frames){
		loop(2){
			let r = 200 + rand(-50,50);
			Charge(type,x+280*cos(dir+move),y+280*sin(dir+move),dir+move,-6,r,g,b,0.02,0.04,60,false);
			dir+=360/5;
		}
	move+=rand(0,80);
	yield;
	}
}

task MakeConcentrationB1(obj,type,r,g,b,frames){
	let dir = 0;
	CircleCharge(ObjRender_GetX(obj),ObjRender_GetY(obj),r,g,b,frames);
	loop(frames-50){
		Charge(type,ObjRender_GetX(obj)+280*cos(dir),ObjRender_GetY(obj)+280*sin(dir),
							dir,-4,r,g,b,3,-0.04,45,true);
		dir+=rand(1,20)*5;
	yield;
	}
}

task MakeConcentrationB2(x,y,type,r,g,b,frames){
	let dir = 0;
	CircleCharge(x,y,r,g,b,frames);
	loop(frames-50){
		Charge(type,x+250*cos(dir),y+250*sin(dir),dir,-6,r,g,b,3,-0.04,45,true);
		dir+=rand(1,20)*5;
	yield;
	}
}

task Charge(type,xpos,ypos,angle,speed,r,g,b,min,max,time,nTime){
	let scale = 0.5;
	let alpha = 0;
	let xangle = cos(angle);
	let yangle = sin(angle);
	let a = 0;
	let obj = ObjPrim_Create(OBJ_SPRITE_2D);
	if(type=="FLOWER"){ObjPrim_SetTexture(obj,flower);}
	if(type=="HEART"){ObjPrim_SetTexture(obj,heart);}
	if(type=="MAGIC"){ObjPrim_SetTexture(obj,magic);}
	if(type=="MAPLE"){ObjPrim_SetTexture(obj,maple);}
	if(type=="NOTE"){ObjPrim_SetTexture(obj,note);}
	if(type=="SAKURA"){ObjPrim_SetTexture(obj,sakura);}
	if(type=="SNOW"){ObjPrim_SetTexture(obj,snow);}
	if(type=="STAR"){ObjPrim_SetTexture(obj,star);}
	if(type=="MOON"){ObjPrim_SetTexture(obj,moon);}
	if(type=="COGWHEEL"){ObjPrim_SetTexture(obj,cogwheel);}
	if(type=="BAN"){ObjPrim_SetTexture(obj,ban);}
	if(type=="CIRCLE"){ObjPrim_SetTexture(obj,circle);}
	if(type=="PENTAGON"){ObjPrim_SetTexture(obj,pentagon);}
	if(type=="HEXAGON"){ObjPrim_SetTexture(obj,hexagon);}
	ObjSprite2D_SetSourceRect(obj,0,0,64,64);
	ObjSprite2D_SetDestCenter(obj);
	ObjRender_SetAngleZ(obj,rand(0,20)*18);
	ObjRender_SetPosition(obj,xpos,ypos,0);
	ObjRender_SetBlendType(obj,BLEND_ADD_ARGB);
	Obj_SetRenderPriorityI(obj,41);
	ObjRender_SetColor(obj,r,g,b);

	loop(10){
		if(GetCommonData("EFFECT",0) == 1){break;}
		let mx = (-0.5)*xangle;
		let my = (-0.5)*yangle;
		ObjRender_SetAlpha(obj,alpha);
		ObjRender_SetScaleXYZ(obj,scale,scale,scale);
		ObjRender_SetAngleZ(obj, ObjRender_GetAngleZ(obj) + 1);
		ObjRender_SetPosition(obj,ObjRender_GetX(obj)+mx,ObjRender_GetY(obj)+my,0);
		scale+=0.04;
		alpha+=200/10;
		yield;
	}
	loop(45){
		if(GetCommonData("EFFECT",0) == 1){break;}
		let mx = (-0.5-a)*xangle;
		let my = (-0.5-a)*yangle;
		ObjRender_SetScaleXYZ(obj,scale,scale,scale);
		ObjRender_SetAngleZ(obj, ObjRender_GetAngleZ(obj) + 1.2);
		ObjRender_SetPosition(obj,ObjRender_GetX(obj)+mx,ObjRender_GetY(obj)+my,0);
		scale-=0.01;
		a+=0.1;
		yield;
	}
	loop(15){
		if(GetCommonData("EFFECT",0) == 1){break;}
		let mx = (-5)*xangle;
		let my = (-5)*yangle;
		ObjRender_SetAlpha(obj, alpha);
		ObjRender_SetPosition(obj,ObjRender_GetX(obj)+mx,ObjRender_GetY(obj)+my,0);
		alpha-=200/15;
		yield;
	}
	Obj_Delete(obj);
	return;
}

task CircleCharge(x,y,r,g,b,time){
	let alpha = 120;
	let scale = 0;
	let obj = ObjPrim_Create(OBJ_SPRITE_2D);
	ObjPrim_SetTexture(obj,charge);
	ObjSprite2D_SetSourceRect(obj,0,0,128,128);
	ObjSprite2D_SetDestCenter(obj);
	ObjRender_SetPosition(obj,x,y,0);
	ObjRender_SetBlendType(obj,BLEND_ALPHA);
	ObjRender_SetAlpha(obj,150);
	Obj_SetRenderPriorityI(obj,40);
	ObjRender_SetColor(obj,r,g,b);
		loop(time*2){
			if(GetCommonData("EFFECT",0) == 1){break;}
			ObjRender_SetAlpha(obj,alpha);
			ObjRender_SetScaleXYZ(obj,7-scale,7-scale,0);
			scale+=2.8/time;
			alpha-=40/time;
			yield;
		}
	Obj_Delete(obj);
	return;
}

task ScreenShake(time){
	let shakeamount = 4;
	let delay = 1;
	
	loop(time){
	Set2DCameraFocusX(GetStgFrameWidth/2+shakeamount);
	Set2DCameraFocusY(GetStgFrameHeight/2+shakeamount);
	loop(delay){yield;}
	Set2DCameraFocusX(GetStgFrameWidth/2-shakeamount);
	Set2DCameraFocusY(GetStgFrameHeight/2-shakeamount);
	loop(delay){yield;}
	Set2DCameraFocusX(GetStgFrameWidth/2+shakeamount);
	Set2DCameraFocusY(GetStgFrameHeight/2-shakeamount);
	loop(delay){yield;}
	Set2DCameraFocusX(GetStgFrameWidth/2-shakeamount);
	Set2DCameraFocusY(GetStgFrameHeight/2+shakeamount);
	loop(delay){yield;}}
	
	Set2DCameraFocusX(GetStgFrameWidth/2);
	Set2DCameraFocusY(GetStgFrameHeight/2);
}