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

	}

	@MainLoop
	{

		yield;
	}
	@Finalize
	{
	}	

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

	task run()
	{
		let Wait=40;

		loop(8){
			fleez(Wait);
			Wait-=5;
			loop(5){yield}
		}
		loop(30){yield;}

	}
	
	task fleez(Wait){
		let angle=0;
		let A=1;
     		let obj=Obj_Create(OBJ_EFFECT);
		Obj_SetAutoDelete(obj,false);
		ObjEffect_SetTexture(obj,imgEffect);
		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,playerX+rand(80,-80),playerY+rand(80,-80));
		loop(40){
			angle+=12;
			A+=255/40;
			ObjEffect_SetAngle(obj,0,angle,0);
			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;
		}
		loop(Wait){
			angle+=12;
			ObjEffect_SetAngle(obj,0,angle,0);
			yield;
		}
		loop(10){
			angle+=12;
			ObjEffect_SetAngle(obj,0,angle,0);
			let Sangle=-90;
			loop(6){
				let objShot = Obj_Create(OBJ_SHOT);
				Obj_SetX(objShot, Obj_GetX(obj));//x座標設定
				Obj_SetY(objShot, Obj_GetY(obj));//y座標設定;
				Obj_SetSpeed(objShot,12);//速度設定
				ObjShot_SetGraphic(objShot, 2);//画像設定
				ObjShot_SetDamage(objShot, 20);//ダメージを設定
				ObjShot_SetPenetration(objShot, 5);//貫通力
              			Obj_SetAngle(objShot,Sangle);
				Sangle-=60;
			}
			PlaySE(SE_1);
			loop(2){yield;}
		}
		Obj_Delete(obj);

	}


}