script_spell REIGEKIFreez
{
	let PX = GetPlayerX;
	let PY = GetPlayerY;
	let imgEffectA = GetCurrentScriptDirectory~"img\effect_tiny.png";
	let imgEffectC = GetCurrentScriptDirectory~"img\effect_circle.png";
	let ReigekiSE = GetCurrentScriptDirectory()~"freeze10.wav";
	@Initialize
	{
		SetPlayerInvincibility(120);//無敵時間を設定
		BackOpen;
		run();
		EF();
		ScoreUP();
		SETask();

	}

	@MainLoop
	{
		yield;
	}
	@Finalize
	{
	}	

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

	task run()
	{
		let A=128;
		let angle = 0;
		let r = 20;
		loop(60){//弾消し範囲
			loop(4){
				fleez(A,r,angle+rand(0,90));
				angle+=90;
			}
			A-=64/60;
			DeleteEnemyShotToItemInCircle(SHOT,PX,PY,r);			
			r += 8;
			yield;
		}
		loop(10){//弾消し範囲
			DeleteEnemyShotToItemInCircle(SHOT,PX,PY,r);			
			r += 8;
			yield;
		}
		SetCommonData("C",1200);
		SetCommonData("REIGEKI",false);
	}

	task EF{//ブリザード的な物
		let A=140;
		let r = 0;
     		let obj=Obj_Create(OBJ_EFFECT);
		Obj_SetAutoDelete(obj,false);
		ObjEffect_SetTexture(obj,imgEffectC);
		ObjEffect_SetRenderState(obj,ADD);
		ObjEffect_SetPrimitiveType(obj,PRIMITIVE_TRIANGLESTRIP);
		ObjEffect_CreateVertex(obj,4);
		ObjEffect_SetVertexXY(obj,0,-64,-64);
		ObjEffect_SetVertexXY(obj,1, 64,-64);
		ObjEffect_SetVertexXY(obj,2,-64, 64);
		ObjEffect_SetVertexXY(obj,3, 64, 64);
		ObjEffect_SetVertexUV(obj,0,128,256);
		ObjEffect_SetVertexUV(obj,1,256,256);
		ObjEffect_SetVertexUV(obj,2,128,384);
		ObjEffect_SetVertexUV(obj,3,256,384);
		ObjEffect_SetLayer(obj,0);
		Obj_SetPosition(obj,PX,PY);
		loop(60){
			A-=140/60;
			r+=0.13;
			ObjEffect_SetScale(obj,r,r);
			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;
		}
		Obj_Delete(obj);
	}

	task fleez(A,r,P_angle){//氷エフェクト
     		let obj=Obj_Create(OBJ_EFFECT);
		let angle=0;
		let NA = A;
		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);
		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);
		loop(25){
			A-=NA/25;
			ObjEffect_SetAngle(obj,0,0,angle);
			Obj_SetPosition(obj,PX+r*sin(P_angle),PY+r*cos(P_angle));
			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);
			angle+=2;
			yield;
		}
		Obj_Delete(obj);		

	}

	task SETask{
		loop(6){
			PlaySE(ReigekiSE);
			loop(10){yield}
		}
	}

	task ScoreUP{//アイススコア増加
		let nun = GetEnemyShotCount;
		loop(70){
			SetCommonData("GetIce",GetCommonData("GetIce")+truncate(nun/70)*10);
			yield;
		}
	}

}