#東方弾幕風[Player]
#ScriptVersion[2] 
#Menu[射命丸文]
#Text[]
#ReplayName[文]
script_player_main
{
	let csd = GetCurrentScriptDirectory();
	let imgDS = csd~"..\img\pl10.png";
	let imgPlayer = csd~"..\img\Aya_myship2.png";
	let imgSpell = csd~"..\img\HoshiShot.png";
	let imgBorder = csd~"..\img\border.png";
	let imgCamera =csd~"..\img\Aya＆Hatate_camera_add.png";
	let imgCircle =csd~"..\img\Circle.png";
	let CameraBack=csd~"..\img\Back.png";
	let CameraBack2=csd~"..\img\Back2.png";
	let Charge=50;//フィルム装填率
	let FinderMode=false;//ファインダーモードかどうか
	let FinderTimeOut=false;//ファインダーモードがタイムアウトしたかどうか
	let FinderCentral=[];//焦点の中心座標Obj
	let CameraAngle=270;//カメラ角
	let CameraDir=90;//カメラの縦横
	let BossCapture=false;//ボスに当たり判定があるかどうか
	let PhotoSelectCorsol=0;

	let CharaDrawCount=0;
	let CharaLeftMoveDrawCount=0;
	let CharaRightMoveDrawCount=0;
	let DrawFrame=5;
	let CameraCoordinate;

	let CameraLong=256;
	let CameraWide=192;
	let snapFile=["DSAya00","DSAya01","DSAya02","DSAya03","DSAya04","DSAya05","DSAya06","DSAya07","DSAya08","DSAya09",
			"DSAya10","DSAya11","DSAya12","DSAya13","DSAya14","DSAya15","DSAya16","DSAya17","DSAya18","DSAya19",
			"DSAya20","DSAya21","DSAya22","DSAya23","DSAya24","DSAya25","DSAya26","DSAya27","DSAya28","DSAya29"];//SSに適当に名付け
	let photoNo=0;//何枚目かの判定。ボスを取るのに成功すると１増える
	let SE=[csd~"..\se\beep15" , csd~"..\se\power35" ,csd~"..\se\weapon00" , "0", csd~"..\se\se-033.mp3"  , csd~"..\se\power00" , csd~"..\se\kaze0102", csd~"..\se\sha01"];

	let NiceBonusNum=0;//スコア計算用変数
	let deleteShotTotal = 0;
	let deleteShotTotal2 = 0;
	let deleteShotKind = [];
	let deleteShotColor = [];
	let deleteShotKind2 = [];
	let deleteShotColor2 = [];
	loop(12){deleteShotKind = deleteShotKind ~ [0];}
	loop(8){deleteShotColor = deleteShotColor ~[0];}
	loop(12){deleteShotKind2 = deleteShotKind2 ~ [0];}
	loop(8){deleteShotColor2 = deleteShotColor2 ~[0];}

let shotPoint = [100, 150, 400, 110, 40, 70, 80, 130, 200, 70, 60, 200, 150];

let Color=["RedShot","OrangeShot","YellowShot","GreenShot","CyanShot","BlueShot","PurpleShot","WhiteShot"];
let DefaultBullet=[RED01,RED02,RED03,RED04,RED05,RED11,RED12,RED21,RED22,RED23,RED31,RED32,
		ORANGE01,ORANGE02,ORANGE03,ORANGE04,ORANGE05,ORANGE11,ORANGE12,ORANGE21,ORANGE22,ORANGE23,ORANGE31,ORANGE32,
		YELLOW01,YELLOW02,YELLOW03,YELLOW04,YELLOW05,YELLOW11,YELLOW12,YELLOW21,YELLOW22,YELLOW23,YELLOW31,YELLOW32,
		GREEN01,GREEN02,GREEN03,GREEN04,GREEN05,GREEN11,GREEN12,GREEN21,GREEN22,GREEN23,GREEN31,GREEN32,
		AQUA01,AQUA02,AQUA03,AQUA04,AQUA05,AQUA11,AQUA12,AQUA21,AQUA22,AQUA23,AQUA31,AQUA32,
		BLUE01,BLUE02,BLUE03,BLUE04,BLUE05,BLUE11,BLUE12,BLUE21,BLUE22,BLUE23,BLUE31,BLUE32,
		PURPLE01,PURPLE02,PURPLE03,PURPLE04,PURPLE05,PURPLE11,PURPLE12,PURPLE21,PURPLE22,PURPLE23,PURPLE31,PURPLE32,
		WHITE01,WHITE02,WHITE03,WHITE04,WHITE05,WHITE11,WHITE12,WHITE21,WHITE22,WHITE23,WHITE31,WHITE32
		];

	@Initialize
	{
	/*	if(DSdot==true)
		{
			SetPlayerLifeImage(img, 0, 0, 48, 48);
		}
		else
		{
	*/		SetPlayerLifeImage(imgPlayer, 0, 0, 48, 48);
	//	}
		LoadGraphic(imgPlayer);
		LoadGraphic(imgDS);
		LoadGraphic(imgSpell);
		LoadGraphic(imgBorder);
		LoadGraphic(imgCamera);
		LoadGraphic(CameraBack);
		LoadGraphic(CameraBack2);
		LoadGraphic(imgCircle);
		SetSpeed(5.5, 2.3);//自機の移動速度
		LoadPlayerShotData(csd~"..\txt\ShotData.txt");
		SetItemCollectLine(176);//アイテム回収されるy座標
		SetRebirthFrame(1);//食らいボムの有効フレーム
		SetGrazeCircle(0);
		if(GetCommonDataDefault("BunSpell",false)==true)
		{
			SetDefaultStatusVisible(false);
		}
		Tmain;
	}

	task Tmain
	{
		wait(2);
if(GetCommonDataDefault("ReplayMode",false)==false)
{
		Cdraw;//自機中心の陣のタスク
		Finder;//ファインダー制御
		CameraDirChange;//カメラの回転を制御
		CameraAngleChange;//カメラ角を制御
		SetSpeedChange;//スピードを三段階で制御
		ChargeFilm;//装填速度を制御
		ChargeFilmSE;
		ChargeFilmFinishSE;
		PhotoSelectChange;
		PlayerDrawCount;
}
else
{
	SetSpeed(0, 0);
}
		LoadDoubleSpoilerData;//開始してから60F後に読み込むデータ。スペル側で設定される。弾ごとのスコアのみ
	}

	@MainLoop
	{
		SetIntersectionCircle(GetPlayerX, GetPlayerY, 0);//自機の当たり判定
		yield;
	}

	@Missed{
	DeleteSE(SE[0]);
	DeleteSE(SE[1]);
	DeleteSE(SE[2]);
	DeleteSE(SE[3]);
	DeleteSE(SE[4]);
	DeleteSE(SE[5]);
	DeleteSE(SE[6]);
		MainLoop;
		if(GetCommonDataDefault("BunSpell",false)==true)
		{
			SetPlayerInvincibility(1200);
		}
		}

	@SpellCard
	{		
		AddBomb(1);
	}

	@DrawLoop
	{
	/*DrawText(CameraDir,100,50,12,200);
	DrawText(GetCommonDataDefault("angle",0),100,100,12,200);
	DrawText((atan2(GetEnemyInfo(1,ENEMY_Y)-GetPlayerY,GetEnemyInfo(1,ENEMY_X)-GetPlayerX)+360)%360,100,150,12,200);
	DrawText(floor(absolute((atan2(GetEnemyInfo(1,ENEMY_Y)-GetPlayerY,GetEnemyInfo(1,ENEMY_X)-GetPlayerX)+360)%360-GetCommonDataDefault("angle",0))%90),100,200,12,200);
	*/
	PlayerDraw;
	atari;
	}

	@Finalize
	{
		DeleteGraphic(imgSpell);
		DeleteGraphic(imgBorder);
	}

task PlayerDrawCount
{
loop
{
	if(DSdot)
	{
		CharaDrawCount+=1;
		if(CharaDrawCount>=DrawFrame*7)
		{
			CharaDrawCount=0;
		}

		CharaLeftMoveDrawCount+=1;

		if(CharaLeftMoveDrawCount>=DrawFrame*7)
		{
			CharaLeftMoveDrawCount=DrawFrame*4;
		}
		if(GetKeyState(VK_LEFT)==KEY_FREE)
		{
			CharaLeftMoveDrawCount=0;
		}

		CharaRightMoveDrawCount+=1;

		if(CharaRightMoveDrawCount>=DrawFrame*7)
		{
			CharaRightMoveDrawCount=DrawFrame*4;
		}
		if(GetKeyState(VK_RIGHT)==KEY_FREE)
		{
			CharaRightMoveDrawCount=0;
		}
	}
/////////////////////////////////////////////////////////////////////////////////////////////////////
	else
	{	
			if(GetKeyState(VK_LEFT)==KEY_PUSH || GetKeyState(VK_LEFT)==KEY_HOLD || GetKeyState(VK_RIGHT)==KEY_PUSH || GetKeyState(VK_RIGHT)==KEY_HOLD){
				if((GetKeyState(VK_LEFT)==KEY_PUSH || GetKeyState(VK_LEFT)==KEY_HOLD) && CharaDrawCount>=-18){
					CharaDrawCount--;
				}else if((GetKeyState(VK_RIGHT)==KEY_PUSH || GetKeyState(VK_RIGHT)==KEY_HOLD) && CharaDrawCount<=18){
					CharaDrawCount++;
				}
			}else{
				if(CharaDrawCount<0){
					CharaDrawCount++;
				}else if(CharaDrawCount>0){
					CharaDrawCount--;
				}
			}
	}
//////////////////////////////////////////////////////////////////////////////////////////////////
yield;
}
}

sub PlayerDraw
{
	if(DSdot)
	{
		SetTexture(imgDS);
		if(FinderMode==false && GetCommonDataDefault("DefeatBossAction",false)==false)
		{
			if(GetKeyState(VK_LEFT)==KEY_PUSH || GetKeyState(VK_LEFT)==KEY_HOLD)
			{
				if(GetCommonDataDefault("TimeStop",false)==false && GetCommonDataDefault("DefeatBoss",false)==false)
				{
				SetGraphicRect(floor(CharaLeftMoveDrawCount/DrawFrame)*32, 49, floor(CharaLeftMoveDrawCount/DrawFrame+1)*32, 97);
				}
			}
			else if(GetKeyState(VK_RIGHT)==KEY_PUSH || GetKeyState(VK_RIGHT)==KEY_HOLD)
			{
				if(GetCommonDataDefault("TimeStop",false)==false && GetCommonDataDefault("DefeatBoss",false)==false)
				{
				SetGraphicRect(floor(CharaRightMoveDrawCount/DrawFrame)*32, 97, floor(CharaRightMoveDrawCount/DrawFrame+1)*32, 144);
				}
			}
			else
			{
				if(GetCommonDataDefault("TimeStop",false)==false && GetCommonDataDefault("DefeatBoss",false)==false)
				{
				SetGraphicRect(floor(CharaDrawCount/DrawFrame)*32, 1, floor(CharaDrawCount/DrawFrame+1)*32, 49);
				}
			}
		}
		else
		{
			let angle=360+atan2(Obj_GetY(CameraCoordinate)-GetPlayerY,Obj_GetX(CameraCoordinate)-GetPlayerX);
			if(angle%360>=337.5)
			{
				SetGraphicRect(0, 177, 32, 225);
			}
			else
			{
				SetGraphicRect(floor((angle%360+22.5)/45)*32, 177, floor((angle%360+22.5)/45+1)*32, 225);
			}
		}
		SetRenderState(ALPHA);
		DrawGraphic(GetPlayerX(), GetPlayerY());//自機の描画
	}
	else
	{
		SetTexture(imgPlayer);
		let dir = 0;
		if(FinderMode || GetCommonDataDefault("DefeatBossAction",false)==true)
		{
			let angle=atan2(Obj_GetY(CameraCoordinate)-GetPlayerY,Obj_GetX(CameraCoordinate)-GetPlayerX);
			dir = trunc((angle + 11.25) / 22.5);
			if(dir < 0){dir += 16;}
			else if(dir >= 16){dir -= 16;}
			let rX = 48 * dir;
			SetGraphicRect(rX, 144, rX + 48, 208);
		}
		else if(GetCommonDataDefault("TimeStop",false)==false)
		{
			SetGraphicRect(432+(48*trunc(CharaDrawCount/2)),0,48+432+(48*trunc(CharaDrawCount/2)),48);
		}
		SetRenderState(ALPHA);
		SetGraphicAngle(0,0,0);
		DrawGraphic(GetPlayerX, GetPlayerY+6);
	}
}

task Finder//ファインダーの挙動。かなり長い。
{
	//	let scax=1.5;
	//	let scay=1.15;
		let scax=1.0;
		let scay=1.0;
		let ScAngle=90;//通常時のカメラの大きさの周期変化させるための値
		let CameraRD=48;//自機からカメラ中心のまでの基本距離
		let SlowRD=0;//低速に時カメラが伸びる距離（４０まで）
		let obj=Obj_Create(OBJ_EFFECT);
		CameraCoordinate = obj;
		ObjEffect_SetTexture(obj, imgCamera);
		ObjEffect_SetPrimitiveType(obj, PRIMITIVE_TRIANGLEFAN);
		ObjEffect_SetRenderState(obj, ADD); 
		ObjEffect_CreateVertex(obj, 4);

		ObjEffect_SetVertexXY(obj, 0, -40, -30);
		ObjEffect_SetVertexXY(obj, 1, 40,  -30);
		ObjEffect_SetVertexXY(obj, 2, 40, 30);
		ObjEffect_SetVertexXY(obj, 3,  -40,  30);
		
		ObjEffect_SetVertexUV(obj, 0,  20,  100);
		ObjEffect_SetVertexUV(obj, 1,  100, 100);
		ObjEffect_SetVertexUV(obj, 2, 100,  160);
		ObjEffect_SetVertexUV(obj, 3, 20, 160);

		ObjEffect_SetScale(obj, scax,scay);
		ObjEffect_SetLayer(obj,3);
		ascent(let i in 0..4)
		{
			ObjEffect_SetVertexColor(obj,i,200,255,200,200);
		}

		Pdraw(obj);//装填率と可能、不可能を表示するタスク
		FinderPdraw(obj);//ファインダーモード時残り時間％で表示するをタスク
		FinderCircle(obj);//カメラの中心をくるくる回ってるやつ

		let ChargeAdjust=0;//高速巻き時、カメラの位置を補正するための値
		loop{
			if(Charge==100)//100%かどうかで若干大きさを変更
			{
				ObjEffect_SetScale(obj, scax-0.2+0.1*cos(ScAngle),scay-0.2+0.1*cos(ScAngle));
			}
			else
			{
				ObjEffect_SetScale(obj, scax-0.3+0.1*cos(ScAngle),scay-0.3+0.1*cos(ScAngle));
			}
			ScAngle+=10;
			if(FinderMode==false)
			{
				if((GetKeyState(VK_SHOT)==KEY_PUSH || GetKeyState(VK_SHOT)==KEY_HOLD) && (GetKeyState(VK_SLOWMOVE)==KEY_PUSH || GetKeyState(VK_SLOWMOVE)==KEY_HOLD) && Charge!=100)
				{
					Obj_SetPosition(obj,GetPlayerX+(CameraRD+ChargeAdjust)*cos(CameraAngle),GetPlayerY+(CameraRD+ChargeAdjust)*sin(CameraAngle));
					ObjEffect_SetAngle(obj,0,0,CameraAngle+CameraDir);
					if(ChargeAdjust>-48)
					{
						ChargeAdjust-=9.6;
					}
					SlowRD=0;
				}
				else if((GetKeyState(VK_SHOT)==KEY_PUSH || GetKeyState(VK_SHOT)==KEY_HOLD) && (GetKeyState(VK_SLOWMOVE)==KEY_PUSH || GetKeyState(VK_SLOWMOVE)==KEY_HOLD) && Charge==100)
				{
					Obj_SetPosition(obj,GetPlayerX+56*cos(CameraAngle),GetPlayerY+56*sin(CameraAngle));
					ObjEffect_SetAngle(obj,0,0,CameraAngle+CameraDir);
					SlowRD=0;
					ChargeAdjust=0;
				}
				else
				{
					Obj_SetPosition(obj,GetPlayerX+(CameraRD+SlowRD)*cos(CameraAngle),GetPlayerY+(CameraRD+SlowRD)*sin(CameraAngle));
					ObjEffect_SetAngle(obj,0,0,CameraAngle+CameraDir);
					ChargeAdjust=0;
				}
			}

			if(Obj_GetX(obj)<=GetClipMinX)//カメラが画面外に行かないように位置補正
			{
				Obj_SetX(obj,GetClipMinX);
			}
			if(Obj_GetX(obj)>=GetClipMaxX)
			{
				Obj_SetX(obj,GetClipMaxX);
			}
			if(Obj_GetY(obj)<=GetClipMinY)
			{
				Obj_SetY(obj,GetClipMinY);
			}
			if(Obj_GetY(obj)>=GetClipMaxY)
			{
				Obj_SetY(obj,GetClipMaxY);
			}

			if(GetKeyState(VK_SHOT)==KEY_PUSH  && (GetKeyState(VK_SLOWMOVE)==KEY_FREE || GetKeyState(VK_SLOWMOVE)==KEY_PULL )  && Charge==100 && GetCommonDataDefault("LoseBoss",false)==false)
			{
				TFinderMode(obj);//ファインダーモードに移行
				ChargeDicrease;//装填率を減らしていく。ファインダーモードの残り時間を表示するために使用。
			}

			if(GetKeyState(VK_SLOWMOVE)==KEY_PUSH || GetKeyState(VK_SLOWMOVE)==KEY_HOLD)
			{//低速時の望遠
				if(SlowRD<40)
				{
				SlowRD+=1;
				}
				if(GetCommonDataDefault("BunSpell",false)==true)
				{//専用スペルかどうかで場合わけ
					if(((GetPlayerY-GetEnemyInfo(1,ENEMY_Y))^2+(GetPlayerX-GetEnemyInfo(1,ENEMY_X))^2)^0.5>=56 && ((GetPlayerY-GetEnemyInfo(1,ENEMY_Y))^2+(GetPlayerX-GetEnemyInfo(1,ENEMY_X))^2)^0.5<=CameraRD+SlowRD)
					{//一定距離以下の場合距離補正
						Obj_SetX(obj,GetEnemyInfo(1,ENEMY_X));
						Obj_SetY(obj,GetEnemyInfo(1,ENEMY_Y));
						SlowRD-=1;
					}
					if(((GetPlayerY-GetEnemyInfo(1,ENEMY_Y))^2+(GetPlayerX-GetEnemyInfo(1,ENEMY_X))^2)^0.5<56)
					{
						Obj_SetPosition(obj,GetPlayerX+56*cos(CameraAngle),GetPlayerY+56*sin(CameraAngle));
						SlowRD-=1;
					}
				}
				else
				{
					if(((GetPlayerY-GetEnemyInfo(0,ENEMY_Y))^2+(GetPlayerX-GetEnemyInfo(0,ENEMY_X))^2)^0.5>=56 && ((GetPlayerY-GetEnemyInfo(0,ENEMY_Y))^2+(GetPlayerX-GetEnemyInfo(0,ENEMY_X))^2)^0.5<=CameraRD+SlowRD)
					{
						Obj_SetX(obj,GetEnemyInfo(0,ENEMY_X));
						Obj_SetY(obj,GetEnemyInfo(0,ENEMY_Y));
						SlowRD-=1;
					}
					if(((GetPlayerY-GetEnemyInfo(0,ENEMY_Y))^2+(GetPlayerX-GetEnemyInfo(0,ENEMY_X))^2)^0.5<56)
					{
						Obj_SetPosition(obj,GetPlayerX+56*cos(CameraAngle),GetPlayerY+56*sin(CameraAngle));
						SlowRD-=1;
					}
				}
			}
			else if(SlowRD>0)
			{
				SlowRD-=1;
			}
			//以下ファインダーモード
			if(FinderMode==true)
			{
				ascent(let i in 0..4)
				{//ファインダーモード時は見えないように
					ObjEffect_SetVertexColor(obj,i,0,255,255,255);
				}
				while(FinderMode==true){wait(1);}
				//これ以下は撮影後手元に戻るまでのコード
				ascent(let i in 0..4)
				{
					ObjEffect_SetVertexColor(obj,i,200,255,200,200);
				}
				let posX=Obj_GetX(obj);
				let posY=Obj_GetY(obj);
				loop(60)
				{
					ObjEffect_SetAngle(obj,0,0,CameraAngle+CameraDir);
					if(Charge==100)
					{
						ObjEffect_SetScale(obj, scax-0.2+0.1*cos(ScAngle),scay-0.2+0.1*cos(ScAngle));
					}
					else
					{
						ObjEffect_SetScale(obj, scax-0.3+0.1*cos(ScAngle),scay-0.3+0.1*cos(ScAngle));
					}
					ScAngle+=10;
					if((GetKeyState(VK_SHOT)==KEY_PUSH || GetKeyState(VK_SHOT)==KEY_HOLD) && (GetKeyState(VK_SLOWMOVE)==KEY_PUSH || GetKeyState(VK_SLOWMOVE)==KEY_HOLD) && Charge!=100)
					{
						if(ChargeAdjust>-50)
						{
							ChargeAdjust-=10;
						}
						SlowRD=0;
					}
					else if((GetKeyState(VK_SHOT)==KEY_PUSH || GetKeyState(VK_SHOT)==KEY_HOLD) && (GetKeyState(VK_SLOWMOVE)==KEY_PUSH || GetKeyState(VK_SLOWMOVE)==KEY_HOLD) && Charge==100)
					{
						SlowRD=0;
						ChargeAdjust=0;
					}
					else
					{
						ChargeAdjust=0;
					}
					if(GetKeyState(VK_SLOWMOVE)==KEY_PUSH || GetKeyState(VK_SLOWMOVE)==KEY_HOLD)
					{
						if(SlowRD<40)
						{
						SlowRD+=1;
						}
					}
					else if(SlowRD>0)
					{
						SlowRD-=1;
					}
				wait(1);
				}

				loop(10)
				{
					if(Charge==100)
					{
						ObjEffect_SetScale(obj, scax-0.2+0.1*cos(ScAngle),scay-0.2+0.1*cos(ScAngle));
					}
					else
					{
						ObjEffect_SetScale(obj, scax-0.3+0.1*cos(ScAngle),scay-0.3+0.1*cos(ScAngle));
					}
					ScAngle+=10;

					if((GetKeyState(VK_SHOT)==KEY_PUSH || GetKeyState(VK_SHOT)==KEY_HOLD) && (GetKeyState(VK_SLOWMOVE)==KEY_PUSH || GetKeyState(VK_SLOWMOVE)==KEY_HOLD) && Charge!=100)
					{
						Obj_SetPosition(obj,Obj_GetX(obj)+(GetPlayerX+(CameraRD+ChargeAdjust)*cos(CameraAngle)-posX)/10,Obj_GetY(obj)+(GetPlayerY+(CameraRD+ChargeAdjust)*sin(CameraAngle)-posY)/10);
						ObjEffect_SetAngle(obj,0,0,CameraAngle+CameraDir);
						if(ChargeAdjust>-50)
						{
							ChargeAdjust-=10;
						}
						SlowRD=0;
					}
					else if((GetKeyState(VK_SHOT)==KEY_PUSH || GetKeyState(VK_SHOT)==KEY_HOLD) && (GetKeyState(VK_SLOWMOVE)==KEY_PUSH || GetKeyState(VK_SLOWMOVE)==KEY_HOLD) && Charge==100)
					{
						Obj_SetPosition(obj,Obj_GetX(obj)+(GetPlayerX+55*cos(CameraAngle)-posX)/10,Obj_GetY(obj)+(GetPlayerY+55*sin(CameraAngle)-posY)/10);
						ObjEffect_SetAngle(obj,0,0,CameraAngle+CameraDir);
						SlowRD=0;
						ChargeAdjust=0;
					}
					else
					{
						Obj_SetPosition(obj,Obj_GetX(obj)+(GetPlayerX+(CameraRD+SlowRD)*cos(CameraAngle)-posX)/10,Obj_GetY(obj)+(GetPlayerY+(CameraRD+SlowRD)*sin(CameraAngle)-posY)/10);
						ObjEffect_SetAngle(obj,0,0,CameraAngle+CameraDir);
						ChargeAdjust=0;
					}
					if(GetKeyState(VK_SLOWMOVE)==KEY_PUSH || GetKeyState(VK_SLOWMOVE)==KEY_HOLD)
					{
						if(SlowRD<40)
						{
						SlowRD+=1;
						}
					}
					else if(SlowRD>0)
					{
						SlowRD-=1;
					}

					wait(1);
				}
			}
			if(GetCommonDataDefault("BunSpell",false)==true)
			{//即撮影でボスが撮れるとき色変更。専用スペルかどうかでボスＩＤが変わるため場合わけ
				if(Charge>=100 && Collision_Line_Circle(Obj_GetX(obj)-(CameraWide/2-8)*cos(CameraAngle+CameraDir-90),Obj_GetY(obj)-(CameraWide/2-8)*sin(CameraAngle+CameraDir-90),Obj_GetX(obj)+(CameraWide/2-8)*cos(CameraAngle+CameraDir-90),Obj_GetY(obj)+(CameraWide/2-8)*sin(CameraAngle+CameraDir-90),(CameraLong-8*2),GetEnemyInfo(1,ENEMY_X),GetEnemyInfo(1,ENEMY_Y),0))
				{	
					ObjEffect_SetVertexUV(obj, 0,  320,  100);
					ObjEffect_SetVertexUV(obj, 1,  400, 100);
					ObjEffect_SetVertexUV(obj, 2, 400,  160);
					ObjEffect_SetVertexUV(obj, 3, 320, 160);
				}
				else
				{	
					ObjEffect_SetVertexUV(obj, 0,  20,  100);
					ObjEffect_SetVertexUV(obj, 1,  100, 100);
					ObjEffect_SetVertexUV(obj, 2, 100,  160);
					ObjEffect_SetVertexUV(obj, 3, 20, 160);
				}
			}
			else
			{
				if(Charge>=100 && Collision_Line_Circle(Obj_GetX(obj)-(CameraWide/2-8)*cos(CameraAngle+CameraDir-90),Obj_GetY(obj)-(CameraWide/2-8)*sin(CameraAngle+CameraDir-90),Obj_GetX(obj)+(CameraWide/2-8)*cos(CameraAngle+CameraDir-90),Obj_GetY(obj)+(CameraWide/2-8)*sin(CameraAngle+CameraDir-90),(CameraLong-8*2),GetEnemyInfo(0,ENEMY_X),GetEnemyInfo(0,ENEMY_Y),0))
				{	
					ObjEffect_SetVertexUV(obj, 0,  320,  100);
					ObjEffect_SetVertexUV(obj, 1,  400, 100);
					ObjEffect_SetVertexUV(obj, 2, 400,  160);
					ObjEffect_SetVertexUV(obj, 3, 320, 160);
				}
				else
				{
					ObjEffect_SetVertexUV(obj, 0,  20,  100);
					ObjEffect_SetVertexUV(obj, 1,  100, 100);
					ObjEffect_SetVertexUV(obj, 2, 100,  160);
					ObjEffect_SetVertexUV(obj, 3, 20, 160);
				}
			}
			wait(1);
		}
}

task ChargeDicrease//装填率を減少させる。タイムアウトまでの時間を表示させるために使用
{
	wait(8);
	loop(20)
	{
		if(FinderMode==false){break;}
		Charge-=5;
		wait(1);
	}
Charge=0;
}

task FinderScale(Cobj,angle)//ファインダーモード時の４隅枠の動作、写真を取る時の殆ど黒のテクスチャもここ
{
		let scax=1.0*4/3;
		let scay=1.0;

		let dis=((CameraLong/2-25.2)^2+(CameraWide/2-16.8)^2)^0.5;

		let finderangle=atan(-192/256)+CameraDir-90;
		let obj=Obj_Create(OBJ_EFFECT);
		ObjEffect_SetTexture(obj, imgCamera);
		ObjEffect_SetPrimitiveType(obj, PRIMITIVE_TRIANGLEFAN);
		ObjEffect_SetRenderState(obj, ADD); 
		ObjEffect_CreateVertex(obj, 4);

		ObjEffect_SetVertexXY(obj, 1, -24, -24);
		ObjEffect_SetVertexXY(obj, 0, 24,  -24);
		ObjEffect_SetVertexXY(obj, 3, 24, 24);
		ObjEffect_SetVertexXY(obj, 2,  -24,  24);

		ObjEffect_SetVertexUV(obj, 0,  0,  0);
		ObjEffect_SetVertexUV(obj, 1,  120, 0);
		ObjEffect_SetVertexUV(obj, 2, 120,  80);
		ObjEffect_SetVertexUV(obj, 3, 0, 80);

		ObjEffect_SetScale(obj, scax,scay);
		ObjEffect_SetAngle(obj,0,0,angle+CameraDir);
		ObjEffect_SetLayer(obj,6);
////////////////////////////////////////////////////////////////////////////
		let finderangle2=atan(192/256)+CameraDir-90;
		let obj2=Obj_Create(OBJ_EFFECT);
		ObjEffect_SetTexture(obj2, imgCamera);
		ObjEffect_SetPrimitiveType(obj2, PRIMITIVE_TRIANGLEFAN);
		ObjEffect_SetRenderState(obj2, ADD); 
		ObjEffect_CreateVertex(obj2, 4);

		let finderangle=atan(-1.15/1.5)+CameraDir-90;
		let obj2=Obj_Create(OBJ_EFFECT);
		ObjEffect_SetTexture(obj2, imgCamera);
		ObjEffect_SetPrimitiveType(obj2, PRIMITIVE_TRIANGLEFAN);
		ObjEffect_SetRenderState(obj2, ADD); 
		ObjEffect_CreateVertex(obj2, 4);

		ObjEffect_SetVertexXY(obj2, 1, -24, -24);
		ObjEffect_SetVertexXY(obj2, 0, 24,  -24);
		ObjEffect_SetVertexXY(obj2, 3, 24, 24);
		ObjEffect_SetVertexXY(obj2, 2,  -24,  24);
	
		ObjEffect_SetVertexUV(obj2, 0,  0,  0);
		ObjEffect_SetVertexUV(obj2, 1,  120, 0);
		ObjEffect_SetVertexUV(obj2, 2, 120,  80);
		ObjEffect_SetVertexUV(obj2, 3, 0, 80);

		ObjEffect_SetScale(obj2, scax,scay);
		ObjEffect_SetAngle(obj2,0,0,angle+CameraDir);
		ObjEffect_SetLayer(obj2,6);

		ObjEffect_SetScale(obj2, scax,scay);
		ObjEffect_SetAngle(obj2,180,0,-angle-CameraDir);
		ObjEffect_SetLayer(obj2,6);
///////////////////////////////////////////////////////////////////////////////////////////
		let finderangle3=atan(-192/256)+180+CameraDir-90;
		let obj3=Obj_Create(OBJ_EFFECT);
		ObjEffect_SetTexture(obj3, imgCamera);
		ObjEffect_SetPrimitiveType(obj3, PRIMITIVE_TRIANGLEFAN);
		ObjEffect_SetRenderState(obj3, ADD); 
		ObjEffect_CreateVertex(obj3, 4);

		ObjEffect_SetVertexXY(obj3, 1, -24, -24);
		ObjEffect_SetVertexXY(obj3, 0, 24,  -24);
		ObjEffect_SetVertexXY(obj3, 3, 24, 24);
		ObjEffect_SetVertexXY(obj3, 2,  -24,  24);
	
		ObjEffect_SetVertexUV(obj3, 0,  0,  0);
		ObjEffect_SetVertexUV(obj3, 1,  120, 0);
		ObjEffect_SetVertexUV(obj3, 2, 120,  80);
		ObjEffect_SetVertexUV(obj3, 3, 0, 80);

	

		ObjEffect_SetScale(obj3, scax,scay);
		ObjEffect_SetAngle(obj3,0,0,angle+CameraDir+180);
		ObjEffect_SetLayer(obj3,6);
///////////////////////////////////////////////////////////////////////////////////////////
		let finderangle4=atan(192/256)+180+CameraDir-90;
		let obj4=Obj_Create(OBJ_EFFECT);
		ObjEffect_SetTexture(obj4, imgCamera);
		ObjEffect_SetPrimitiveType(obj4, PRIMITIVE_TRIANGLEFAN);
		ObjEffect_SetRenderState(obj4, ADD); 
		ObjEffect_CreateVertex(obj4, 4);

		ObjEffect_SetVertexXY(obj4, 1, -24, -24);
		ObjEffect_SetVertexXY(obj4, 0, 24,  -24);
		ObjEffect_SetVertexXY(obj4, 3, 24, 24);
		ObjEffect_SetVertexXY(obj4, 2,  -24,  24);
	
		ObjEffect_SetVertexUV(obj4, 0,  0,  0);
		ObjEffect_SetVertexUV(obj4, 1,  120, 0);
		ObjEffect_SetVertexUV(obj4, 2, 120,  80);
		ObjEffect_SetVertexUV(obj4, 3, 0, 80);

		ObjEffect_SetScale(obj4, scax,scay);
		ObjEffect_SetAngle(obj4,0,180,-angle-CameraDir);
		ObjEffect_SetLayer(obj4,6);
///////////////////////////////////////////////////////////////////////////////////////////
		let BGscax=4.5;
		let BGscay=3.5;
		let finderangle5=atan(192/256)+180+CameraDir-90;
		let obj5=Obj_Create(OBJ_EFFECT);
		ObjEffect_SetTexture(obj5, CameraBack);
		ObjEffect_SetPrimitiveType(obj5, PRIMITIVE_TRIANGLEFAN);
		ObjEffect_SetRenderState(obj5, ADD); 
	//	ObjEffect_SetRenderState(obj5, MULTIPLY); 
		ObjEffect_CreateVertex(obj5, 4);

		ObjEffect_SetVertexXY(obj5, 0, -1280, -1280);
		ObjEffect_SetVertexXY(obj5, 1, 1280,  -1280);
		ObjEffect_SetVertexXY(obj5, 2, 1280, 1280);
		ObjEffect_SetVertexXY(obj5, 3,  -1280,  1280);
		
		ObjEffect_SetVertexUV(obj5, 0,  0,  0);
		ObjEffect_SetVertexUV(obj5, 1,  256, 0);
		ObjEffect_SetVertexUV(obj5, 2, 256,  256);
		ObjEffect_SetVertexUV(obj5, 3, 0, 256);


		ObjEffect_SetScale(obj5, BGscax,BGscay);
		ObjEffect_SetAngle(obj5,0,0,angle+CameraDir);
		ObjEffect_SetLayer(obj5,6);
		Obj_SetPosition(obj5,Obj_GetX(Cobj),Obj_GetY(Cobj));
			ascent(let i in 0..4)
			{
				ObjEffect_SetVertexColor(obj5,i,100,255,255,255);
				ObjEffect_SetVertexColor(obj,i,150,255,255,255);
				ObjEffect_SetVertexColor(obj2,i,150,255,255,255);
				ObjEffect_SetVertexColor(obj3,i,150,255,255,255);
				ObjEffect_SetVertexColor(obj4,i,150,255,255,255);
			}
////////////////////////////////////////////////////////////////////////////////////////////////////
		let BGscax2=1.00;
		let BGscay2=1.00;
	//	let finderangle9=atan(1.15/1.5)+180+CameraDir-90;
		let obj9=Obj_Create(OBJ_EFFECT);
	//			ObjEffect_SetTexture(obj9, CameraBack2);
		ObjEffect_SetPrimitiveType(obj9, PRIMITIVE_TRIANGLEFAN);
	//	ObjEffect_SetRenderState(obj9, ADD); 
	//	ObjEffect_SetRenderState(obj9, MULTIPLY); 
		ObjEffect_CreateVertex(obj9, 4);

		ObjEffect_SetVertexXY(obj9, 0, -117, -89);
		ObjEffect_SetVertexXY(obj9, 1, 116,  -89);
		ObjEffect_SetVertexXY(obj9, 2, 116, 90);
		ObjEffect_SetVertexXY(obj9, 3,  -117,  90);
		
		ObjEffect_SetVertexUV(obj9, 0,  0,  0);
		ObjEffect_SetVertexUV(obj9, 1,  400, 0);
		ObjEffect_SetVertexUV(obj9, 2, 400,  405);
		ObjEffect_SetVertexUV(obj9, 3, 0, 405);


		ObjEffect_SetScale(obj9, BGscax2,BGscay2);
		ObjEffect_SetAngle(obj9,0,0,angle+CameraDir);
		ObjEffect_SetLayer(obj9,6);
		Obj_SetPosition(obj9,Obj_GetX(Cobj),Obj_GetY(Cobj));
			ascent(let i in 0..4)
			{
				ObjEffect_SetVertexColor(obj9,i,255,255,255,255);
			}

///////////////////////////////////////////////////////////////////////////////////////
		let ringx=1.0;
		let ringy=1.0;
		let finderangle6=atan(192/256)+180+CameraDir-90;
		let obj6=Obj_Create(OBJ_EFFECT);
		ObjEffect_SetTexture(obj6, imgCamera);
		ObjEffect_SetPrimitiveType(obj6, PRIMITIVE_TRIANGLEFAN);
		ObjEffect_SetRenderState(obj6, ADD); 
		ObjEffect_CreateVertex(obj6, 4);

		ObjEffect_SetVertexXY(obj6, 1, -100, -100);
		ObjEffect_SetVertexXY(obj6, 0, 100,  -100);
		ObjEffect_SetVertexXY(obj6, 3, 100, 100);
		ObjEffect_SetVertexXY(obj6, 2,  -100,  100);
		
		ObjEffect_SetVertexUV(obj6, 0,  0,  180);
		ObjEffect_SetVertexUV(obj6, 1,  300, 180);
		ObjEffect_SetVertexUV(obj6, 2, 300,  480);
		ObjEffect_SetVertexUV(obj6, 3, 0, 480);

		ObjEffect_SetScale(obj6, ringx,ringy);
		ObjEffect_SetAngle(obj6,0,180,-angle-CameraDir);
		ObjEffect_SetLayer(obj6,6);
		Obj_SetPosition(obj6,Obj_GetX(Cobj),Obj_GetY(Cobj));
///////////////////////////////////////////////////////////////////////////
	let size=1;
	let CameraRadius=CameraWide/2;
	let CameraRadius2=CameraWide/2;
		ObjEffect_SetLayer(obj,4);
		ObjEffect_SetLayer(obj2,4);
		ObjEffect_SetLayer(obj3,4);
		ObjEffect_SetLayer(obj4,4);
		ObjEffect_SetLayer(obj5,4);
		ObjEffect_SetLayer(obj6,4);
		ObjEffect_SetLayer(obj9,4);
////////////////////////////////////////////////////////////////////////////////////
		ascent(let i in 0..29)
		{
			if(FinderMode==true)
			{
				Obj_SetPosition(obj,Obj_GetX(Cobj)+dis*cos(finderangle+angle-270),Obj_GetY(Cobj)+dis*sin(finderangle+angle-270));
				Obj_SetPosition(obj2,Obj_GetX(Cobj)+dis*cos(finderangle2+angle-270),Obj_GetY(Cobj)+dis*sin(finderangle2+angle-270));
				Obj_SetPosition(obj3,Obj_GetX(Cobj)+dis*cos(finderangle3+angle-270),Obj_GetY(Cobj)+dis*sin(finderangle3+angle-270));
				Obj_SetPosition(obj4,Obj_GetX(Cobj)+dis*cos(finderangle4+angle-270),Obj_GetY(Cobj)+dis*sin(finderangle4+angle-270));
				Obj_SetPosition(obj5,Obj_GetX(Cobj),Obj_GetY(Cobj));
				Obj_SetPosition(obj6,Obj_GetX(Cobj),Obj_GetY(Cobj));
				Obj_SetPosition(obj9,Obj_GetX(Cobj),Obj_GetY(Cobj));
				ObjEffect_SetScale(obj5, BGscax,BGscay);
				ObjEffect_SetScale(obj9, BGscax2,BGscay2);
				Obj_SetPosition(obj6,Obj_GetX(Cobj),Obj_GetY(Cobj));
				ObjEffect_SetScale(obj6, ringx,ringy);
			}
			if(GetKeyState(VK_SHOT)==KEY_PULL)
			{
				Obj_Delete(obj);
				Obj_Delete(obj2);
				Obj_Delete(obj3);
				Obj_Delete(obj4);
				Obj_Delete(obj6);
				SetCommonData("Shooting",true);//撮影する合図、これを元に他の表示が一時的に消えたりする
				wait(10);
				SetCommonData("Shooting",false);
				Obj_Delete(obj5);
				Obj_Delete(obj9);
				break;

			}
			if(i>=9)
			{
				BGscax-=(4.5*2/3)/20;
				BGscay-=(3.5*2/3)/20;
				BGscax2-=(1.0*2/3)/20;
				BGscay2-=(1.0*2/3)/20;
				ringx-=1/20;
				ringy-=1/20;
				CameraRadius2=CameraRadius-3.428*(i-8);
				size=CameraRadius2/CameraRadius;
				dis=((CameraLong/2*size-25.2)^2+(CameraWide/2*size-16.8)^2)^0.5;
			}
			if(GetCommonDataDefault("BunSpell",false)==true)//専用スペルかどうかで場合わけ
			{//以下撮影範囲にいるかどうかで色が変わるコード
				if(Collision_Line_Circle(Obj_GetX(Cobj)-(CameraWide/2-8)*size*cos(angle+CameraDir-90),Obj_GetY(Cobj)-(CameraWide/2-8)*size*sin(angle+CameraDir-90),Obj_GetX(Cobj)+(CameraWide/2-8)*size*cos(angle+CameraDir-90),Obj_GetY(Cobj)+(CameraWide/2-8)*size*sin(angle+CameraDir-90),(CameraLong-8*2)*size,GetEnemyInfo(1,ENEMY_X),GetEnemyInfo(1,ENEMY_Y),0))
				{
					ObjEffect_SetVertexUV(obj, 0,  300,  0);
					ObjEffect_SetVertexUV(obj, 1,  420, 0);
					ObjEffect_SetVertexUV(obj, 2, 420,  80);
					ObjEffect_SetVertexUV(obj, 3, 300, 80);
					ObjEffect_SetVertexUV(obj2, 0,  300,  0);
					ObjEffect_SetVertexUV(obj2, 1,  420, 0);
					ObjEffect_SetVertexUV(obj2, 2, 420,  80);
					ObjEffect_SetVertexUV(obj2, 3, 300, 80);
					ObjEffect_SetVertexUV(obj3, 0,  300,  0);
					ObjEffect_SetVertexUV(obj3, 1,  420, 0);
					ObjEffect_SetVertexUV(obj3, 2, 420,  80);
					ObjEffect_SetVertexUV(obj3, 3, 300, 80);
					ObjEffect_SetVertexUV(obj4, 0,  300,  0);
					ObjEffect_SetVertexUV(obj4, 1,  420, 0);
					ObjEffect_SetVertexUV(obj4, 2, 420,  80);
					ObjEffect_SetVertexUV(obj4, 3, 300, 80);
					ObjEffect_SetVertexUV(obj6, 0,  300,  180);
					ObjEffect_SetVertexUV(obj6, 1,  600, 180);
					ObjEffect_SetVertexUV(obj6, 2, 600,  480);
					ObjEffect_SetVertexUV(obj6, 3, 300, 480);
				}
				else
				{
					ObjEffect_SetVertexUV(obj, 0,  0,  0);
					ObjEffect_SetVertexUV(obj, 1,  120, 0);
					ObjEffect_SetVertexUV(obj, 2, 120,  80);
					ObjEffect_SetVertexUV(obj, 3, 0, 80);
					ObjEffect_SetVertexUV(obj2, 0,  0,  0);
					ObjEffect_SetVertexUV(obj2, 1,  120, 0);
					ObjEffect_SetVertexUV(obj2, 2, 120,  80);
					ObjEffect_SetVertexUV(obj2, 3, 0, 80);
					ObjEffect_SetVertexUV(obj3, 0,  0,  0);
					ObjEffect_SetVertexUV(obj3, 1,  120, 0);
					ObjEffect_SetVertexUV(obj3, 2, 120,  80);
					ObjEffect_SetVertexUV(obj3, 3, 0, 80);
					ObjEffect_SetVertexUV(obj4, 0,  0,  0);
					ObjEffect_SetVertexUV(obj4, 1,  120, 0);
					ObjEffect_SetVertexUV(obj4, 2, 120,  80);
					ObjEffect_SetVertexUV(obj4, 3, 0, 80);
					ObjEffect_SetVertexUV(obj6, 0,  0,  180);
					ObjEffect_SetVertexUV(obj6, 1,  300, 180);
					ObjEffect_SetVertexUV(obj6, 2, 300,  480);
					ObjEffect_SetVertexUV(obj6, 3, 0, 480);
				}
			}
			else
			{
				if(Collision_Line_Circle(Obj_GetX(Cobj)-(CameraWide/2-8)*size*cos(angle+CameraDir-90),Obj_GetY(Cobj)-(CameraWide/2-8)*size*sin(angle+CameraDir-90),Obj_GetX(Cobj)+(CameraWide/2-8)*size*cos(angle+CameraDir-90),Obj_GetY(Cobj)+(CameraWide/2-8)*size*sin(angle+CameraDir-90),(CameraLong-8*2)*size,GetEnemyInfo(0,ENEMY_X),GetEnemyInfo(0,ENEMY_Y),0))
				{
					ObjEffect_SetVertexUV(obj, 0,  300,  0);
					ObjEffect_SetVertexUV(obj, 1,  420, 0);
					ObjEffect_SetVertexUV(obj, 2, 420,  80);
					ObjEffect_SetVertexUV(obj, 3, 300, 80);
					ObjEffect_SetVertexUV(obj2, 0,  300,  0);
					ObjEffect_SetVertexUV(obj2, 1,  420, 0);
					ObjEffect_SetVertexUV(obj2, 2, 420,  80);
					ObjEffect_SetVertexUV(obj2, 3, 300, 80);
					ObjEffect_SetVertexUV(obj3, 0,  300,  0);
					ObjEffect_SetVertexUV(obj3, 1,  420, 0);
					ObjEffect_SetVertexUV(obj3, 2, 420,  80);
					ObjEffect_SetVertexUV(obj3, 3, 300, 80);
					ObjEffect_SetVertexUV(obj4, 0,  300,  0);
					ObjEffect_SetVertexUV(obj4, 1,  420, 0);
					ObjEffect_SetVertexUV(obj4, 2, 420,  80);
					ObjEffect_SetVertexUV(obj4, 3, 300, 80);
					ObjEffect_SetVertexUV(obj6, 0,  300,  180);
					ObjEffect_SetVertexUV(obj6, 1,  600, 180);
					ObjEffect_SetVertexUV(obj6, 2, 600,  480);
					ObjEffect_SetVertexUV(obj6, 3, 300, 480);
				}
				else
				{
					ObjEffect_SetVertexUV(obj, 0,  0,  0);
					ObjEffect_SetVertexUV(obj, 1,  120, 0);
					ObjEffect_SetVertexUV(obj, 2, 120,  80);
					ObjEffect_SetVertexUV(obj, 3, 0, 80);
					ObjEffect_SetVertexUV(obj2, 0,  0,  0);
					ObjEffect_SetVertexUV(obj2, 1,  120, 0);
					ObjEffect_SetVertexUV(obj2, 2, 120,  80);
					ObjEffect_SetVertexUV(obj2, 3, 0, 80);
					ObjEffect_SetVertexUV(obj3, 0,  0,  0);
					ObjEffect_SetVertexUV(obj3, 1,  120, 0);
					ObjEffect_SetVertexUV(obj3, 2, 120,  80);
					ObjEffect_SetVertexUV(obj3, 3, 0, 80);
					ObjEffect_SetVertexUV(obj4, 0,  0,  0);
					ObjEffect_SetVertexUV(obj4, 1,  120, 0);
					ObjEffect_SetVertexUV(obj4, 2, 120,  80);
					ObjEffect_SetVertexUV(obj4, 3, 0, 80);
					ObjEffect_SetVertexUV(obj6, 0,  0,  180);
					ObjEffect_SetVertexUV(obj6, 1,  300, 180);
					ObjEffect_SetVertexUV(obj6, 2, 300,  480);
					ObjEffect_SetVertexUV(obj6, 3, 0, 480);
				}
			}
			wait(1);	
		}

		let ad=0;
		loop(30)
		{
				ObjEffect_SetAngle(obj,0,0,angle+CameraDir+ad);
				ObjEffect_SetAngle(obj2,180,0,-angle-CameraDir+ad);
				ObjEffect_SetAngle(obj3,0,0,angle+CameraDir+180+ad);
				ObjEffect_SetAngle(obj4,0,180,-angle-CameraDir+ad);
				ad+=12;
			wait(1);
		}

		Obj_Delete(obj);
		Obj_Delete(obj2);
		Obj_Delete(obj3);
		Obj_Delete(obj4);
		Obj_Delete(obj5);
		Obj_Delete(obj6);
		Obj_Delete(obj9);
		if(FinderTimeOut){
		PlaySE(SE[0]);
		wait(10);
		DeleteSE(SE[0]);
}
}

task TFinderMode(obj)//ファインダーモードでのタスク
{
FinderScale(obj,CameraAngle);//撮影範囲を示すカメラ枠を表示
let FinderSpeed=6.6;//ファインダーモードのカメラ移動速度
Slow(1);//ファインダーモード時は1/2倍速
FinderMode=true;
SpeedChange=true;
FinderTimeOut=true;

PlaySE(SE[6]);

ascent(let i in 0..29)
{
		if(GetKeyState(VK_SHOT)==KEY_PULL)
		{
			FinderTimeOut=false;
			Shoot(obj,i,CameraAngle);//撮影タスク、iによって撮影範囲が変わる
			SpeedChange=false;
			wait(1);
			if(GetCommonDataDefault("BunSpell",false)==true)
			{
			//	wait(10);
			}
			FinderMode=false;
			break;
		}
		//以下はキー入力でカメラが動くようにするコード＆画面外にする補正用コード（ascent中）
		if((GetKeyState(VK_UP)==KEY_PUSH || GetKeyState(VK_UP)==KEY_HOLD) && GetKeyState(VK_LEFT)==KEY_FREE && GetKeyState(VK_RIGHT)==KEY_FREE)
		{
			Obj_SetPosition(obj,Obj_GetX(obj),Obj_GetY(obj)-FinderSpeed);
		}
		else if((GetKeyState(VK_DOWN)==KEY_PUSH || GetKeyState(VK_DOWN)==KEY_HOLD) && GetKeyState(VK_LEFT)==KEY_FREE && GetKeyState(VK_RIGHT)==KEY_FREE)
		{
			Obj_SetPosition(obj,Obj_GetX(obj),Obj_GetY(obj)+FinderSpeed);
		}
		else if(GetKeyState(VK_LEFT)==KEY_PUSH || GetKeyState(VK_LEFT)==KEY_HOLD)
		{
			if(GetKeyState(VK_UP)==KEY_PUSH || GetKeyState(VK_UP)==KEY_HOLD)
			{
				Obj_SetPosition(obj,Obj_GetX(obj)-FinderSpeed*(2^0.5)/2,Obj_GetY(obj)-FinderSpeed*(2^0.5)/2);
			}
			else if(GetKeyState(VK_DOWN)==KEY_PUSH || GetKeyState(VK_DOWN)==KEY_HOLD)
			{
				Obj_SetPosition(obj,Obj_GetX(obj)-FinderSpeed*(2^0.5)/2,Obj_GetY(obj)+FinderSpeed*(2^0.5)/2);
			}
			else
			{
				Obj_SetPosition(obj,Obj_GetX(obj)-FinderSpeed,Obj_GetY(obj));
			}
		}
		else if(GetKeyState(VK_RIGHT)==KEY_PUSH || GetKeyState(VK_RIGHT)==KEY_HOLD)
		{
			if(GetKeyState(VK_UP)==KEY_PUSH || GetKeyState(VK_UP)==KEY_HOLD)
			{
				Obj_SetPosition(obj,Obj_GetX(obj)+FinderSpeed*(2^0.5)/2,Obj_GetY(obj)-FinderSpeed*(2^0.5)/2);
			}
			else if(GetKeyState(VK_DOWN)==KEY_PUSH || GetKeyState(VK_DOWN)==KEY_HOLD)
			{
				Obj_SetPosition(obj,Obj_GetX(obj)+FinderSpeed*(2^0.5)/2,Obj_GetY(obj)+FinderSpeed*(2^0.5)/2);
			}
			else if(CameraAngle%360!=0)
			{
				Obj_SetPosition(obj,Obj_GetX(obj)+FinderSpeed,Obj_GetY(obj));
			}
		}
			if(Obj_GetX(obj)<=GetClipMinX)
			{
				Obj_SetX(obj,GetClipMinX);
			}
			if(Obj_GetX(obj)>=GetClipMaxX)
			{
				Obj_SetX(obj,GetClipMaxX);
			}
			if(Obj_GetY(obj)<=GetClipMinY)
			{
				Obj_SetY(obj,GetClipMinY);
			}
			if(Obj_GetY(obj)>=GetClipMaxY)
			{
				Obj_SetY(obj,GetClipMaxY);
			}
wait(1);
}

DeleteSE(SE[6]);

if(FinderTimeOut==true)
{
	ShootTimeOut;//撮影しなかった（時間切れ）で呼びだす
	SpeedChange=false;
	wait(1);
	FinderMode=false;
}
Slow(0);
wait(40);

FinderTimeOut=false;
}

task Shoot(Cobj,time,CAngle)//弾を消したりするタスク、弾の数の判定もしている（精度悪い）
{
	deleteShotTotal=0;
	deleteShotTotal2=0;

	let size=1;
	let finderangle=atan(192/256)+180+CameraDir-90;

	let dis2=(96^2+128^2)^0.5;
	let CameraRadius=96;
	let CameraRadius2=96;

	if(time>=9)
	{
		CameraRadius2=CameraRadius-3.428*(time-8);
		size=CameraRadius2/CameraRadius;
		dis2=((96*size)^2+(128*size)^2)^0.5;
	}

	let GradBasePoint=0;

	SaveSnapShot("snapshot\"~snapFile[photoNo]~".bmp",0,0,448,480);

	NiceBonusNum=GetCommonDataDefault("NiceShot",0);

	SetCommonData("CD_photoNo",photoNo);
	SetCommonData("CD_dis2",dis2);
	SetCommonData("CD_finderangle",finderangle);
	SetCommonData("CameraPositionX",Obj_GetX(Cobj));
	SetCommonData("CameraPositionY",Obj_GetY(Cobj));
	SetCommonData("CameraLong",CameraLong);
	SetCommonData("CameraWide",CameraWide);
	SetCommonData("CameraRadius",CameraWide/2);
	SetCommonData("CameraAngle",CAngle);
	SetCommonData("CameraDir",CameraDir);
	SetCommonData("CameraSize",size);

	ascent(let enemy in EnumEnemyBegin .. EnumEnemyEnd)
	{
		let enemyID = EnumEnemyGetID(enemy);
		if(Collision_Line_Circle(Obj_GetX(Cobj)-((CameraWide/2-8)*size)*cos(CAngle+CameraDir-90),Obj_GetY(Cobj)-((CameraWide/2-8)*size)*sin(CAngle+CameraDir-90),Obj_GetX(Cobj)+((CameraWide/2-8)*size)*cos(CAngle+CameraDir-90),Obj_GetY(Cobj)+((CameraWide/2-8)*size)*sin(CAngle+CameraDir-90),(CameraLong-8*2)*size,GetEnemyInfo(enemyID,ENEMY_X),GetEnemyInfo(enemyID,ENEMY_Y),0))
		{//撮影内の敵全ての敵座標にダメージを与える透明弾を出す。特定のＩＤの敵に当たった時成功かどうかの変数が変わる
			dummyshot(enemyID,GetEnemyInfo(enemyID,ENEMY_X),GetEnemyInfo(enemyID,ENEMY_Y));
		}
	}
	wait(1);//スナップショットを取る時間&dummyshotのヒット確認

	SetCommonData("PlayerPhotoTimeStop",true);

	if(GetCommonDataDefault("GradScoreSystem",true))
	{//汎用スコアシステムを使用する場合。リスクボーナス,クリアショットを計算
		let RiskPoint=80*GetEnemyShotCountEx(GetPlayerX,GetPlayerY,50,ALL);
		if(RiskPoint>=2000){RiskPoint=2000;}
		SetCommonData("RiskPoint",RiskPoint);
		SetCommonData("ClearShot",GetEnemyShotCountEx(GetPlayerX,GetPlayerY,50,ALL));
	}
///////////////////////////////////////////////////////////////////////////////////
task deleteBulletsProcess(Cobj,rad,angle,size)
{
	deleteBullets(Obj_GetX(Cobj)+(CameraLong/2-CameraWide/2)*size*cos(angle),Obj_GetY(Cobj)+(CameraLong/2-CameraWide/2)*size*sin(angle),rad*size,angle,size,1,0);
	wait(1);
	deleteBullets(Obj_GetX(Cobj)-(CameraLong/2-CameraWide/2)*size*cos(angle),Obj_GetY(Cobj)-(CameraLong/2-CameraWide/2)*size*sin(angle),rad*size,angle,size,2,0);
}


task deleteBullets(let dx,let dy,let rad,let angle,let size,let DeleteOrder,let num){
		if(DeleteOrder==1)
		{
		deleteShotTotal += GetEnemyShotCountEx(dx,dy,rad,ALL);
		ascent(i in 0..8){
			ascent(j in 0..12){
				let deleteShotNum = GetEnemyShotCountEx(dx,dy,rad,DefaultBullet[i*12+j]);
				deleteShotKind[j] = deleteShotKind[j] + deleteShotNum;
				deleteShotColor[i] = deleteShotColor[i] + deleteShotNum;
			}
		}
		DeleteEnemyShotImmediatelyInCircle(SHOT,dx,dy,rad);
		}
		if(DeleteOrder==2)
		{
		deleteShotTotal2 += GetEnemyShotCountEx(dx,dy,rad,ALL);
		ascent(i in 0..8){
			ascent(j in 0..12){
				let deleteShotNum2 = GetEnemyShotCountEx(dx,dy,rad,DefaultBullet[i*12+j]);
				deleteShotKind2[j] = deleteShotKind2[j] + deleteShotNum2;
				deleteShotColor2[i] = deleteShotColor2[i] + deleteShotNum2;
			}
		}
		DeleteEnemyShotImmediatelyInCircle(SHOT,dx,dy,rad);
		}
		wait(2);
		if(num < 2){
			rad = rad/2;
			ascent(i in 0..4){
				deleteBullets(dx +rad*cos(angle+45+i*90)*2^0.5,dy + rad*sin(angle+45+i*90)*2^0.5, rad,angle+i*90,size,DeleteOrder,num+1);
			}
		}
	}
////////////////////////////////////////////////////////////////////////////////////////
	if(BossCapture==true)
	{//dummyshotが当たった時。成功時のタスクと撮影した枚数を1増やす
		SetCommonData("SnapShootingToStage",true);
		Photo(photoNo,Cobj,CAngle,finderangle,dis2,size);
		photoNo++;
	//	BossCapture=false;
	}
	else
	{
		SetCommonData("SnapShootingToStageFalse",true);
		FalsePhoto(Cobj,CAngle,finderangle,dis2,size);
	}
	deleteBulletsProcess(Cobj,CameraWide/2,CAngle+CameraDir,size);
	SetCommonData("AllPhoto",GetCommonDataDefault("AllPhoto",0)+1);//撮影枚数+1、ステージ側で読むこむ
	PlaySE(SE[4]);

	TimeSlowEffect;//撮影した時のスロータスク
	Slow(0);

	wait(6);//弾消しタスクが終わるまで待つ時間

	if(GetCommonDataDefault("GradScoreSystem",true))
	{//汎用スコアシステムを使用する場合。弾点数計算、色計算、ベースポイント加算を行う
		//弾の種類別弾数から、それぞれの倍率に応じてGradBasePointに加算する
		let number = 0;
		ascent(i in 0..12){
			GradBasePoint += (deleteShotKind[i]+deleteShotKind2[i]) * shotPoint[i];
			number += deleteShotKind[i]+deleteShotKind2[i];
			deleteShotKind[i] = 0;
			deleteShotKind2[i] = 0;
		}
		let other = deleteShotTotal+deleteShotTotal2- number;
		GradBasePoint += other * shotPoint[12];
		//弾の色別弾数から共通データに数値を送る
		ascent(let i in 0..8)
		{
			SetCommonData(Color[i],GetCommonDataDefault(Color[i],0)+deleteShotColor[i]+deleteShotColor2[i]);
		}

		SetCommonData("BasePoint",GetCommonDataDefault("BasePoint",0)+GradBasePoint);//ベースポイントを送る
	}

	if(BossCapture==true)
	{//dummyshotが当たった時。成功時の
		loop((deleteShotTotal+deleteShotTotal2)/2)
		{//撮影内ランダム、カメラ中心からの角度を決定し発生させる。
			let rx=rand(Obj_GetX(Cobj)-(CameraLong/2)*size,Obj_GetX(Cobj)+(CameraLong/2)*size);
			let ry=rand(Obj_GetY(Cobj)-(CameraWide/2)*size,Obj_GetY(Cobj)+(CameraWide/2)*size);
			let rdis=((rx-Obj_GetX(Cobj))^2+(ry-Obj_GetY(Cobj))^2)^0.5;
			let rangle=atan2(ry-Obj_GetY(Cobj),rx-Obj_GetX(Cobj));
			ItemCreate(Cobj,photoNo,true,35,Obj_GetX(Cobj)+rdis*cos(rangle+CAngle+CameraDir),Obj_GetY(Cobj)+rdis*sin(rangle+CAngle+CameraDir));
		}
		BossCapture=false;
	}
	else
	{
		loop((deleteShotTotal+deleteShotTotal2)/2)
		{//撮影内ランダム、カメラ中心からの角度を決定し発生させる。
			let rx=rand(Obj_GetX(Cobj)-(CameraLong/2)*size,Obj_GetX(Cobj)+(CameraLong/2)*size);
			let ry=rand(Obj_GetY(Cobj)-(CameraWide/2)*size,Obj_GetY(Cobj)+(CameraWide/2)*size);
			let rdis=((rx-Obj_GetX(Cobj))^2+(ry-Obj_GetY(Cobj))^2)^0.5;
			let rangle=atan2(ry-Obj_GetY(Cobj),rx-Obj_GetX(Cobj));
			ItemCreate(Cobj,photoNo,false,55,Obj_GetX(Cobj)+rdis*cos(rangle+CAngle+CameraDir),Obj_GetY(Cobj)+rdis*sin(rangle+CAngle+CameraDir));
		}
	}
}

task Photo(No,Cobj,CAngle,finderangle,dis2,size)//成功時の写真を取ってから収めるまでの動作。
{
	let imgPhoto = "snapshot\"~snapFile[photoNo]~".bmp";
		LoadGraphic(imgPhoto);//撮った写真から読み込む

		let scax=1;
		let scay=1;
	//以下カメラの中心から画面端までの距離と角度を設定
		let OriAngle1=atan2(GetClipMinX-Obj_GetX(Cobj),GetClipMinY-Obj_GetY(Cobj));
		let OriDis1=((GetClipMinX-Obj_GetX(Cobj))^2+((GetClipMinY-Obj_GetY(Cobj))^2))^0.5;
		let OriAngle2=atan2(GetClipMaxX-Obj_GetX(Cobj),GetClipMinY-Obj_GetY(Cobj));
		let OriDis2=((GetClipMaxX-Obj_GetX(Cobj))^2+((GetClipMinY-Obj_GetY(Cobj))^2))^0.5;
		let OriAngle3=atan2(GetClipMaxX-Obj_GetX(Cobj),GetClipMaxY-Obj_GetY(Cobj));
		let OriDis3=((GetClipMaxX-Obj_GetX(Cobj))^2+((GetClipMaxY-Obj_GetY(Cobj))^2))^0.5;
		let OriAngle4=atan2(GetClipMinX-Obj_GetX(Cobj),GetClipMaxY-Obj_GetY(Cobj));
		let OriDis4=((GetClipMinX-Obj_GetX(Cobj))^2+((GetClipMaxY-Obj_GetY(Cobj))^2))^0.5;

		let DX=GetClipMaxX+40+65*((photoNo%10)%3);//一般スペルの時の写真Ｘ座標
		let DY=GetCenterY+50+65*trunc((photoNo%10)/3);//一般スペルの時の写真Ｘ座標
		let SnapSize=0.2;//そのまま。写真のサイズ
		if(GetCommonDataDefault("BunSpell",false)==true)
		{
			SnapSize=0.4;
			if((photoNo%10)<=4)
			{
				DX=GetClipMaxX+70;
				DY=GetCenterY-170+(photoNo%10)*85;
			}
			else
			{
				DX=GetClipMaxX+155;
				DY=GetCenterY-170+((photoNo%10)-5)*85;
			}
		}

//X,Yはカメラの４頂点の座標。PX,PYはカメラの中心から頂点までの成分の絶対値。
		let X=[Obj_GetX(Cobj)+dxdy(0,0,dis2,finderangle,CAngle,size),Obj_GetX(Cobj)+dxdy(CameraLong,0,dis2,finderangle,CAngle,size),Obj_GetX(Cobj)+dxdy(CameraLong,CameraWide,dis2,finderangle,CAngle,size), Obj_GetX(Cobj)+dxdy(0,CameraWide,dis2,finderangle,CAngle,size), ];
		let Y=[Obj_GetY(Cobj)+dxdy2(0,0,dis2,finderangle,CAngle,size),Obj_GetY(Cobj)+dxdy2(CameraLong,0,dis2,finderangle,CAngle,size),Obj_GetY(Cobj)+dxdy2(CameraLong,CameraWide,dis2,finderangle,CAngle,size), Obj_GetY(Cobj)+dxdy2(0,CameraWide,dis2,finderangle,CAngle,size)];
		let PX=CameraLong/2*size;
		let PY=CameraWide/2*size;

		let Distance1;//カメラの中心からボスまでの距離
		if(GetCommonDataDefault("BunSpell",false)==true)
		{
			Distance1=((GetEnemyInfo(1,ENEMY_X)-Obj_GetX(Cobj))^2+(GetEnemyInfo(1,ENEMY_Y)-Obj_GetY(Cobj))^2)^0.5;//写真の中心からボスまでの距離
		}
		else
		{
			Distance1=((GetEnemyInfo(0,ENEMY_X)-Obj_GetX(Cobj))^2+(GetEnemyInfo(0,ENEMY_Y)-Obj_GetY(Cobj))^2)^0.5;//写真の中心からボスまでの距離
		}

		let SelfPhoto=false;
		if(Collision_Line_Circle(Obj_GetX(Cobj)-(PY-12)*cos(CAngle+CameraDir-90),Obj_GetY(Cobj)-(PY-12)*sin(CAngle+CameraDir-90),Obj_GetX(Cobj)+(PY-12)*cos(CAngle+CameraDir-90),Obj_GetY(Cobj)+(PY-12)*sin(CAngle+CameraDir-90),(PX-12)*2,GetPlayerX,GetPlayerY,0))
		{//写真内に自分かいるかどうか判定
			SelfPhoto=true;
		}

		let ShootPlayerPositionX=GetPlayerX;
		let ShootPlayerPositionY=GetPlayerY;

		if(GetCommonDataDefault("BunSpell",false)==true)
		{
		loop(7){yield;}
		//wait(7);
		}

		let obj=Obj_Create(OBJ_EFFECT);
		ObjEffect_SetTexture(obj, imgPhoto);
		ObjEffect_SetPrimitiveType(obj, PRIMITIVE_TRIANGLEFAN);
	//	ObjEffect_SetRenderState(obj, ADD); 

//写真の切り取り方を決定するタスク。
		let CDAngle=CameraDir;
		ShootRange(obj,CAngle,CDAngle,X,Y,PX,PY,OriAngle1,OriDis1,OriAngle2,OriDis2,OriAngle3,OriDis3,OriAngle4,OriDis4);

		ObjEffect_SetScale(obj, scax,scay);
		ObjEffect_SetAngle(obj,0,0,CAngle+CameraDir);
		ObjEffect_SetLayer(obj,8);
		Obj_SetPosition(obj,Obj_GetX(Cobj),Obj_GetY(Cobj));


		/*	ObjEffect_SetVertexColor(obj,0,255,255,255,255);
			ObjEffect_SetVertexColor(obj,1,255,255,255,255);
			ObjEffect_SetVertexColor(obj,2,255,255,255,255);
			ObjEffect_SetVertexColor(obj,3,255,255,255,255);
*/
		let posX=Obj_GetX(obj);//徐々に移動させるために必要
		let posY=Obj_GetY(obj);
		let loopnum=10;//写真が規定座標に行くまでの時間スローのため体感時間は長いけど

		if(GetCommonDataDefault("BunSpell",false)==true)
		{
			loopnum=30;
		}

		let SnapAngle=0;//回転させるための値

		Successed;//Successed!!と表示する

///////////////////////////////////////////////////////////////////////////////////
		let BGscax2=1.00;
		let BGscay2=1.00;
	//	let finderangle9=atan(1.15/1.5)+180+CameraDir-90;
		let obj9=Obj_Create(OBJ_EFFECT);
				ObjEffect_SetTexture(obj9, CameraBack2);
		ObjEffect_SetPrimitiveType(obj9, PRIMITIVE_TRIANGLEFAN);
		ObjEffect_SetRenderState(obj9, ADD); 
	//	ObjEffect_SetRenderState(obj9, MULTIPLY); 
		ObjEffect_CreateVertex(obj9, 16);

		let VertexX=PX/2;
		let VertexY=PY/2;

		ObjEffect_SetVertexXY(obj9, 0, -VertexX*2, -VertexY*2);
		ObjEffect_SetVertexXY(obj9, 1, -VertexX,  -VertexY*2);
		ObjEffect_SetVertexXY(obj9, 2, 0, -VertexY*2);
		ObjEffect_SetVertexXY(obj9, 3,  VertexX,  -VertexY*2);
		ObjEffect_SetVertexXY(obj9, 4, VertexX*2, -VertexY*2);
		ObjEffect_SetVertexXY(obj9, 5, VertexX*2,  -VertexY);
		ObjEffect_SetVertexXY(obj9, 6, VertexX*2, 0);
		ObjEffect_SetVertexXY(obj9, 7,  VertexX*2,  VertexY);
		ObjEffect_SetVertexXY(obj9, 8, VertexX*2, VertexY*2);
		ObjEffect_SetVertexXY(obj9, 9, VertexX,  VertexY*2);
		ObjEffect_SetVertexXY(obj9, 10, 0, VertexY*2);
		ObjEffect_SetVertexXY(obj9, 11,  -VertexX,  VertexY*2);
		ObjEffect_SetVertexXY(obj9, 12, -VertexX*2, VertexY*2);
		ObjEffect_SetVertexXY(obj9, 13, -VertexX*2,  VertexY);
		ObjEffect_SetVertexXY(obj9, 14, -VertexX*2, 0);
		ObjEffect_SetVertexXY(obj9, 15,  -VertexX*2,  -VertexY);

		ObjEffect_SetVertexUV(obj9, 0,  0,  0);
		ObjEffect_SetVertexUV(obj9, 1,  100, 0);
		ObjEffect_SetVertexUV(obj9, 2, 200,  0);
		ObjEffect_SetVertexUV(obj9, 3, 300, 0);
		ObjEffect_SetVertexUV(obj9, 4, 401,  0);
		ObjEffect_SetVertexUV(obj9, 5, 401,  100);
		ObjEffect_SetVertexUV(obj9, 6, 401, 200);
		ObjEffect_SetVertexUV(obj9, 7,  401,  300);
		ObjEffect_SetVertexUV(obj9, 8,  401, 401);
		ObjEffect_SetVertexUV(obj9, 9, 300,  401);
		ObjEffect_SetVertexUV(obj9, 10, 200, 401);
		ObjEffect_SetVertexUV(obj9, 11,  100,  401);
		ObjEffect_SetVertexUV(obj9, 12,  0, 401);
		ObjEffect_SetVertexUV(obj9, 13, 0,  300);
		ObjEffect_SetVertexUV(obj9, 14, 0, 200);
		ObjEffect_SetVertexUV(obj9, 15, 0, 100);

		ObjEffect_SetScale(obj9, BGscax2,BGscay2);
		ObjEffect_SetAngle(obj9,0,0,CAngle+CameraDir);
		ObjEffect_SetLayer(obj9,8);
		Obj_SetPosition(obj9,Obj_GetX(Cobj),Obj_GetY(Cobj));
			ascent(let i in 0..16)
			{
				ObjEffect_SetVertexColor(obj9,i,150,255,255,255);
			}
	ascent(let j in 0..4)
	{
		ascent(let i in 0..5)
		{
			if((X[j]*(5-i)+X[(j+1)%4]*i)/5<GetClipMinX || (Y[j]*(5-i)+Y[(j+1)%4]*i)/5<GetClipMinY || (X[j]*(5-i)+X[(j+1)%4]*i)/5>GetClipMaxX || (Y[j]*(5-i)+Y[(j+1)%4]*i)/5>GetClipMaxY)
			{
				ObjEffect_SetVertexColor(obj9,j*4+i,0,50,50,50);
			}
		}
	}
//////////////////////////////////////////////////////////////////////////
	if(GetCommonDataDefault("BunSpell",false)==false)
	{
		loop(loopnum)
		{
			Obj_SetPosition(obj,Obj_GetX(obj)+(DX-posX)/loopnum,Obj_GetY(obj)+(DY-posY)/loopnum);
			ObjEffect_SetScale(obj, scax,scay);
			scax-=(1-SnapSize)/loopnum;
			scay-=(1-SnapSize)/loopnum;
			SnapAngle+=360/loopnum;
			ObjEffect_SetAngle(obj,0,0,CAngle+CameraDir+SnapAngle);

			Obj_SetPosition(obj9,Obj_GetX(obj9)+(DX-posX)/loopnum,Obj_GetY(obj9)+(DY-posY)/loopnum);
			ObjEffect_SetScale(obj9, BGscax2,BGscay2);
			BGscax2-=(1-SnapSize)/loopnum;
			BGscay2-=(1-SnapSize)/loopnum;
			ObjEffect_SetAngle(obj9,0,0,CAngle+CameraDir+SnapAngle);

			wait(1);
		}
	}
			Obj_SetPosition(obj,DX,DY);
			Obj_SetPosition(obj9,DX,DY);
			scax=SnapSize;
			scay=SnapSize;
			ObjEffect_SetScale(obj, scax,scay);
			ObjEffect_SetScale(obj9, scax,scay);
			BGscax2-=SnapSize/loopnum;
			BGscay2-=SnapSize/loopnum;
		PlaySE(SE[1]);

PhotoSelectAndEraze(obj,obj9,No,DX,DY, scax,scay);

AddShootingScore("AYA",Cobj,CAngle,PX,PY,No,SelfPhoto,Distance1,ShootPlayerPositionX,ShootPlayerPositionY);//スコア計算文とはたてで違うのはセルフショット判定
loop
{
	if(GetCommonDataDefault("DetailShooting",false)==true)
	{
		ascent(let i in 0..16)
		{
			ObjEffect_SetVertexColor(obj,i,0,255,255,255);
			ObjEffect_SetVertexColor(obj9,i,0,255,255,255);
		}
	}
	else
	{
		ShootRange(obj,CAngle,CDAngle,X,Y,PX,PY,OriAngle1,OriDis1,OriAngle2,OriDis2,OriAngle3,OriDis3,OriAngle4,OriDis4);
		ascent(let i in 0..4)
		{
			ObjEffect_SetVertexColor(obj,i,255,255,255,255);
		}
		ascent(let i in 0..16)
		{
			ObjEffect_SetVertexColor(obj9,i,150,255,255,255);
		}
		ascent(let j in 0..4)
		{
			ascent(let i in 0..5)
			{
				if((X[j]*(5-i)+X[(j+1)%4]*i)/5<GetClipMinX || (Y[j]*(5-i)+Y[(j+1)%4]*i)/5<GetClipMinY || (X[j]*(5-i)+X[(j+1)%4]*i)/5>GetClipMaxX || (Y[j]*(5-i)+Y[(j+1)%4]*i)/5>GetClipMaxY)
				{
					ObjEffect_SetVertexColor(obj9,j*4+i,0,50,50,50);
				}
			}
		}
	}

//wait(1);
yield;
}
}

task PhotoSelectAndEraze(obj,obj9,No,DX,DY, scax,scay)
{
		while(photoNo<No+11)
		{//１１枚以上になったら１枚目から順に破棄。専用スペルではまず使わないはず。
			if(GetCommonDataDefault("ShootingEnd",false)==true)
			{
				PhotoSelect(obj,obj9,No,DX,DY, scax,scay);
			}
			if(GetCommonDataDefault("PhotoEraze",false)==true)
			{
				Obj_Delete(obj);
				break;
			}
			//wait(1);
		yield;
		}
		Obj_Delete(obj);
		Obj_Delete(obj9);
}

task FalsePhoto(Cobj,CAngle,finderangle,dis2,size)//失敗時の写真を取ってから捨てるまでの動作。
{//成功時と殆ど変わらない。BasePointを初期化すること
	let imgPhoto = "snapshot\"~snapFile[photoNo]~".bmp";
		LoadGraphic(imgPhoto);
		let scax=1;
		let scay=1;

		let X=[Obj_GetX(Cobj)+dxdy(0,0,dis2,finderangle,CAngle,size),Obj_GetX(Cobj)+dxdy(CameraLong,0,dis2,finderangle,CAngle,size),Obj_GetX(Cobj)+dxdy(CameraLong,CameraWide,dis2,finderangle,CAngle,size), Obj_GetX(Cobj)+dxdy(0,CameraWide,dis2,finderangle,CAngle,size), ];
		let Y=[Obj_GetY(Cobj)+dxdy2(0,0,dis2,finderangle,CAngle,size),Obj_GetY(Cobj)+dxdy2(CameraLong,0,dis2,finderangle,CAngle,size),Obj_GetY(Cobj)+dxdy2(CameraLong,CameraWide,dis2,finderangle,CAngle,size), Obj_GetY(Cobj)+dxdy2(0,CameraWide,dis2,finderangle,CAngle,size)];
		let PX=CameraLong/2*size;
		let PY=CameraWide/2*size;
		let OriAngle1=atan2(GetClipMinX-Obj_GetX(Cobj),GetClipMinY-Obj_GetY(Cobj));
		let OriDis1=((GetClipMinX-Obj_GetX(Cobj))^2+((GetClipMinY-Obj_GetY(Cobj))^2))^0.5;
		let OriAngle2=atan2(GetClipMaxX-Obj_GetX(Cobj),GetClipMinY-Obj_GetY(Cobj));
		let OriDis2=((GetClipMaxX-Obj_GetX(Cobj))^2+((GetClipMinY-Obj_GetY(Cobj))^2))^0.5;
		let OriAngle3=atan2(GetClipMaxX-Obj_GetX(Cobj),GetClipMaxY-Obj_GetY(Cobj));
		let OriDis3=((GetClipMaxX-Obj_GetX(Cobj))^2+((GetClipMaxY-Obj_GetY(Cobj))^2))^0.5;
		let OriAngle4=atan2(GetClipMinX-Obj_GetX(Cobj),GetClipMaxY-Obj_GetY(Cobj));
		let OriDis4=((GetClipMinX-Obj_GetX(Cobj))^2+((GetClipMaxY-Obj_GetY(Cobj))^2))^0.5;

		let Distance1;//カメラの中心からボスまでの距離
		if(GetCommonDataDefault("BunSpell",false)==true)
		{
			Distance1=((GetEnemyInfo(1,ENEMY_X)-Obj_GetX(Cobj))^2+(GetEnemyInfo(1,ENEMY_Y)-Obj_GetY(Cobj))^2)^0.5;//写真の中心からボスまでの距離
		}
		else
		{
			Distance1=((GetEnemyInfo(0,ENEMY_X)-Obj_GetX(Cobj))^2+(GetEnemyInfo(0,ENEMY_Y)-Obj_GetY(Cobj))^2)^0.5;//写真の中心からボスまでの距離
		}

		let SelfPhoto=false;
		if(Collision_Line_Circle(Obj_GetX(Cobj)-(PY-12)*cos(CAngle+CameraDir-90),Obj_GetY(Cobj)-(PY-12)*sin(CAngle+CameraDir-90),Obj_GetX(Cobj)+(PY-12)*cos(CAngle+CameraDir-90),Obj_GetY(Cobj)+(PY-12)*sin(CAngle+CameraDir-90),(PX-12)*2,GetPlayerX,GetPlayerY,0))
		{//写真内に自分かいるかどうか判定
			SelfPhoto=true;
		}

		let ShootPlayerPositionX=GetPlayerX;
		let ShootPlayerPositionY=GetPlayerY;

		wait(10);
/*		let obj=Obj_Create(OBJ_EFFECT);
		ObjEffect_SetTexture(obj, imgPhoto);
		ObjEffect_SetPrimitiveType(obj, PRIMITIVE_TRIANGLEFAN);
	//	ObjEffect_SetRenderState(obj, ADD); 
		ObjEffect_CreateVertex(obj, 4);
		let CDAngle=CameraDir;
		ShootRange(obj,CAngle,CDAngle,X,Y,PX,PY,OriAngle1,OriDis1,OriAngle2,OriDis2,OriAngle3,OriDis3,OriAngle4,OriDis4);

		ObjEffect_SetScale(obj, scax,scay);
		ObjEffect_SetAngle(obj,0,0,CAngle+CameraDir);
		ObjEffect_SetLayer(obj,8);
		Obj_SetPosition(obj,Obj_GetX(Cobj),Obj_GetY(Cobj));

		let DX=Obj_GetX(Cobj);
		let DY=Obj_GetY(Cobj)+60;
		let posX=Obj_GetX(obj);
		let posY=Obj_GetY(obj);
		let loopnum=10;
		if(GetCommonDataDefault("BunSpell",false)==true)
		{
			loopnum=30;
		}
		let SnapAngle=0;

		loop(loopnum)
		{
			Obj_SetPosition(obj,Obj_GetX(obj)+(DX-posX)/loopnum,Obj_GetY(obj)+(DY-posY)/loopnum);
			ObjEffect_SetScale(obj, scax,scay);
			scax-=4/5/loopnum;
			scay-=4/5/loopnum;
			SnapAngle+=360/loopnum;
			ObjEffect_SetAngle(obj,0,0,CAngle+CameraDir+SnapAngle);
			wait(1);
		}
		Obj_Delete(obj);
*/
		AddShootingScore("AYA",Cobj,CAngle,PX,PY,-5,SelfPhoto,Distance1,ShootPlayerPositionX,ShootPlayerPositionY);//スコア計算文とはたてで違うのはセルフショット判定
		PlaySE(SE[0]);
		Failed;
		wait(10);
		DeleteSE(SE[0]);
		SetCommonData("BasePoint",0);
		wait(30);
		DeleteGraphic(imgPhoto);
}

task CameraAngleChange//キー入力によってカメラ角が変わるタスクabsoluteとかはブレ防止用
{
let angle;
loop
{
if(FinderMode==false)
{
	if(GetCommonDataDefault("BunSpell",false)==true)
	{
		angle=atan2(GetEnemyInfo(1,ENEMY_Y)-GetPlayerY,GetEnemyInfo(1,ENEMY_X)-GetPlayerX);
	}
	else
	{
		angle=atan2(GetEnemyInfo(0,ENEMY_Y)-GetPlayerY,GetEnemyInfo(0,ENEMY_X)-GetPlayerX);
	}
	loop(10)
	{
	if(GetKeyState(VK_SLOWMOVE)==KEY_FREE && GetKeyState(VK_UP)==KEY_FREE && GetKeyState(VK_DOWN)==KEY_FREE && GetKeyState(VK_LEFT)==KEY_FREE && GetKeyState(VK_RIGHT)==KEY_FREE)
	{
			if((absolute(sin(CameraAngle-angle))>=0.01 || sin(CameraAngle%360-angle)<=0))
			{
				if(sin(CameraAngle-angle)>=0)
				{
					CameraAngle-=0.5;
				}
				else
				{
					CameraAngle+=0.5;
				}
			}
	}	
	else if(GetKeyState(VK_SLOWMOVE)==KEY_PUSH || GetKeyState(VK_SLOWMOVE)==KEY_HOLD)
	{
			if((absolute(sin(CameraAngle-angle))>=0.01 || sin(CameraAngle%360-angle)<=0))
			{
				if(sin(CameraAngle-angle)>=0)
				{
					CameraAngle-=2;
				}
				else
				{
					CameraAngle+=2;
				}
			}
	}
	else
	{
		if((GetKeyState(VK_UP)==KEY_PUSH || GetKeyState(VK_UP)==KEY_HOLD) && GetKeyState(VK_LEFT)==KEY_FREE && GetKeyState(VK_RIGHT)==KEY_FREE)
		{
			if(absolute(sin(CameraAngle+90))>=0.01 || sin(CameraAngle%360+180)<=0)
			{
				if(sin(CameraAngle+90)>=0)
				{
					CameraAngle-=0.5;
				}
				else
				{
					CameraAngle+=0.5;
				}
			}
		}
		else if((GetKeyState(VK_DOWN)==KEY_PUSH || GetKeyState(VK_DOWN)==KEY_HOLD) && GetKeyState(VK_LEFT)==KEY_FREE && GetKeyState(VK_RIGHT)==KEY_FREE)
		{
			if(absolute(sin(CameraAngle+90))>=0.01 || sin(CameraAngle%360+180)>=0)
			{
				if(sin(CameraAngle+270)>=0)
				{
					CameraAngle-=0.5;
				}
				else
				{
					CameraAngle+=0.5;
				}
			}
		}
		else if(GetKeyState(VK_LEFT)==KEY_PUSH || GetKeyState(VK_LEFT)==KEY_HOLD)
		{
			if(GetKeyState(VK_UP)==KEY_PUSH || GetKeyState(VK_UP)==KEY_HOLD)
			{
				if(absolute(sin(CameraAngle+135))>=0.01 || sin(CameraAngle%360+225)<=0)
				{
					if(sin(CameraAngle+135)>=0)
					{
						CameraAngle-=0.5;
					}
					else
					{
						CameraAngle+=0.5;
					}
				}
			}
			else if(GetKeyState(VK_DOWN)==KEY_PUSH || GetKeyState(VK_DOWN)==KEY_HOLD)
			{
				if(absolute(sin(CameraAngle+225))>=0.01 || sin(CameraAngle%360+315)<=0)
				{
					if(sin(CameraAngle+225)>=0)
					{
						CameraAngle-=0.5;
					}
					else
					{
						CameraAngle+=0.5;
					}
				}
			}
			else if(CameraAngle%360!=180)
			{
			if(absolute(sin(CameraAngle+180))>=0.02 || cos(CameraAngle%360+270)>=0)
			{
				if(sin(CameraAngle+180)>=0)
				{
					CameraAngle-=0.5;
				}
				else
				{
					CameraAngle+=0.5;
				}
			}
			}
		}
		else if(GetKeyState(VK_RIGHT)==KEY_PUSH || GetKeyState(VK_RIGHT)==KEY_HOLD)
		{
			if(GetKeyState(VK_UP)==KEY_PUSH || GetKeyState(VK_UP)==KEY_HOLD)
			{
				if(absolute(sin(CameraAngle+45))>=0.01 || sin(CameraAngle%360+135)<=0)
				{
					if(sin(CameraAngle+45)>=0)
					{
						CameraAngle-=0.5;
					}
					else
					{
						CameraAngle+=0.5;
					}
				}
			}
			else if(GetKeyState(VK_DOWN)==KEY_PUSH || GetKeyState(VK_DOWN)==KEY_HOLD)
			{
				if(absolute(sin(CameraAngle-45))>=0.01 || sin(CameraAngle%360+45)<=0)
				{
					if(sin(CameraAngle-45)>=0)
					{
						CameraAngle-=0.5;
					}
					else
					{
						CameraAngle+=0.5;
					}
				}
			}
			else if(CameraAngle%360!=0)
			{
				if(absolute(sin(CameraAngle+180))>=0.01 || sin(CameraAngle%360+270)>=0)
				{
					if(sin(CameraAngle+180)>=0)
					{
						CameraAngle+=0.5;
					}
					else
					{
						CameraAngle-=0.5;
					}
				}
			}
		}
	}
	}
}
else
{
	while(FinderMode==true){wait(1);}
	wait(60);
}
if(CameraAngle>=360){CameraAngle=0.001;}
if(CameraAngle<=0){CameraAngle=360;}
wait(1);
}
}
#include_script".\..\txt\Pdraw.txt"//装填率や可能不可能表示
#include_script".\..\txt\Cdraw.txt"//.自機魔方陣や当たり判定
#include_script".\..\txt\data.txt"//wait関数のみ
#include_script".\..\txt\CommonData.txt"
#include_script".\..\txt\VariableCommonData.txt"
#include_script".\Config.txt"
}
