script_spell ParfectFreez
{
	let playerX = GetPlayerX;//スペル発動時の自機のx座標
	let playerY = GetPlayerY;//スペル発動時の自機のy座標
	let imgEffectA = GetCurrentScriptDirectory~"img\effect_tiny.png";
	let imgEffectB = GetCurrentScriptDirectory~"img\back05_06.png";
	let BombSE = GetCurrentScriptDirectory()~"tm2_gun000.wav";
	let SpellSE=  GetCurrentScriptDirectory()~"don10_a.wav";
	@Initialize
	{
		SetPlayerInvincibility(180);//無敵時間を設定
		PlaySE(SpellSE);
		BackOpen;
		run();
		SEPlayer;

	}

	@MainLoop
	{
		yield;
	}
	@Finalize
	{
	}	

	task BackOpen{//暗転解除、暗転は背景側で行う
		let SB_a=0;
		loop(90){yield;}
		loop(30){
			SB_a+=100/30;
			SetCommonData("Spell_Back",SB_a);//自機スペル中の背景暗転用共通関数
			yield;				 //少ずつ明るくなる
		}
		DeleteEnemyShotToItem(SHOT);
		End();
	}

	task run()
	{
		let wait=60;
		SetBG( 8);
		SetBG(-8);
		loop(20){
			fleez(10,wait,GetClipMinX-15, 8);
			fleez(10,wait,GetClipMaxX-15,-8);
			loop(2){yield;}
		}
		loop(20){
			fleez(10,wait,GetClipMinX+15, 8);
			fleez(10,wait,GetClipMaxX-15,-8);
			wait-=2;
			loop(2){yield;}
		}
		
	}

	task SetBG(P){//ブリザード的な物
		let A=70;
		let PX=0;
		let PY=0;
     		let obj=Obj_Create(OBJ_EFFECT);
		Obj_SetAutoDelete(obj,false);
		ObjEffect_SetTexture(obj,imgEffectB);
		ObjEffect_SetRenderState(obj,ADD);
		ObjEffect_SetPrimitiveType(obj,PRIMITIVE_TRIANGLESTRIP);
		ObjEffect_CreateVertex(obj,4);
		ObjEffect_SetVertexXY(obj,0,-192,-256);
		ObjEffect_SetVertexXY(obj,1, 192,-256);
		ObjEffect_SetVertexXY(obj,2,-192, 256);
		ObjEffect_SetVertexXY(obj,3, 192, 256);
		ObjEffect_SetVertexUV(obj,0,  0,  0);
		ObjEffect_SetVertexUV(obj,1,394,  0);
		ObjEffect_SetVertexUV(obj,2,  0,512);
		ObjEffect_SetVertexUV(obj,3,394,512);
		ObjEffect_SetLayer(obj,1);
		Obj_SetPosition(obj,GetCenterX,GetCenterY);
		loop(90){
			ObjEffect_SetVertexUV(obj,0,  0-PX,  0-PY);
			ObjEffect_SetVertexUV(obj,1,394-PX,  0-PY);
			ObjEffect_SetVertexUV(obj,2,  0-PX,512-PY);
			ObjEffect_SetVertexUV(obj,3,394-PX,512-PY);
			ObjEffect_SetVertexColor(obj,0,A,255,255,255);
			ObjEffect_SetVertexColor(obj,1,A,255,255,255);
			ObjEffect_SetVertexColor(obj,2,A,255,255,255);
			ObjEffect_SetVertexColor(obj,3,A,255,255,255);
			SetIntersectionCircle(GetCenterX,GetCenterY,360,2.5,false);
			PX+=P;
			PY+=8;
			yield;
		}
		loop(30){
			ObjEffect_SetVertexUV(obj,0,  0-PX,  0-PY);
			ObjEffect_SetVertexUV(obj,1,394-PX,  0-PY);
			ObjEffect_SetVertexUV(obj,2,  0-PX,512-PY);
			ObjEffect_SetVertexUV(obj,3,394-PX,512-PY);
			ObjEffect_SetVertexColor(obj,0,A,255,255,255);
			ObjEffect_SetVertexColor(obj,1,A,255,255,255);
			ObjEffect_SetVertexColor(obj,2,A,255,255,255);
			ObjEffect_SetVertexColor(obj,3,A,255,255,255);
			SetIntersectionCircle(GetCenterX,GetCenterY,360,3,false);
			PX+=P;
			PY+=8;
			A-=70/30;
			yield;
		}
		ObjShot_FadeDelete(obj);
	}
	
	task fleez(loops,wait,SetXPoint,PX){//氷エフェクト
		let angle  = 0;
		let A=255;
     		let obj=Obj_Create(OBJ_EFFECT);
		Obj_SetAutoDelete(obj,false);
		ObjEffect_SetTexture(obj,imgEffectA);
		ObjEffect_SetRenderState(obj,ADD);
		ObjEffect_SetPrimitiveType(obj,PRIMITIVE_TRIANGLESTRIP);
		ObjEffect_CreateVertex(obj,4);
		ObjEffect_SetVertexXY(obj,0,-12,-12);
		ObjEffect_SetVertexXY(obj,1, 12,-12);
		ObjEffect_SetVertexXY(obj,2,-12, 12);
		ObjEffect_SetVertexXY(obj,3, 12, 12);
		ObjEffect_SetVertexUV(obj,0, 0, 0);
		ObjEffect_SetVertexUV(obj,1,22, 0);
		ObjEffect_SetVertexUV(obj,2, 0,24);
		ObjEffect_SetVertexUV(obj,3,22,24);
		Obj_SetPosition(obj,SetXPoint,GetCenterY+rand(200,-300));//位置指定、画面端から
		loop(loops){
			angle+=10;
			ObjEffect_SetAngle(obj,0,0,angle);
			Obj_SetPosition(obj,Obj_GetX(obj)+PX,Obj_GetY(obj)+4);
			yield;
		}
		loop(wait){
			angle+=10;
			A-=255/wait;
			ObjEffect_SetAngle(obj,0,0,angle);
			Obj_SetPosition(obj,Obj_GetX(obj)+PX,Obj_GetY(obj)+4);
			ObjEffect_SetVertexColor(obj,0,A,255,255,255);
			ObjEffect_SetVertexColor(obj,1,A,255,255,255);
			ObjEffect_SetVertexColor(obj,2,A,255,255,255);
			ObjEffect_SetVertexColor(obj,3,A,255,255,255);
			yield;
		}
		ObjShot_FadeDelete(obj);

	}

	task SEPlayer{
		loop(5){
			PlaySE(BombSE);
			loop(20){yield;}
		}
	}

}