
task Vortex(x, y, scale, scalesp, alpha, alphasp, color, rotation)
{
	let path = GetCurrentScriptDirectory() ~ "img/effects/vortex.png";
	let obj = ObjPrim_Create(OBJ_SPRITE_2D);
	ObjPrim_SetTexture(obj, path);
	Obj_SetRenderPriority(obj, 0.65);
	ObjRender_SetBlendType(obj, BLEND_ADD_ARGB);
	ObjSprite2D_SetSourceRect(obj, 1, 1, 255, 255);
	ObjSprite2D_SetDestCenter(obj);
	ObjRender_SetPosition(obj, x, y, 0);
	ObjRender_SetColor(obj, color[0], color[1], color[2]);
	let rotate = 0;
	let a = 0;
	let alphaws = 0;
	
	while(alpha > 0 && scale > 0)
	{
		if(a == 0){ObjRender_SetAlpha(obj, alphaws);}
		if(a == 1){ObjRender_SetAlpha(obj, alpha);}
		ObjRender_SetScaleXYZ(obj, scale, scale, 1);
		ObjRender_SetAngleZ(obj, rotate);
		
		rotate += rotation;
		scale += scalesp;
		if(a == 0){alphaws += 50;
		if(alphaws >= 255){a++;}
		}
		if(a == 1){alpha += alphasp;}
		yield;
	}
	Obj_Delete(obj);
}

task Particle(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 Concentrate(x, y, angl, angle, num, rad, spd, scale, type, ang, color, negate){
	ascent(i in 0..num){
	Particle(x+rad*cos(i*360/num+angle), y+rad*sin(i*360/num+angle), spd, angl, scale, ang, type, color, negate);
	}
}

task Aura(obj, file, num, color, scale, dir){
	let aur = ObjPrim_Create(OBJ_SPRITE_2D);
	let a = 0;
	let ar = rand(0,360);
	let recs = [0,0,0,0];
	
	if(file == 0){ObjPrim_SetTexture(aur, GetCurrentScriptDirectory ~ "img/effects/charge.png");}
	if(file == 1){ObjPrim_SetTexture(aur, GetCurrentScriptDirectory ~ "img/effects/spark.png");}	
	if(num == 0){ObjSprite2D_SetSourceRect(aur,128*0,128*0,128*1,128*1);}
	if(num == 1){ObjSprite2D_SetSourceRect(aur,128*1,128*0,128*2,128*1);}
	if(num == 2){ObjSprite2D_SetSourceRect(aur,128*0,128*1,128*1,128*2);}
	if(num == 3){ObjSprite2D_SetSourceRect(aur,128*1,128*1,128*2,128*2);}
	ObjSprite2D_SetDestCenter(aur);		
	ObjRender_SetScaleXYZ(aur,scale, scale,0);
	Obj_SetRenderPriorityI(aur, 45);
	ObjRender_SetBlendType(aur, BLEND_ADD_ARGB);
	ObjRender_SetAngleZ(aur, ar+a);
	ObjRender_SetColorHSV(aur, color, 255, 255);
	ObjRender_SetPosition(aur, ObjMove_GetX(obj), ObjMove_GetY(obj), 0);
	
	while(!Obj_IsDeleted(obj)){
	ObjRender_SetAlpha(aur, a);
	ObjRender_SetPosition(aur, ObjMove_GetX(obj), ObjMove_GetY(obj), 0);
	ObjRender_SetAngleZ(aur, ar+(a*3)*dir);
	a+=6;
	yield;
	}
	Obj_Delete(aur);
}

task MagicRing(tar){
	let obj = ObjPrim_Create(OBJ_SPRITE_2D);
	let objScene = GetEnemyBossSceneObjectID();
	let a = 0;
	let lifeRateRender = 0;
	
	ObjPrim_SetTexture(obj, GetCurrentScriptDirectory ~ "img/effects/magicring.png");
	ObjSprite2D_SetSourceRect(obj, 0, 0, 128, 128);
	ObjSprite2D_SetDestCenter(obj);		
	Obj_SetRenderPriorityI(obj, 32);
	ObjRender_SetBlendType(obj, BLEND_ADD_ARGB);
	ObjRender_SetPosition(obj, ObjMove_GetX(tar), ObjMove_GetY(tar), 0);
	
	while(!Obj_IsDeleted(tar)){
	let lifeTotalMax = ObjEnemyBossScene_GetInfo(objScene, INFO_CURRENT_LIFE_MAX);
	let lifeTotal = ObjEnemyBossScene_GetInfo(objScene, INFO_CURRENT_LIFE);
	let lifeRate = min(lifeTotal / lifeTotalMax, lifeRateRender);
	
	ObjRender_SetAlpha(obj, 255*lifeRate);
	
	ObjRender_SetPosition(obj, ObjMove_GetX(tar), ObjMove_GetY(tar), 0);
	ObjRender_SetScaleXYZ(obj, 1.5+0.25*cos(a/2), 1.5+0.25*cos(a/2), 1);
	ObjRender_SetAngleZ(obj, a*1.5);
	lifeRateRender += 0.01;
	lifeRateRender = min(lifeRateRender, 1);
	a+=6;
	yield;
	}
	Obj_Delete(obj);
}

task WaveCircle(r, g, b, rad)
{
	//レンダリングターゲットに使用するテクスチャ
	let renderTexture = GetReservedRenderTargetName(0);

	let frame = 0; //フレーム
	let baseEffectRadius = rad; //基準エフェクト半径
	let outerFluct = 16; //エフェクト半径の最大変化量
	let effectRadius = 0; //エフェクト半径


	let priEffectMin = 20; //エフェクトをかける最小優先度
	let priEffectMax = 28; //エフェクトをかける最大優先度

	//背景のみエフェクトの対象とする
	//エフェクトの描画でまかなえるため、
	//優先度20～28の通常描画を無効にする。
	SetInvalidRenderPriorityA1(priEffectMin, priEffectMax);

	let frameWidth = GetStgFrameWidth();
	let frameHeight = GetStgFrameHeight();
	let frameLeft = GetStgFrameLeft();
	let frameRight = frameLeft + frameWidth;
	let frameTop = GetStgFrameTop();
	let frameBottom = frameTop + frameHeight;


	//--------------------------------
	//ゆがみオブジェクト
	let objWave = ObjPrim_Create(OBJ_SPRITE_2D); //2Dスプライトオブジェクト生成
	Obj_SetRenderPriorityI(objWave, 25); //描画優先度を設定
	ObjPrim_SetTexture(objWave, renderTexture); //テクスチャを設定
	ObjSprite2D_SetSourceRect(objWave, frameLeft, frameTop, frameRight, frameBottom);
	ObjSprite2D_SetDestRect(objWave, 0, 0, frameWidth, frameHeight);
	Obj_SetRenderPriorityI(objWave, priEffectMax + 1);

	//ゆがみオブジェクトにシェーダを設定
	let pathShader = GetCurrentScriptDirectory ~ "shaders/WaveCircle.txt";
	ObjShader_SetShaderF(objWave, pathShader);
	ObjShader_SetTechnique(objWave, "TecWave");


	//ボスのライフが0になるまでエフェクトをかける。
	let objEnemy = GetEnemyBossObjectID[0];
	while(ObjEnemy_GetInfo(objEnemy, INFO_LIFE) > 0)
	{
		//エフェクト半径
		effectRadius = baseEffectRadius + outerFluct * sin(frame*4);

		let enemyX = ObjMove_GetX(objEnemy); //敵座標X
		let enemyY = ObjMove_GetY(objEnemy); //敵座標Y

		//--------------------------------
		//優先度20～28(背景)をエフェクト用のテクスチャに描画
		//シェーダ解除
		RenderToTextureA1(renderTexture, priEffectMin, priEffectMax, true);

		//--------------------------------
		//シェーダにパラメータを設定
		ObjShader_SetFloat(objWave, "frame_", frame);
		ObjShader_SetFloat(objWave, "enemyX_", enemyX + frameLeft);
		ObjShader_SetFloat(objWave, "enemyY_", enemyY + frameTop);
		ObjShader_SetFloat(objWave, "waveRadius_", effectRadius);
		ObjShader_SetFloat(objWave, "red", r);
		ObjShader_SetFloat(objWave, "green", g);
		ObjShader_SetFloat(objWave, "blue", b);

		frame++;
		yield;
	}

	//エフェクト用オブジェクト削除
	Obj_Delete(objWave);
	ClearInvalidRenderPriority();
}

task Monochrome{
	let dir = GetCurrentScriptDirectory();
	let pathShader = GetCurrentScriptDirectory ~ "shaders/Monochrome.txt";

	let objShader = ObjShader_Create();
	let objShader2 = ObjShader_Create();
	let objShader3 = ObjShader_Create();
	ObjShader_SetShaderF(objShader, pathShader);
	ObjShader_SetShaderF(objShader2, pathShader);
	ObjShader_SetShaderF(objShader3, pathShader);
	ObjShader_SetTechnique(objShader, "TecMonotone");
	ObjShader_SetTechnique(objShader2, "TecMonotone");
	ObjShader_SetTechnique(objShader3, "TecMonotone");
	SetShaderI(objShader, 60, 100);
	SetShaderI(objShader2, 0, 24);
	SetShaderI(objShader2, 30, 40);
}