/////////////////////////////////////////////////////////////////////////////
function CR(color){
	let a;
	
	if(color == "red"){a = [255,63,63];}
	if(color == "orange"){a = [255,127,63];}
	if(color == "yellow"){a = [255,255,127];}
	if(color == "green"){a = [127,255,127];}
	if(color == "blue"){a = [63,63,255];}
	if(color == "cian"){a = [127,127,255];}
	if(color == "purple"){a = [255,63,255];}
	if(color == "rainbow"){a = [[255,63,63],[255,127,63],[255,255,127],[127,255,127],[63,63,255],[127,127,255],[255,63,255]][floor(rand(0,6.99))];}
	if(color == "white"){a = [255,255,255];}
	if(color == "black"){a = [0,0,0];}	
	
	return a;
}
//////////////////////////////////////////////////////////////////////////
task TCharge1(x,y,color,r,type,del,ang2){
	let path = GetMainStgScriptDirectory ~ "img/effect/rest/" ~ type ~ ".png";
	let obj = ObjPrim_Create(OBJ_SPRITE_2D);
	let loc = 90;
	let alpha = 0;
	let ang = rand(0,360);
	let xa = rand(-50,50);
	let ya = rand(-50,50);
	
	ObjPrim_SetTexture(obj, path);
	Obj_SetRenderPriority(obj, 0.75);
	ObjRender_SetBlendType(obj, BLEND_ADD_ARGB);
	ObjSprite2D_SetSourceRect(obj, 0, 0, 256, 256);
	ObjSprite2D_SetDestCenter(obj);
	ObjRender_SetColor(obj, color[0], color[1], color[2]);
	
	ObjRender_SetScaleXYZ(obj,1/128*r/3,1/128*r/3,0);
	ObjRender_SetAngleXYZ(obj, xa, ya, ang);
	
	while(loc > 0){
		if(loc > 50){alpha = min(alpha+255/(del/90*40),255)}
		else{alpha = max(alpha-255/(del/90*50),0);}
		
		ObjRender_SetAlpha(obj, alpha);
		ObjRender_SetPosition(obj,x+r*sin(loc)*cos(ang2+loc/90*60),y+r*sin(loc)*sin(ang2+loc/90*60),0);
		ObjRender_SetAngleXYZ(obj, xa, ya, ang);
		
		loc-= 90/del;
		
		yield;
	}
	
	Obj_Delete(obj);
}

task TCharge2(x, y, color, r){
	let path = GetMainStgScriptDirectory ~ "img/effect/charge_wave.png";
	let obj = ObjPrim_Create(OBJ_SPRITE_2D);
	let dScale = 90;
	
	ObjPrim_SetTexture(obj, path);
	Obj_SetRenderPriority(obj, 0.65);
	ObjRender_SetBlendType(obj, BLEND_ADD_ARGB);
	ObjSprite2D_SetSourceRect(obj, 0, 0, 128, 128);
	ObjSprite2D_SetDestCenter(obj);
	ObjRender_SetPosition(obj, x, y, 0);
	ObjRender_SetAlpha(obj,128);
	ObjRender_SetColor(obj, color[0], color[1], color[2]);

	let scale = 90;
	while(scale > 0)
	{
		ObjRender_SetScaleXYZ(obj, scale, scale, 1);

		scale = r/64*sin(dScale);
		dScale-= 90/35;
		yield;
	}
	Obj_Delete(obj);
}

task TChargeA1( x, y, color, type){//w = 75
	
	loop(10){
		ascent(a in 0..3){TCharge1(x,y,color,200,type,30,rand(-30,30)+a*360/3+60);}
		yield;
	}

	_PlaySE(14);
	
	loop(30){
		ascent(a in 0..3){TCharge1(x,y,color,200,type,30,rand(-30,30)+a*360/3+60);}
		yield;
	}
	
	TCharge2(x, y, color, 250);
}

/////////////////////////////////////////////////////////////////////////////
task TExplosion1(x, y, color, let r2, xa, ya){
	let path = GetMainStgScriptDirectory ~ "img/bg/fog.png";
	let obj = ObjPrim_Create(OBJ_PRIMITIVE_2D);
	let dAlpha = 255/35;
	let dScale = 0;
	
	ObjPrim_SetPrimitiveType(obj, PRIMITIVE_LINESTRIP);
	ObjPrim_SetTexture(obj, path);
	ObjPrim_SetVertexCount(obj,16);
	Obj_SetRenderPriority(obj, 0.65);
	ObjRender_SetBlendType(obj, BLEND_ADD_RGB);
	ObjRender_SetPosition(obj, x, y, 0);

	let scale = 0;
	let alpha = 255;
	r2 = r2/2;
	let r = 0;
	while(alpha > 0)
	{
		ObjRender_SetColor(obj, alpha*(color[0]/255), alpha*(color[1]/255), alpha*(color[2]/255));

		ascent(i in 0..16){
		    ObjPrim_SetVertexPosition(obj, i+0, r*cos(i*360/15), r*sin(i*360/15), 0);

		    ObjPrim_SetVertexUVT(obj, i+0, 0, 0);
		}

		r = r2*sin(dScale);
		dScale+= 90/35;
		alpha -= dAlpha;
		yield;
	}
	Obj_Delete(obj);
}

task TExplosion2(x,y,color,r,type,del,scaler){
	let path = GetMainStgScriptDirectory ~ "img/effect/rest/" ~ type ~ ".png";
	let obj = ObjPrim_Create(OBJ_SPRITE_2D);
	let loc = 0;
	let alpha = 0;
	let ang = rand(0,360);
	let xa = rand(-50,50);
	let ya = rand(-50,50);
	let ang2 = rand(0,360);
	
	ObjPrim_SetTexture(obj, path);
	Obj_SetRenderPriority(obj, 0.75);
	ObjRender_SetBlendType(obj, BLEND_ADD_ARGB);
	ObjSprite2D_SetSourceRect(obj, 0, 0, 256, 256);
	ObjSprite2D_SetDestCenter(obj);
	
	ObjRender_SetScaleXYZ(obj,1/2*scaler,1/2*scaler,0);
	ObjRender_SetAngleXYZ(obj, xa, ya, ang);
	
	while(loc < 90){
		if(loc < 40){alpha = min(alpha+255/40,255)}
		else{alpha = max(alpha-255/50,0);}
		
		ObjRender_SetColor(obj, alpha*(color[0]/255), alpha*(color[1]/255), alpha*(color[2]/255));
		ObjRender_SetPosition(obj,x+r*sin(loc)*cos(ang2),y+r*sin(loc)*sin(ang2),0);
		ObjRender_SetAngleXYZ(obj, xa, ya, ang+loc);
		
		loc+= 90/del;
		
		yield;
	}
	
	Obj_Delete(obj);
}

task NegativeEx( x, y, t, d){
	let obj = ObjPrim_Create(OBJ_SPRITE_2D);
	ObjRender_SetBlendType(obj, BLEND_INV_DESTRGB);
	Obj_SetRenderPriorityI(obj, 70);
	ObjPrim_SetTexture(obj, GetMainStgScriptDirectory ~ "img/effect/invcircle.png");
	ObjSprite2D_SetSourceRect(obj, 0, 0, 256, 256);
	ObjSprite2D_SetDestCenter(obj);

	ObjRender_SetScaleXYZ(obj, 0, 0, 0);
	ObjRender_SetPosition(obj, x, y, 0);

	let s = 0;
	while(s < 5){
		ObjRender_SetScaleXYZ(obj, s, s, 0);
		s += 5/t;
		yield;
	}
	
	wait(d);
	
	Obj_Delete(obj);
}

task TExplosionA1(x, y, color, type){
	_PlaySE(16);
	
	loop(4){TExplosion1(x+rand(-24,24), y+rand(-24,24), color, 128, 0, 0);}
	
	loop(7){TExplosion2(x,y,color,50+rand(-10,10),type,30,0.5);}
}

task TExplosionA2(x, y, color,r){
	TExplosion1(x, y, color, r, 0, 0);
}

task TExplosionA3(x, y, color, type,r){
	
	TExplosion1(x, y, color, r, 0, 0);
	
	loop(3){TExplosion2(x,y,color,50+rand(-10,10),type,30,0.5);}
}

task TExplosionB1(x,y,type){
	let ra = 128;
	loop(10){
		_PlaySE(17);
		loop(10){
			let ranang = rand(0,360);
			TExplosionA3(x+rand(0,ra)*cos(ranang), y+rand(0,ra)*sin(ranang), CR("rainbow"), type,128);
			wait(1);
		}
	}

	StartSlow(TARGET_ALL,30);
	
	loop(10){
		_PlaySE(17);
		loop(10){
			loop(1){
				let ranang = rand(0,360);
				TExplosionA3(x+rand(0,ra)*cos(ranang), y+rand(0,ra)*sin(ranang), CR("rainbow"), type,128);
			}
			yield;
		}
	}

	_PlaySE(18);
		
	ra = 128*1.5;
	loop(50){
		let ranang = rand(0,360);
		TExplosionA3(x+rand(0,ra)*cos(ranang), y+rand(0,ra)*sin(ranang), CR("rainbow"), type,128);
	}

	TExplosion1(x, y, CR("white"), ra*3, 0, 0);
	
	wait(10);

	StopSlow(TARGET_ALL);

	ScreenShakeA1(50, 3);
}

task TExplosionB2(x,y,type){
	_PlaySE(18);
		
	let ra = 128*1.5;
	loop(50){
		let ranang = rand(0,360);
		TExplosionA3(x+rand(0,ra)*cos(ranang), y+rand(0,ra)*sin(ranang), CR("rainbow"), type,128);
	}

	TExplosion1(x, y, CR("white"), ra*3, 0, 0);
	
	wait(10);

	ScreenShakeA1(50, 3);
}
/////////////////////////////////////////////////////////////////////////////////
task ScreenShakeA1(shaketime, intensity){//Python?
	let x = Get2DCameraX;
	let y = Get2DCameraY;
	while(shaketime>0){
		Set2DCameraFocusX(GetStgFrameWidth/2 + rand(-intensity, intensity));
		Set2DCameraFocusY(GetStgFrameHeight/2 + rand(-intensity, intensity));
		shaketime--;
		yield;
	}
	Set2DCameraFocusX(GetStgFrameWidth/2);
	Set2DCameraFocusY(GetStgFrameHeight/2);
	yield;
}
/////////////////////////////////////////////////////////////////////////////////
task DeleteShotAnimCircle(x,y,r){
	DeleteShotInCircle(TYPE_SHOT,TYPE_ITEM,x,y,r);
}
/////////////////////////////////////////////////////////////////////////////////////