let exp=2.71828;//ネイピア数

function DistanceToPlayer(X,Y)
{//プレイヤーまでの距離を返す
	return(((X-GetPlayerX)^2+(Y-GetPlayerY)^2)^0.5);
}

function DistanceToBoss(X,Y)
{//敵までの距離を返す。IDが１なので注意
	return(((X-GetEnemyInfo(1,ENEMY_X))^2+(Y-GetEnemyInfo(1,ENEMY_Y))^2)^0.5);
}

function wait(w)
{
    loop(w) {
	 yield; 
	}
}

function CsdDistanceToPlayer(X,Y,EX,EY)
{//距離を返す
	return(((X-EX)^2+(Y-EY)^2)^0.5);
}

let imgSpellEffect=GetCurrentScriptDirectory ~ "..\img/effect_tiny.png";
LoadGraphic(imgSpellEffect);
let imgCircleEffect=GetCurrentScriptDirectory ~ "..\img/CircleEffect.png";
LoadGraphic(imgCircleEffect);

task Concentration03(frame,R,G,B)
{
Concentration03CircleEffect(frame,R,G,B);
if(frame<31){return;}
loop(frame-30)
{
	Concentration03Effect(R,G,B);
	Concentration03Effect(R,G,B);
	yield;
}
}

task Concentration03Effect(R,G,B)
{
		let Rudius=rand(100,250);
		let StandardRudius=Rudius;
		let Angle=rand(0,360);
		let RotateAngle=rand(2,10);
		let Zangle=rand(0,360);
		let dir=rand_int(0,1)*2-1;
		let MinScale=0.5;
		let Scale=rand(0.5,2.0);
		let StandardScale=Scale;
		let Alpha=40;

		let obj = Obj_Create(OBJ_EFFECT);
		ObjEffect_SetTexture(obj, imgSpellEffect);
		ObjEffect_SetPrimitiveType(obj, PRIMITIVE_TRIANGLEFAN);
		ObjEffect_SetRenderState(obj, ADD); 
		ObjEffect_CreateVertex(obj, 4);
		ObjEffect_SetVertexXY(obj, 0, -15, -15);
		ObjEffect_SetVertexXY(obj, 1, 15,  -15);
		ObjEffect_SetVertexXY(obj, 2, 15, 15);
		ObjEffect_SetVertexXY(obj, 3,  -15,  15);
		
		ObjEffect_SetVertexUV(obj, 0,  2,  24);
		ObjEffect_SetVertexUV(obj, 1,  32, 24);
		ObjEffect_SetVertexUV(obj, 2, 32,  55);
		ObjEffect_SetVertexUV(obj, 3, 2, 55);
		ObjEffect_SetLayer(obj,4);
		ObjEffect_SetScale(obj, Scale,Scale);
		
		ObjEffect_SetVertexColor(obj,0,Alpha,R,G,B);
		ObjEffect_SetVertexColor(obj,1,Alpha,R,G,B);
		ObjEffect_SetVertexColor(obj,2,Alpha,R,G,B);
		ObjEffect_SetVertexColor(obj,3,Alpha,R,G,B);

		Obj_SetPosition(obj,GetX+Rudius*cos(Angle),GetY+Rudius*sin(Angle));
		Obj_SetAngle(obj,Angle);

		ascent(let i in 0..40)
		{
			ObjEffect_SetVertexColor(obj,0,Alpha,R,G,B);
			ObjEffect_SetVertexColor(obj,1,Alpha,R,G,B);
			ObjEffect_SetVertexColor(obj,2,Alpha,R,G,B);
			ObjEffect_SetVertexColor(obj,3,Alpha,R,G,B);
			Obj_SetPosition(obj,GetX+Rudius*cos(Angle),GetY+Rudius*sin(Angle));
			ObjEffect_SetAngle(obj,0,0,Zangle);
			ObjEffect_SetScale(obj, Scale+MinScale,Scale+MinScale);
			Rudius-=StandardRudius/35;
			Zangle+=RotateAngle*dir;
			Scale-=StandardScale/35;
			if(i>25)
			{
			Alpha-=4;
			}
			yield;
		}
		Obj_Delete(obj);
}

task Concentration03CircleEffect(let frame,R,G,B)
{
		let Scale=0.8;
		let StandardScale=Scale;
		let Alpha=80;

		let obj = Obj_Create(OBJ_EFFECT);
		ObjEffect_SetTexture(obj, imgCircleEffect);
		ObjEffect_SetPrimitiveType(obj, PRIMITIVE_TRIANGLEFAN);
		ObjEffect_SetRenderState(obj, ADD); 
		ObjEffect_CreateVertex(obj, 4);
		ObjEffect_SetVertexXY(obj, 0, -256, -256);
		ObjEffect_SetVertexXY(obj, 1, 256,  -256);
		ObjEffect_SetVertexXY(obj, 2, 256, 256);
		ObjEffect_SetVertexXY(obj, 3,  -256,  256);
		
		ObjEffect_SetVertexUV(obj, 0,  0,  0);
		ObjEffect_SetVertexUV(obj, 1,  512, 0);
		ObjEffect_SetVertexUV(obj, 2, 512,  512);
		ObjEffect_SetVertexUV(obj, 3, 0, 512);
		ObjEffect_SetLayer(obj,4);
		ObjEffect_SetScale(obj, Scale,Scale);
		
		ObjEffect_SetVertexColor(obj,0,Alpha,R,G,B);
		ObjEffect_SetVertexColor(obj,1,Alpha,R,G,B);
		ObjEffect_SetVertexColor(obj,2,Alpha,R,G,B);
		ObjEffect_SetVertexColor(obj,3,Alpha,R,G,B);

		Obj_SetPosition(obj,GetX,GetY);

		ascent(let i in 0..frame)
		{
			ObjEffect_SetVertexColor(obj,0,Alpha,R,G,B);
			ObjEffect_SetVertexColor(obj,1,Alpha,R,G,B);
			ObjEffect_SetVertexColor(obj,2,Alpha,R,G,B);
			ObjEffect_SetVertexColor(obj,3,Alpha,R,G,B);
			ObjEffect_SetScale(obj, Scale,Scale);
			Scale-=StandardScale/frame;
			yield;
		}
		Obj_Delete(obj);
}

//残像描画部

let BossShadowDrawNum=0;
let BossShadowAngle=[];
let BossShadowX=[];
let BossShadowY=[];
loop(10)
{
BossShadowX=BossShadowX~[0];
BossShadowY=BossShadowX~[0];
BossShadowAngle=BossShadowAngle~[0];
}

task DrawBossAndShadow(imgBoss,R,G,B)
{
	ascent(let j in 0..11)
	{
		SetGraphicAngle(0,0,BossShadowAngle[(BossShadowDrawNum+j)%10]);
	//	SetRenderState(ADD);
	//	SetGraphicScale(1.1,1.1);
		SetGraphicScale(1.3-0.3*(j+1)/13,1.3-0.3*(j+1)/13);
		SetColor(R,G,B);
		SetAlpha(255*(j+1)/13);
		DrawGraphic(BossShadowX[(BossShadowDrawNum+j)%10],BossShadowY[(BossShadowDrawNum+j)%10]);
	}
	SetRenderState(ALPHA);
	SetColor(255,255,255);
	SetAlpha(255);
	SetGraphicAngle(0,0,0);
	SetGraphicScale(1,1);
}


task BossShadowPosition(frame)
{
wait(frame);
GetBossShadowPosition;
}

task GetBossShadowPosition
{
loop
{
	BossShadowDrawNum++;
	if(BossShadowDrawNum>9){BossShadowDrawNum=0;}
	BossShadowX[BossShadowDrawNum]=GetX;
	BossShadowY[BossShadowDrawNum]=GetY;
	BossShadowAngle[BossShadowDrawNum]=0;
	yield;
}
}

task BossShadowRoll(frame)
{
	ascent(let i in 0..frame)
	{
		BossShadowAngle[BossShadowDrawNum]=i*12;
		yield;
	}
}