#東方弾幕風[Player]	//自機スクリプトであることを示します
#ScriptVersion[2]	//スクリプトバージョン2が必須です
#Menu[チルノ 凍符 レーザー装備]//自機選択画面で表示されるメニューです
#Text[
高速移動時攻撃力★★★★☆
低速移動時攻撃力★★★★★
通常攻撃範囲    ★★☆☆☆
ボム攻撃力      ★★★★★
ボム攻撃範囲    ★★★☆☆
]	//自機選択画面で表示されるテキストです
#Image[]	//自機選択画面で表示される画像ファイルへのパスです
#ReplayName[cirnoB]	//リプレイ選択時に表示される文字です。8文字以内です。

script_player_main
{
	let cmx=GetClipMinX;//画面X最小
	let cmX=GetClipMaxX;//画面X最大
	let cmy=GetClipMinY;//画面Y最小
	let cmY=GetClipMaxY;//画面Y最大
	let imgPlayer = GetCurrentScriptDirectory~"img\player_cirno.png";
	let imgEffect = GetCurrentScriptDirectory~"img\effect_tiny.png";
	let imgSpell  = GetCurrentScriptDirectory~"img\imgSpell.png";
	let gazeeffect = GetCurrentScriptDirectory~"img\gazeeffect.png";
	let imgEffectA = GetCurrentScriptDirectory~"img\effect_tiny.png";
	let imgEffectC = GetCurrentScriptDirectory~"img\effect_circle.png";
	let shotCount = -1;//弾を連続で発射するための変数
	let shotSE ="sePlayerShot01.wav";
	let REIGEKISE = GetCurrentScriptDirectory()~"freeze10.wav";
	let BombSE = GetCurrentScriptDirectory()~"tm2_gun000.wav";
	let SpellSE=  GetCurrentScriptDirectory()~"don10_a.wav";
	let SE_1   =  GetCurrentScriptDirectory()~"freeze10.wav";
	let Reigeki = true; //冷撃再充填

	let S_obj1 = Obj_Create(OBJ_EFFECT);//スローエフェクトズレ対策用
	let S_obj2 = Obj_Create(OBJ_EFFECT);
	let S_obj3 = Obj_Create(OBJ_EFFECT);
	let SlowEffectObj = [S_obj1,S_obj2,S_obj3];
	@Initialize
	{	
		//自機の初期化時に一回だけ呼び出される部分です
		//ロード-----------------------------------------------------------
		LoadSE(shotSE);	
		LoadSE(BombSE);	
		LoadSE(SpellSE);
		LoadGraphic(gazeeffect);
		LoadGraphic(imgEffectA);
		LoadGraphic(imgEffectC);
		LoadSE(SE_1);	
		LoadGraphic(imgPlayer);
		LoadGraphic(imgEffect);
		LoadGraphic(imgSpell);
		//------------------------------------------------------------------
		SetInitialBombCount(2);			//初期ボム数
		SetRebirthFrame(8);			//食らいボム有効フレーム
		SetRebirthFrameReduction(0);		//食らいボム有効フレーム減少無し
		SetSpeed(4.5, 2);			//移動速度を設定
		SetGrazeCircle(50);			//かすり判定
		SetPlayerLifeImage(imgPlayer,0, 1, 48, 50);//残機数の画像
		LoadPlayerShotData(GetCurrentScriptDirectory~"img\cirnoShotData.txt");
		SetItemCollectLine(150);//アイテム回収ラインを設定

		SlowEffect;//低速エフェクト
 		option;//オプション
		Shot;//ショット
		//Reigeki_Switch_Gaze;//冷撃ゲージ
		Reigeki_Switch_Mark;//冷撃マーク
	}
	
	@MainLoop
	{	
		//毎フレーム実行される部分です
		//
		yield;
		if(GetCommonData("ResultTime") == 1){break;}
		SetIntersectionCircle(GetPlayerX, GetPlayerY, 1);//当たり判定登録	
		if(GetCommonData("C") < 100 && Reigeki == true && GetCommonData("REIGEKI") == false){//冷撃ＯＫ
			PlaySE(REIGEKISE);
			SetCommonData("REIGEKI",true); 
		}
		if(GetKeyState(VK_BOMB )==KEY_PUSH ){
			if(GetCommonData("REIGEKI") == true && Reigeki == true){
				UseSpellCard("REIGEKIFreez",0);
				Reigeki_Switch;
								
			}
		}

	}
	@Missed{
		let C = GetCommonData("C");
		let I = GetCommonData("GetIce");
		if(C>0){SetCommonData("C",C-14);}//気温低下
		if(I > 0){SetCommonData("GetIce",GetCommonData("GetIce")-1000);}//最大スコア低下
	}
	task  Reigeki_Switch_Gaze{//冷撃ゲージ
		let C = GetCommonData("C");
		let Sca=0;
		let a=255;
     		let obj=Obj_Create(OBJ_EFFECT);
		ObjEffect_SetTexture(obj,gazeeffect);
		ObjEffect_SetPrimitiveType(obj,PRIMITIVE_TRIANGLESTRIP);
		ObjEffect_CreateVertex(obj,4);
		ObjEffect_SetVertexXY(obj,0,  0,-2);
		ObjEffect_SetVertexXY(obj,1, 42,-2);
		ObjEffect_SetVertexXY(obj,2,  0, 2);
		ObjEffect_SetVertexXY(obj,3, 42, 2);
		ObjEffect_SetVertexUV(obj,0,14,8);
		ObjEffect_SetVertexUV(obj,1,15,8);
		ObjEffect_SetVertexUV(obj,2,14,9);
		ObjEffect_SetVertexUV(obj,3,15,9);
		Obj_SetPosition(obj,cmx+6,cmY-26);
		while( !Obj_BeDeleted(obj) ){
			if(GetPlayerX<=cmx+120&&GetPlayerY>=cmY-60){a=96;}
			else{a=255;}
			ObjEffect_SetVertexColor(obj ,0,a,160,160,200);
			ObjEffect_SetVertexColor(obj ,1,a,205,205,255);
			ObjEffect_SetVertexColor(obj ,2,a,160,160,200);
			ObjEffect_SetVertexColor(obj ,3,a,205,205,255);
			if(Reigeki == true){
				Sca=0;
				ObjEffect_SetScale(obj,1,1);
			}
			else{
				ObjEffect_SetScale(obj,Sca,1);
				Sca+=1/1200;
			}
			yield;
		}
		Obj_Delete(obj);
	}

	task Reigeki_Switch_Mark{//冷撃マーク
		let a=0;
		let angle=0;
     		let obj=Obj_Create(OBJ_EFFECT);
		ObjEffect_SetTexture(obj,imgEffectA);
		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,cmx+14,cmY-32);
		while( !Obj_BeDeleted(obj) ){
			if(GetPlayerX<=cmx+120&&GetPlayerY>=cmY-60){a=96;}
			else{a=255;}
			if(GetCommonData("REIGEKI") != true || Reigeki != true){
				a=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);
			ObjEffect_SetAngle(obj,0,angle,0);
			angle+=6;
			yield;
		}
		Obj_Delete(obj);
	}

	@SpellCard
	{
		if(GetCommonData("ResultTime") == 1){
			AddBomb(1);
			break;
		}
		if(GetCommonData("REIGEKI") == true && Reigeki == true){
			UseSpellCard("REIGEKIFreez",0);
			Reigeki_Switch;
			AddBomb(1);	//ボムが一個以上あるときに減らないようにする
			SetCommonData("GetIce",GetCommonData("GetIce")-10000);//最大スコア低下
		}
		else{
			let C = GetCommonData("C");
			if(C>600){SetCommonData("C",C-500);}//気温低下
			else{SetCommonData("C",0);}
			SetCommonData("GetIce",GetCommonData("GetIce")-20000);//最大スコア低下
			UseSpellCard("ParfectFreez",0);	
			SpellName;//スペル名表示
		}
	}

	task SpellName{
		let Sca=1.2;
		let Y=80;
		let A=128;
     		let obj=Obj_Create(OBJ_EFFECT);
		Obj_SetAutoDelete(obj,false);
		ObjEffect_SetTexture(obj,imgSpell);
		ObjEffect_SetPrimitiveType(obj,PRIMITIVE_TRIANGLESTRIP);
		ObjEffect_CreateVertex(obj,4);
		ObjEffect_SetVertexXY(obj,0,-128,-16);
		ObjEffect_SetVertexXY(obj,1, 128,-16);
		ObjEffect_SetVertexXY(obj,2,-128, 16);
		ObjEffect_SetVertexXY(obj,3, 128, 16);
		ObjEffect_SetVertexUV(obj,0,  0, 0);
		ObjEffect_SetVertexUV(obj,1,256, 0);
		ObjEffect_SetVertexUV(obj,2,  0,32);
		ObjEffect_SetVertexUV(obj,3,256,32);
		loop(20){
			A+=127/20;
			Sca-=0.2/20;
			ObjEffect_SetVertexColor(obj,0,A,255,255,255);
			ObjEffect_SetVertexColor(obj,1,A,223,223,255);
			ObjEffect_SetVertexColor(obj,2,A,96,96,255);
			ObjEffect_SetVertexColor(obj,3,A,64,64,255);
			ObjEffect_SetScale(obj,Sca,Sca);
			Obj_SetPosition(obj,GetCenterX-50,GetCenterY+Y);
			yield;
		}
		loop(50){yield;}
		loop(35){
			Obj_SetPosition(obj,GetCenterX-50,GetCenterY+Y);
			Y+=3;
			yield;
		}
		loop(50){yield;}
		Obj_Delete(obj);
	}

	task Reigeki_Switch{
		Reigeki = false;
		loop(120){yield;}
		Reigeki = true;
	}
	
	@DrawLoop
	{
		SetColor(255, 255, 255);//自機グラフィック
		SetRenderState(ALPHA);
		SetTexture(imgPlayer);
		if(GetKeyState(VK_LEFT)==KEY_PUSH || GetKeyState(VK_LEFT)==KEY_HOLD)
		{
			SetGraphicRect(0, 51, 48, 96);
		}
		else if(GetKeyState(VK_RIGHT)==KEY_PUSH || GetKeyState(VK_RIGHT)==KEY_HOLD)
		{
			SetGraphicRect(0, 97, 48, 144);
		}
		else 
		{
			SetGraphicRect(0, 1, 48, 50);
		}
		DrawGraphic(GetPlayerX(), GetPlayerY());
		Obj_SetPosition(SlowEffectObj[0],GetPlayerX, GetPlayerY);
		Obj_SetPosition(SlowEffectObj[1],GetPlayerX, GetPlayerY);
		Obj_SetPosition(SlowEffectObj[2],GetPlayerX, GetPlayerY);
	}
	
	@Finalize
	{
		//スクリプト終了時に一回だけ呼び出される部分です
		DeleteGraphic(imgPlayer);
	}
	#include_function".\shot.txt"
	#include_function".\option.txt"
	#include_function".\localdata.txt"

}
#include_script".\Spell.txt"
#include_script".\REIGEKI.txt"