SetRateScoreSystemEnable(false);
let LightMode=false;
#include_function ".\..\Config.txt"
SetCommonData("LIGHTMODE",LightMode);

let DoubleSpoilerSetEnemyLife=Norma*500+1000;
let DoubleSpoilerimgBorder =GetCurrentScriptDirectory ~ "..\img/border.png";
let imgSpellName=GetCurrentScriptDirectory ~ "..\img/SpellName.jpg";
let DoubleSpoilerimgSpellBack=GetCurrentScriptDirectory ~ "..\img/フレーム.png";
let DoubleSpoilerimgCircle=GetCurrentScriptDirectory ~ "..\img/Circle.png";

let SetBulletColor=["RED","ORANGE","YELLOW","GREEN","CYAN","BLUE","PURPLE","WHITE"];

let SULeng=length(StepUp);
let StepUpNum1=0;
let StepUpNum2=0;
let StepUpNum3=0;
let StepUpNum4=0;
let StepUpNum5=0;
let StepUpNum6=0;
let StepUpNum7=0;
let StepUpNum8=0;
let StepUpNum9=0;
if(SULeng>=1){StepUpNum1=StepUp[0]*500;}
if(SULeng>=2){StepUpNum2=StepUp[1]*500;}
if(SULeng>=3){StepUpNum3=StepUp[2]*500;}
if(SULeng>=4){StepUpNum4=StepUp[3]*500;}
if(SULeng>=5){StepUpNum5=StepUp[4]*500;}
if(SULeng>=6){StepUpNum6=StepUp[5]*500;}
if(SULeng>=7){StepUpNum7=StepUp[6]*500;}
if(SULeng>=8){StepUpNum8=StepUp[7]*500;}
if(SULeng>=9){StepUpNum9=StepUp[8]*500;}

let StepUp1=false;
let StepUp2=false;
let StepUp3=false;
let StepUp4=false;
let StepUp5=false;
let StepUp6=false;
let StepUp7=false;
let StepUp8=false;
let StepUp9=false;

//////////////////////////////////////////////////////////////////////////////////////
function InitializeDoubleSpoiler
{//Intializeで呼ばれる。初期設定、ライフ設定、タイム設定、画像読み込みなどを行う
	SetCommonData("BossExist",true);
	SetCommonData("BunSpell",true);
        LoadGraphic(DoubleSpoilerimgBorder);
        LoadGraphic(imgSpellName);
        LoadGraphic(DoubleSpoilerimgSpellBack);
        LoadGraphic(DoubleSpoilerimgCircle);

        SetLife(DoubleSpoilerSetEnemyLife);
	SetCommonData("EnemyLife",DoubleSpoilerSetEnemyLife-1000);

	BossEnd;
	DrawTimer(SpellTimer);
	StepUpJudg;
}

sub DrawDoubleSpoiler
{
	if(GetCommonDataDefault("DefeatBoss",false))
	{
		SetAlpha(0);
	}
}

sub FinalizeDoubleSpoiler
{//Finalizeで呼び出す。
	Slow(0);
	SetCommonData("BossExist",false);
}

task StepUpJudg
{//Lifeが一定以下になったらStepUp系をtrueに更新
loop
{
if(GetLife<=DoubleSpoilerSetEnemyLife-StepUpNum1){StepUp1=true;}
if(GetLife<=DoubleSpoilerSetEnemyLife-StepUpNum2){StepUp2=true;}
if(GetLife<=DoubleSpoilerSetEnemyLife-StepUpNum3){StepUp3=true;}
if(GetLife<=DoubleSpoilerSetEnemyLife-StepUpNum4){StepUp4=true;}
if(GetLife<=DoubleSpoilerSetEnemyLife-StepUpNum5){StepUp5=true;}
if(GetLife<=DoubleSpoilerSetEnemyLife-StepUpNum6){StepUp6=true;}
if(GetLife<=DoubleSpoilerSetEnemyLife-StepUpNum7){StepUp7=true;}
if(GetLife<=DoubleSpoilerSetEnemyLife-StepUpNum8){StepUp8=true;}
if(GetLife<=DoubleSpoilerSetEnemyLife-StepUpNum9){StepUp9=true;}
yield;
}
}

////////////////////////////////////////////////////////////////////////////////////////////
function SetBulletScorePoint(No,Score)
{//弾ごとのスコアを設定
	let BulletScorePoint=[100, 150, 400, 110, 40, 70, 80, 130, 200, 70, 60, 200, 150];
	BulletScorePoint[No]=Score;
	SetCommonData("ShotBasePoint",BulletScorePoint);
}


function BasePoint(Base)
{//ベースポイントを更新
	SetCommonData("BasePoint",GetCommonDataDefault("BasePoint",0)+Base);
}

function BulletColor(color)
{//色により共通データを更新
	alternative(color)
	case("RED"){SetCommonData("RedShot",GetCommonDataDefault("RedShot",0)+1);}
	case("BLUE"){SetCommonData("BlueShot",GetCommonDataDefault("BlueShot",0)+1)}
	case("GREEN"){SetCommonData("GreenShot",GetCommonDataDefault("GreenShot",0)+1);}
	case("YELLOW"){SetCommonData("YellowShot",GetCommonDataDefault("YellowShot",0)+1);}
	case("PURPLE"){SetCommonData("PurpleShot",GetCommonDataDefault("PurpleShot",0)+1);}
	case("CYAN"){SetCommonData("CyanShot",GetCommonDataDefault("CyanShot",0)+1);}
	case("ORANGE"){SetCommonData("OrangeShot",GetCommonDataDefault("OrangeShot",0)+1);}
	case("WHITE"){SetCommonData("WhiteShot",GetCommonDataDefault("WhiteShot",0)+1);}
}
////////////////////////////////////////////////////////////////////////////////////////////////
let DoubleSpoilerStopCount=0;
function DoubleSpoilerYield//Mainloopのyield時止め対応版
{
	if(GetCommonDataDefault("TimeStop",false)==true)
	{
		DoubleSpoilerStopCount+=1;
		if(DoubleSpoilerStopCount>=30)
		{
			SetCommonData("TimeStop",false);
		}
	}
	else if(GetCommonDataDefault("DefeatBoss",false)==true)
	{
		DoubleSpoilerStopCount+=1;

	//	yield;
		if(DoubleSpoilerStopCount>=30)
		{
			SetCommonData("TimeStop",false);
			VanishEnemy;
			Slow(0);
		}
	}
	else
	{
		yield;
		DoubleSpoilerStopCount=0;
	}
}

task DoubleSpoilerSetMovePosition02(X,Y,frame)
{//時止め対応版。指定位置に移動

	let GX=GetX;
	let GY=GetY;

	loop(frame)
	{
		SetX(GetX+(X-GX)/frame);
		SetY(GetY+(Y-GY)/frame);
		if(GetCommonDataDefault("DefeatBoss",false)==true)
		{
			break;
		}
		yield;
	}
}

task DoubleSpoilermoveToPlayer(xMove, yAdd, frame, left, top, right, bottom)
{//時止め対応版moveToPlayer
	let x;
	let y;

	if(GetPlayerX < GetX)
	{
		x = GetX - xMove;
		if(x < left)
		{
			x = GetX + xMove;
		}
	}
	else
	{
		x = GetX + xMove;
		if(right < x)
		{
			x = GetX - xMove;
		}
	}

        y = GetY + yAdd;
        if(y < top) {
            y = top;
        } else if(bottom < y) {
            y = bottom;
        }

	let X=GetX;
	let Y=GetY;

	loop(frame)
	{
	if(X-x<=0)
	{
		SetAction(ACT_MOVE_R,1);
	}
	else
	{
		SetAction(ACT_MOVE_L,1);
	}
		SetX(GetX+(x-X)/frame);
		SetY(GetY+(y-Y)/frame);
		if(GetCommonDataDefault("DefeatBoss",false)==true)
		{
			break;
		}
		yield;
	}
}

task DoubleSpoilerSetMovePosition03(let X, let Y, let weight,let MaxSpeed)
{//時止め対応版SetMovePosition03

let angle=atan2(Y-GetY,X-GetX);
let PX=GetX;
let PY=GetY;
let Frame=0;
let speed=0;
let CorX=0;
let CorY=0;

while(GetX!=X && GetY!=Y)
{

if(CsdDistanceToPlayer(PX,PY,X,Y)>weight*MaxSpeed)
{
	if(CsdDistanceToPlayer(GetX,GetY,X,Y)>weight*MaxSpeed)
	{
		speed=MaxSpeed;
	}
	else
	{
		Frame++;
		speed=8*exp^(-Frame/weight);
	}
}
else
{
	Frame++;
	speed=CsdDistanceToPlayer(PX,PY,X,Y)/weight*exp^(-Frame/weight);
} 

SetSpeed(speed);
SetAngle(angle);
yield;

}

}

function DoubleSpoilerDeleteEnemyShotImmediatelyInCircle(Type,X,Y,Rudius)
{
	wait(1);
	DeleteEnemyShotImmediatelyInCircle(Type,X,Y,Rudius);
	SetCommonData("DeleteBulletSignal",true);
}
///////////////////////////////////////////////////////////////////////////////////////////
task BossEnd//1000以下になったら勝利フラグ、被弾したら負けフラグを更新して消滅。
{
loop
{
	if(OnPlayerMissed)
	{
		Slow(0);
		loop(15){yield;}
		Slow(1);
		loop(10){yield;}
		Slow(2);
		loop(5){yield;}
		Slow(0);
		SetCommonData("LoseBoss",true);
		VanishEnemy;
	}

	if(GetCommonDataDefault("PlayerPhotoTimeStop",false)==true)
	{
		SetCommonData("PlayerPhotoTimeStop",false);
		SetCommonData("TimeStop",true);
		TimeStop(30,1,1,1);
	}
	if(GetLife<=1000)
	{
		SetCommonData("DefeatBossAction",true);
		SetCommonData("EndDefeatBullet",true);
		wait(1);
		wait(6);
		DeleteEnemyShotImmediatelyInCircle(ALL,GetCenterX,GetCenterY,350);
		SetCommonData("DefeatBoss",true);

		Slow(0);
		Slow(1);
	}
yield;
}
}

task Escape(time)//時間になったら画面上部に移動し、負けフラグ共通データを更新
{
	loop(time-60){yield;}
	SetAction(ACT_MOVE, 60);
	loop(60)
	{
	SetMovePosition02(GetCenterX, GetClipMinY-150, 60);
	yield;
	}
	SetCommonData("LoseBoss",true);
	VanishEnemy;
}

task DrawTimer(timeframe)//タイマーを表示する。撮る瞬間には一時的に消える。
{
Escape(timeframe);
let timesecond=timeframe/60;

		let bx1=GetCenterX+60;
		let by1=GetClipMinY+25;
		let scax1=0.8;
		let scay1=0.8;
		let obj = Obj_Create(OBJ_EFFECT);
		ObjEffect_SetTexture(obj, DoubleSpoilerimgBorder);
		ObjEffect_SetPrimitiveType(obj, PRIMITIVE_TRIANGLEFAN);
		ObjEffect_SetRenderState(obj, ADD); 
		ObjEffect_CreateVertex(obj, 4);
		ObjEffect_SetVertexXY(obj, 0, -7, -8);
		ObjEffect_SetVertexXY(obj, 1, 7,  -8);
		ObjEffect_SetVertexXY(obj, 2, 7, 8);
		ObjEffect_SetVertexXY(obj, 3,  -7,  8);

		let bx2=GetCenterX+48;
		let by2=GetClipMinY+25;
		let obj2 = Obj_Create(OBJ_EFFECT);
		ObjEffect_SetTexture(obj2, DoubleSpoilerimgBorder);
		ObjEffect_SetPrimitiveType(obj2, PRIMITIVE_TRIANGLEFAN);
		ObjEffect_SetRenderState(obj2, ADD); 
		ObjEffect_CreateVertex(obj2, 4);
		ObjEffect_SetVertexXY(obj2, 0, -7, -8);
		ObjEffect_SetVertexXY(obj2, 1, 7,  -8);
		ObjEffect_SetVertexXY(obj2, 2, 7, 8);
		ObjEffect_SetVertexXY(obj2, 3,  -7,  8);

		let bx3=GetCenterX+15;
		let by3=GetClipMinY+20;
		let scax2=1.6;
		let scay2=1.6;
		let obj3 = Obj_Create(OBJ_EFFECT);
		ObjEffect_SetTexture(obj3, DoubleSpoilerimgBorder);
		ObjEffect_SetPrimitiveType(obj3, PRIMITIVE_TRIANGLEFAN);
		ObjEffect_SetRenderState(obj3, ADD); 
		ObjEffect_CreateVertex(obj3, 4);
		ObjEffect_SetVertexXY(obj3, 0, -7, -8);
		ObjEffect_SetVertexXY(obj3, 1, 7,  -8);
		ObjEffect_SetVertexXY(obj3, 2, 7, 8);
		ObjEffect_SetVertexXY(obj3, 3,  -7,  8);

		let bx5=GetCenterX-7.5;
		let by5=GetClipMinY+20;
		let obj5 = Obj_Create(OBJ_EFFECT);
		ObjEffect_SetTexture(obj5, DoubleSpoilerimgBorder);
		ObjEffect_SetPrimitiveType(obj5, PRIMITIVE_TRIANGLEFAN);
		ObjEffect_SetRenderState(obj5, ADD); 
		ObjEffect_CreateVertex(obj5, 4);
		ObjEffect_SetVertexXY(obj5, 0, -7, -8);
		ObjEffect_SetVertexXY(obj5, 1, 7,  -8);
		ObjEffect_SetVertexXY(obj5, 2, 7, 8);
		ObjEffect_SetVertexXY(obj5, 3,  -7,  8);

		let bx4=GetCenterX+35;
		let by4=GetClipMinY+25;
		let obj4 = Obj_Create(OBJ_EFFECT);
		ObjEffect_SetTexture(obj4, DoubleSpoilerimgBorder);
		ObjEffect_SetPrimitiveType(obj4, PRIMITIVE_TRIANGLEFAN);
		ObjEffect_SetRenderState(obj4, ADD); 
		ObjEffect_CreateVertex(obj4, 4);
		ObjEffect_SetVertexXY(obj4, 0, -7, -8);
		ObjEffect_SetVertexXY(obj4, 1, 7,  -8);
		ObjEffect_SetVertexXY(obj4, 2, 7, 8);
		ObjEffect_SetVertexXY(obj4, 3,  -7,  8);

		let bx6=GetCenterX-30;
		let by6=GetClipMinY+20;
		let obj6 = Obj_Create(OBJ_EFFECT);
		ObjEffect_SetTexture(obj6, DoubleSpoilerimgBorder);
		ObjEffect_SetPrimitiveType(obj6, PRIMITIVE_TRIANGLEFAN);
		ObjEffect_SetRenderState(obj6, ADD); 
		ObjEffect_CreateVertex(obj6, 4);
		ObjEffect_SetVertexXY(obj6, 0, -7, -8);
		ObjEffect_SetVertexXY(obj6, 1, 7,  -8);
		ObjEffect_SetVertexXY(obj6, 2, 7, 8);
		ObjEffect_SetVertexXY(obj6, 3,  -7,  8);
loop{
if(timeframe>0)
{
timeframe-=1;
}
timesecond=timeframe/60;
let Pnum5=truncate(timesecond%1000/100);
let Pnum4=truncate(timesecond%100/10);
let Pnum3=truncate(timesecond%10/1);
let Pnum2=truncate(timesecond*10%10/1);
let Pnum1=truncate(timesecond*100%10/1);
		
		ObjEffect_SetVertexUV(obj, 0,  2+Pnum1*14,  114);
		ObjEffect_SetVertexUV(obj, 1,  14+Pnum1*14, 114);
		ObjEffect_SetVertexUV(obj, 2, 14+Pnum1*14,  131);
		ObjEffect_SetVertexUV(obj, 3, 2+Pnum1*14, 131);
		
		ObjEffect_SetScale(obj, scax1,scay1);
		Obj_SetPosition(obj,bx1,by1);
		ObjEffect_SetLayer(obj,3);

		
		ObjEffect_SetVertexUV(obj2, 0,  2+Pnum2*14,  114);
		ObjEffect_SetVertexUV(obj2, 1,  14+Pnum2*14, 114);
		ObjEffect_SetVertexUV(obj2, 2, 14+Pnum2*14,  131);
		ObjEffect_SetVertexUV(obj2, 3, 2+Pnum2*14, 131);
		
		Obj_SetPosition(obj2,bx2,by2);
		ObjEffect_SetLayer(obj2,3);
		ObjEffect_SetScale(obj2, scax1,scay1);
		
		ObjEffect_SetVertexUV(obj3, 0,  2+Pnum3*14,  114);
		ObjEffect_SetVertexUV(obj3, 1,  14+Pnum3*14, 114);
		ObjEffect_SetVertexUV(obj3, 2, 14+Pnum3*14,  131);
		ObjEffect_SetVertexUV(obj3, 3, 2+Pnum3*14, 131);
		
		Obj_SetPosition(obj3,bx3,by3);
		ObjEffect_SetLayer(obj3,3);
		ObjEffect_SetScale(obj3, scax2,scay2);

		
		ObjEffect_SetVertexUV(obj5, 0,  2+Pnum4*14,  114);
		ObjEffect_SetVertexUV(obj5, 1,  14+Pnum4*14, 114);
		ObjEffect_SetVertexUV(obj5, 2, 14+Pnum4*14,  131);
		ObjEffect_SetVertexUV(obj5, 3, 2+Pnum4*14, 131);
		
		Obj_SetPosition(obj5,bx5,by5);
		ObjEffect_SetLayer(obj5,3);
		ObjEffect_SetScale(obj5, scax2,scay2);

		
		ObjEffect_SetVertexUV(obj4, 0,  2+10*14,  114);
		ObjEffect_SetVertexUV(obj4, 1,  14+10*14, 114);
		ObjEffect_SetVertexUV(obj4, 2, 14+10*14,  131);
		ObjEffect_SetVertexUV(obj4, 3, 2+10*14, 131);
		
		Obj_SetPosition(obj4,bx4,by4);
		ObjEffect_SetLayer(obj4,3);
		ObjEffect_SetScale(obj4, 0.8,1.0);
		
		ObjEffect_SetVertexUV(obj6, 0,  2+Pnum5*14,  114);
		ObjEffect_SetVertexUV(obj6, 1,  14+Pnum5*14, 114);
		ObjEffect_SetVertexUV(obj6, 2, 14+Pnum5*14,  131);
		ObjEffect_SetVertexUV(obj6, 3, 2+Pnum5*14, 131);
		
		Obj_SetPosition(obj6,bx6,by6);
		ObjEffect_SetLayer(obj6,3);
		ObjEffect_SetScale(obj6, scax2,scay2);


			if(GetCommonDataDefault("Shooting",false)==true)
			{
				ascent(let i in 0..4)
				{
				ObjEffect_SetVertexColor(obj,i,0,255,150,150);
				ObjEffect_SetVertexColor(obj2,i,0,255,150,150);
				ObjEffect_SetVertexColor(obj3,i,0,255,150,150);
				ObjEffect_SetVertexColor(obj4,i,0,255,150,150);
				ObjEffect_SetVertexColor(obj5,i,0,255,150,150);
				ObjEffect_SetVertexColor(obj6,i,0,255,150,150);
				}
			}
			else
			{
				ascent(let i in 0..4)
				{
				ObjEffect_SetVertexColor(obj,i,255,255,255,255);
				ObjEffect_SetVertexColor(obj2,i,255,255,255,255);
				ObjEffect_SetVertexColor(obj3,i,255,255,255,255);
				ObjEffect_SetVertexColor(obj4,i,255,255,255,255);
				ObjEffect_SetVertexColor(obj5,i,255,255,255,255);
				ObjEffect_SetVertexColor(obj6,i,255,255,255,255);
				}
				if(timeframe<=600)
				{
					ascent(let i in 0..4)
					{
						ObjEffect_SetVertexColor(obj,i,250,255,150,150);
						ObjEffect_SetVertexColor(obj2,i,250,255,150,150);
						ObjEffect_SetVertexColor(obj3,i,250,255,150,150);
						ObjEffect_SetVertexColor(obj4,i,250,255,150,150);
						ObjEffect_SetVertexColor(obj5,i,250,255,150,150);
						ObjEffect_SetVertexColor(obj6,i,250,255,150,150);
					}
				}
			if(GetPlayerY<=GetCenterY)
			{
				ascent(let i in 0..4)
				{
					ObjEffect_SetVertexColor(obj,i,255+200*(GetPlayerY-32-(GetCenterY-32))/(GetCenterY-32),255,255,255);
					ObjEffect_SetVertexColor(obj2,i,255+200*(GetPlayerY-32-(GetCenterY-32))/(GetCenterY-32),255,255,255);
					ObjEffect_SetVertexColor(obj3,i,255+200*(GetPlayerY-32-(GetCenterY-32))/(GetCenterY-32),255,255,255);
					ObjEffect_SetVertexColor(obj4,i,255+200*(GetPlayerY-32-(GetCenterY-32))/(GetCenterY-32),255,255,255);
					ObjEffect_SetVertexColor(obj5,i,255+200*(GetPlayerY-32-(GetCenterY-32))/(GetCenterY-32),255,255,255);
					ObjEffect_SetVertexColor(obj6,i,255+200*(GetPlayerY-32-(GetCenterY-32))/(GetCenterY-32),255,255,255);
				}
				if(timeframe<=600)
				{
					ascent(let i in 0..4)
					{
						ObjEffect_SetVertexColor(obj,i,255+200*(GetPlayerY-32-(GetCenterY-32))/(GetCenterY-32),255,150,150);
						ObjEffect_SetVertexColor(obj2,i,255+200*(GetPlayerY-32-(GetCenterY-32))/(GetCenterY-32),255,150,150);
						ObjEffect_SetVertexColor(obj3,i,255+200*(GetPlayerY-32-(GetCenterY-32))/(GetCenterY-32),255,150,150);
						ObjEffect_SetVertexColor(obj4,i,255+200*(GetPlayerY-32-(GetCenterY-32))/(GetCenterY-32),255,150,150);
						ObjEffect_SetVertexColor(obj5,i,255+200*(GetPlayerY-32-(GetCenterY-32))/(GetCenterY-32),255,150,150);
						ObjEffect_SetVertexColor(obj6,i,255+200*(GetPlayerY-32-(GetCenterY-32))/(GetCenterY-32),255,150,150);
					}
				}
			}

			}

		yield;
}
}

task DrawSpellName(img,left,up,right,down)//スペル名とフレームを表示する。入力座標を左揃えで表示する。
{
		SpellCardFrame(0,0,256,50);
		if(img=="None"){return};
		let bx=GetClipMaxX-8;
		let by=360;
		let sx=1.5;
		let sy=1.5;
		let obj = Obj_Create(OBJ_EFFECT);
		ObjEffect_SetTexture(obj, img);
		ObjEffect_SetPrimitiveType(obj, PRIMITIVE_TRIANGLEFAN);
		ObjEffect_SetRenderState(obj, ADD); 
		ObjEffect_CreateVertex(obj, 4);

		ObjEffect_SetVertexXY(obj, 0, left-right, -(down-up)/2);
		ObjEffect_SetVertexXY(obj, 1, 0,  -(down-up)/2);
		ObjEffect_SetVertexXY(obj, 2, 0, (down-up)/2);
		ObjEffect_SetVertexXY(obj, 3,  left-right,  (down-up)/2);
		
		ObjEffect_SetVertexUV(obj, 0,  left,  up);
		ObjEffect_SetVertexUV(obj, 1,  right, up);
		ObjEffect_SetVertexUV(obj, 2, right,  down);
		ObjEffect_SetVertexUV(obj, 3, left,down);

		ObjEffect_SetScale(obj, sx,sy);
		Obj_SetPosition(obj,bx,by);
		ObjEffect_SetLayer(obj,3);
		loop(15)
		{
			ObjEffect_SetScale(obj, sx,sy);
			sx-=1/15;
			sy-=1/15;
		yield;
		}
		loop(45){yield;}
		loop(44)
		{
		Obj_SetPosition(obj,bx,by);
		by-=7.0;
		yield;
		}
		loop
		{
			if(GetCommonDataDefault("Shooting",false)==true)
			{
				ascent(let i in 0..4)
				{
					ObjEffect_SetVertexColor(obj,i,0,255,255,255);
				}
			}
			else
			{
				ascent(let i in 0..4)
				{
					ObjEffect_SetVertexColor(obj,i,255,255,255,255);
				}
			if(GetPlayerY<=GetCenterY)
			{
				ascent(let i in 0..4)
				{
					ObjEffect_SetVertexColor(obj,i,255+200*(GetPlayerY-32-(GetCenterY-32))/(GetCenterY-32),255,255,255);
				}
			}
			}
			yield;
		}
}

let DoubleSpoilerDrawY=350;
let DoubleSpoilerDrawScale=2;
let DoubleSpoilerDrawCount=0;

function DrawTextSpellName(name,DrawX)//スペル名とフレームを表示する
{
		if(DoubleSpoilerDrawCount<15)
		{
			DrawText(name,DrawX,DoubleSpoilerDrawY,DoubleSpoilerDrawScale*18,255);
			DoubleSpoilerDrawScale-=1/15;
		}
		else if(DoubleSpoilerDrawCount<60)
		{
			DrawText(name,DrawX,DoubleSpoilerDrawY,DoubleSpoilerDrawScale*18,255);
		}
		else if(DoubleSpoilerDrawCount<103)
		{
		DrawText(name,DrawX,DoubleSpoilerDrawY,DoubleSpoilerDrawScale*18,255);
		DoubleSpoilerDrawY-=7.0;
		}
		else
		{
			if(GetCommonDataDefault("Shooting",false)==true)
			{

			}
			else
			{
				if(GetPlayerY<=GetCenterY)
				{
					DrawText(name,DrawX,DoubleSpoilerDrawY,DoubleSpoilerDrawScale*18,255+200*(GetPlayerY-32-(GetCenterY-32))/(GetCenterY-32));
				}
				else
				{
					DrawText(name,DrawX,DoubleSpoilerDrawY,DoubleSpoilerDrawScale*18,255);
				}
			}
		}
		DoubleSpoilerDrawCount+=1;
}

task SpellCardFrame(left,up,right,down)
{
		let bx=GetClipMaxX-8;
		let by=360;
		let sx=2.7;
		let sy=2.5;
		let obj = Obj_Create(OBJ_EFFECT);
		ObjEffect_SetTexture(obj, DoubleSpoilerimgSpellBack);
		ObjEffect_SetPrimitiveType(obj, PRIMITIVE_TRIANGLEFAN);
		ObjEffect_SetRenderState(obj, ADD); 
		ObjEffect_CreateVertex(obj, 4);

		ObjEffect_SetVertexXY(obj, 0, left-right, -(down-up)/2);
		ObjEffect_SetVertexXY(obj, 1, 0,  -(down-up)/2);
		ObjEffect_SetVertexXY(obj, 2, 0, (down-up)/2);
		ObjEffect_SetVertexXY(obj, 3,  left-right,  (down-up)/2);
		
		ObjEffect_SetVertexUV(obj, 0,  left,  up);
		ObjEffect_SetVertexUV(obj, 1,  right, up);
		ObjEffect_SetVertexUV(obj, 2, right,  down);
		ObjEffect_SetVertexUV(obj, 3, left,down);

		ObjEffect_SetScale(obj, sx,sy);
		Obj_SetPosition(obj,bx,by);
		ObjEffect_SetLayer(obj,3);

			ObjEffect_SetVertexColor(obj,0,100,255,200,200);
			ObjEffect_SetVertexColor(obj,1,100,255,200,200);
			ObjEffect_SetVertexColor(obj,2,100,255,255,255);
			ObjEffect_SetVertexColor(obj,3,100,255,255,255);

		loop(15)
		{
			ObjEffect_SetScale(obj, sx,sy);
			sx-=0.9/15;
			sy-=1/15;
		yield;
		}
		loop(15)
		{
			ObjEffect_SetScale(obj, sx,sy);
			sx-=1/15;
			sy-=1/15;
		yield;
		}
		loop(30){yield;}
		loop(44)
		{
		Obj_SetPosition(obj,bx,by);
		by-=7.0;
		yield;
		}
		loop
		{
			if(GetPlayerY<=GetCenterY)
			{
				ascent(let i in 0..4)
				{
					ObjEffect_SetVertexColor(obj,i,100+50*(GetPlayerY-32-(GetCenterY-32))/(GetCenterY-32),255,255,255);
				}
			}
			if(GetCommonDataDefault("Shooting",false)==true)
			{
				ascent(let i in 0..4)
				{
					ObjEffect_SetVertexColor(obj,i,0,255,255,255);
				}
			}
			else
			{
				ascent(let i in 0..4)
				{
					ObjEffect_SetVertexColor(obj,i,100,255,255,255);
				}
			}
			yield;
		}
}

task MagicCircleEffectTask//魔方陣を呼ぶ
{
		let Zangle=rand(0,360);
		MagicCircleEffect(1,Zangle);
		MagicCircleEffect(-1,Zangle);
}

task MagicCircleEffect(let dir,let Zangle)//次第に小さくなる魔方陣、loopでNiceshotの倍率変動。
{
		let nice=1.5;
		SetCommonData("NiceShot",nice);
		yield;
		//PlaySE(csd~"se\clock04.wav");
		let scax=1;
		let scay=1;
  		let obj = Obj_Create(OBJ_EFFECT);
		Obj_SetPosition(obj,GetEnemyX,GetEnemyY);
		ObjEffect_SetTexture(obj,DoubleSpoilerimgCircle);
		ObjEffect_SetPrimitiveType(obj, PRIMITIVE_TRIANGLEFAN);
		ObjEffect_SetRenderState(obj, ADD);
		ObjEffect_SetScale(obj, scax,scay);
		ObjEffect_CreateVertex(obj, 4);
		ObjEffect_SetVertexXY(obj, 0, -128, -128);
		ObjEffect_SetVertexXY(obj, 1,  128, -128);
		ObjEffect_SetVertexXY(obj, 2,  128,  128);
		ObjEffect_SetVertexXY(obj, 3, -128,  128);
		
		ObjEffect_SetVertexUV(obj, 0,  0,  0);
		ObjEffect_SetVertexUV(obj, 1,  256, 0);
		ObjEffect_SetVertexUV(obj, 2, 256,  256);
		ObjEffect_SetVertexUV(obj, 3, 0, 256);

		ObjEffect_SetVertexColor(obj,0,50,255,250,250);
		ObjEffect_SetVertexColor(obj,1,50,255,250,250);
		ObjEffect_SetVertexColor(obj,2,50,255,250,250);
		ObjEffect_SetVertexColor(obj,3,50,255,250,250);
		ObjEffect_SetLayer(obj,4);
		Obj_SetPosition(obj,GetEnemyX,GetEnemyY);
		ObjEffect_SetScale(obj, scax,scay);
		ObjEffect_SetAngle(obj,0,0,Zangle);
		SetCommonData("NiceShot",nice);
		loop(15)
		{
			Zangle+=6*dir;
			SetCommonData("NiceShot",nice);
			yield;
			scax-=1/15;
			scay-=1/15;
			nice-=0.3/15;
			Obj_SetPosition(obj,GetEnemyX,GetEnemyY);
			ObjEffect_SetScale(obj, scax,scay);
			ObjEffect_SetAngle(obj,0,0,Zangle);
		}
		SetCommonData("NiceShot",0);
		Obj_Delete(obj);
}

#include_function ".\..\txt/CreateShotData.txt"