task MakeExplosion(type,obj,r,g,b){
	CircleExplosion(obj,r,g,b);
	ScreenShake(2);
	loop(10){
	ascent(i in 0..20){
		Explosion(type,ObjMove_GetX(obj),ObjMove_GetY(obj),i*360/20,rand(2,12),r,g,b);}
		yield;}}

task Explosion(type,xpos,ypos,angle,speed,r,g,b){
	let mx = speed*cos(angle);
	let my = speed*sin(angle);
	let alpha = 0;
	let scale = 3;
		let angleX = rand(0,360);
		let angleY = rand(0,360);
		let angleZ = rand(0,360);
		let Xrot = rand(-3,3);
		let Yrot = rand(-3,3);
		let Zrot = rand(-3,3);
		
	let obj = ObjPrim_Create(OBJ_SPRITE_2D);
	if(type=="FLOWER"){ObjPrim_SetTexture(obj,GetCurrentScriptDirectory~"./Images/flower.png");}
	if(type=="HEART"){ObjPrim_SetTexture(obj,GetCurrentScriptDirectory~"./Images/heart.png");}
	if(type=="MAGIC"){ObjPrim_SetTexture(obj,GetCurrentScriptDirectory~"./Images/magic.png");}
	if(type=="MAPLE"){ObjPrim_SetTexture(obj,GetCurrentScriptDirectory~"./Images/maple.png");}
	if(type=="NOTE"){ObjPrim_SetTexture(obj,GetCurrentScriptDirectory~"./Images/note.png");}
	if(type=="SAKURA"){ObjPrim_SetTexture(obj,GetCurrentScriptDirectory~"./Images/sakura.png");}
	if(type=="SNOW"){ObjPrim_SetTexture(obj,GetCurrentScriptDirectory~"./Images/snow.png");}
	if(type=="STAR"){ObjPrim_SetTexture(obj,GetCurrentScriptDirectory~"./Images/star.png");}
	ObjSprite2D_SetSourceRect(obj,0, 0, 64, 64);
	Obj_SetRenderPriorityI(obj,60);
	ObjRender_SetBlendType(obj,BLEND_ALPHA);
	ObjSprite2D_SetDestCenter(obj);
	ObjRender_SetPosition(obj,xpos,ypos,0);
	ObjRender_SetColor(obj,r,g,b);

        loop(60){
        	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);
		
		angleX+=Xrot;
		angleY+=Yrot;
		angleZ+=Zrot;
		alpha+=5;
		scale-=0.05;
		yield;}
	Obj_Delete(obj);}


task CircleExplosion(tobj,r,g,b){
	let alpha = 0;
	let scale = 0;
	let obj = ObjPrim_Create(OBJ_SPRITE_2D);
	ObjPrim_SetTexture(obj,GetCurrentScriptDirectory~"./Images/charge.png");
	ObjSprite2D_SetSourceRect(obj,0,0,128,128);
	ObjSprite2D_SetDestCenter(obj);
	ObjRender_SetPosition(obj,ObjRender_GetX(tobj),ObjRender_GetY(tobj),0);
	ObjRender_SetBlendType(obj,BLEND_ALPHA);
	ObjRender_SetAlpha(obj,150);
	Obj_SetRenderPriorityI(obj,40);
	ObjRender_SetColor(obj,r,g,b);
		loop(64){
			ObjRender_SetAlpha(obj,alpha);
			ObjRender_SetScaleXYZ(obj,scale,scale,0);
			scale+=0.2;
			alpha+=2;
			yield;}
		loop(64){
			ObjRender_SetAlpha(obj,alpha);
			ObjRender_SetScaleXYZ(obj,scale,scale,0);
			scale+=0.2;
			alpha-=2;
			yield;}
		Obj_Delete(obj);}


task MakeConcentration(type,concobj,r,g,b,frames){
	let dir = 0;
	CircleCharge(concobj,r,g,b,frames);
	loop(frames){
		Charge(type,ObjMove_GetX(concobj)+cos(dir)*300,ObjMove_GetY(concobj)+sin(dir)*300,dir,-4,r,g,b);
		dir+=rand(10,50);
	yield;}}

task Charge(type,xpos,ypos,angle,speed,r,g,b){
	let mx = speed*cos(angle);
	let my = speed*sin(angle);
	let scale = 0.02;
	let alpha = 150;
	let obj = ObjPrim_Create(OBJ_SPRITE_2D);
	if(type=="FLOWER"){ObjPrim_SetTexture(obj,GetCurrentScriptDirectory~"./Images/flower.png");}
	if(type=="HEART"){ObjPrim_SetTexture(obj,GetCurrentScriptDirectory~"./Images/heart.png");}
	if(type=="MAGIC"){ObjPrim_SetTexture(obj,GetCurrentScriptDirectory~"./Images/magic.png");}
	if(type=="MAPLE"){ObjPrim_SetTexture(obj,GetCurrentScriptDirectory~"./Images/maple.png");}
	if(type=="NOTE"){ObjPrim_SetTexture(obj,GetCurrentScriptDirectory~"./Images/note.png");}
	if(type=="SAKURA"){ObjPrim_SetTexture(obj,GetCurrentScriptDirectory~"./Images/sakura.png");}
	if(type=="SNOW"){ObjPrim_SetTexture(obj,GetCurrentScriptDirectory~"./Images/snow.png");}
	if(type=="STAR"){ObjPrim_SetTexture(obj,GetCurrentScriptDirectory~"./Images/star.png");}
	ObjSprite2D_SetSourceRect(obj,0,0,64,64);
	ObjSprite2D_SetDestCenter(obj);
	ObjRender_SetAngleZ(obj,rand(0,360));
	ObjRender_SetPosition(obj,xpos,ypos,0);
	ObjRender_SetBlendType(obj,BLEND_ALPHA);
	ObjRender_SetAlpha(obj,150);
	Obj_SetRenderPriorityI(obj,40);
	ObjRender_SetColor(obj,r,g,b);

	loop(75){
		ObjRender_SetAlpha(obj,alpha);
		ObjRender_SetScaleXYZ(obj,scale,scale,scale);
		ObjRender_SetPosition(obj,ObjRender_GetX(obj)+mx,ObjRender_GetY(obj)+my,0);
		
		scale+=0.02;
		alpha-=1.5;
		yield;}
	Obj_Delete(obj);}

task CircleCharge(tobj,r,g,b,time){
	let alpha = 0;
	let scale = 0;
	let obj = ObjPrim_Create(OBJ_SPRITE_2D);
	ObjPrim_SetTexture(obj,GetCurrentScriptDirectory~"./Images/charge.png");
	ObjSprite2D_SetSourceRect(obj,0,0,128,128);
	ObjSprite2D_SetDestCenter(obj);
	ObjRender_SetPosition(obj,ObjMove_GetX(tobj),ObjMove_GetY(tobj),0);
	ObjRender_SetBlendType(obj,BLEND_ALPHA);
	ObjRender_SetAlpha(obj,150);
	Obj_SetRenderPriorityI(obj,40);
	ObjRender_SetColor(obj,r,g,b);
		loop(time+60){
			ObjRender_SetAlpha(obj,alpha);
			ObjRender_SetScaleXYZ(obj,3-scale,3-scale,0);
		scale+=3/(time+60);
		alpha+=120/(time+80);
		yield;}
		Obj_Delete(obj);}

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