#東方弾幕風[Player]
#ScriptVersion[2] 
#Menu[射命丸文]
#Text[]
#ReplayName[文]
script_player_main
{
	#include_script".\..\secret\Config.txt"
	let csd = GetCurrentScriptDirectory();
	let imgDS = csd~"..\secret\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 ShootBack=csd~"..\img\shoot.png";
	let imgMissEffect=csd~"..\img\effect_circle.png";
	let imgMissEffect2=csd~"..\img\effect_tiny.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=6;
	let CameraCoordinate;

	let CameraLong=256;
	let CameraWide=192;
	let CameraShrinkage=3.428;
	let FinderSpeed=6.6;//ファインダーモードのカメラ移動速度

	let snapFile=[];
	ascent(let i in 0..20)
	{
		snapFile=snapFile~["DSAya"~NumToStringNoComplete(i)];
	}

	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",csd~"..\se\sha01"];
	if(DSChargeFinishSE){SE[2]=csd~"..\secret\se\se_ch01";}
	if(DSChargeFinishSE){SE[7]=csd~"..\secret\se\se_focusfix";}
	if(DSChargeFinishSE){SE[8]=csd~"..\secret\se\se_focusfix2";}

	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
	{
		SetInitialBombCount(3);
		if(DSdot==true)
		{
			SetPlayerLifeImage(imgDS, 0, 0, 48, 48);
		}
		else
		{
			SetPlayerLifeImage(imgPlayer, 384, 0, 432, 48);
		}
		LoadGraphic(imgPlayer);
		LoadGraphic(imgDS);
		LoadGraphic(imgSpell);
		LoadGraphic(imgBorder);
		LoadGraphic(imgCamera);
		LoadGraphic(CameraBack);
		LoadGraphic(CameraBack2);
		LoadGraphic(ShootBack);
		LoadGraphic(imgMissEffect);
		LoadGraphic(imgMissEffect2);
		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);
		AddBomb(-1);
		if(GetCommonDataDefault("ReplayMode",false)==false)
		{
		Cdraw;//自機中心の陣の描画タスク
		atari;
		CheckItem;
		Finder(20,100,100,160);//ファインダー制御
		CameraDirChange;//カメラの回転を制御
		CameraAngleChange;//カメラ角を制御
		SetSpeedChange;//スピードを三段階で制御
		ChargeFilm;//装填速度を制御
		ChargeFilmSE;
		ChargeFilmFinishSE;
		PhotoSelectChange;
		PlayerDrawCount;
		MissJudg;
		}
		else
		{
		SetSpeed(0, 0);
		}
		LoadDoubleSpoilerData;//開始してから60F後に読み込むデータ。スペル側で設定される。弾ごとのスコアのみ
	}

	@MainLoop
	{
		if(GetCommonDataDefault("BunSpell",false)==false && KeyStateBomb=="PUSH" && OnMissed==false && OnBorderOfLife==false && IsForbidBomb==false){AddBomb(1);}
		if(GetCommonDataDefault("DefeatBossAction",false)==false)
		{
		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)==false)
		{
			if(GetPlayerBomb==0 && GetPlayerLife>=2){ExtendPlayer(-1);AddBomb(3);}
			CallSpellCard;
		}
		}

	@SpellCard
	{		

	}

	@DrawLoop
	{
	//DrawText(deleteShotColor[0],100,50,12,200);
	//DrawText(GetCommonDataDefault(Color[0],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);
	CdrawPos;//自機中心の陣の位置タスク
	PlayerDraw;
	atariPos;
	}

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

task CameraAngleChange//キー入力によってカメラ角が変わるタスクabsoluteとかはブレ防止用
{
let angle=270;
loop
{
if(FinderMode==false)
{
	if(GetCommonDataDefault("BunSpell",false)==true)
	{
		angle=atan2(GetEnemyInfo(1,ENEMY_Y)-GetPlayerY,GetEnemyInfo(1,ENEMY_X)-GetPlayerX);
	}
	else
	{
		let ID=sarch;
		angle=270;
		if(ID!=-1)
		{
			angle=atan2(GetEnemyInfo(ID,ENEMY_Y)-GetPlayerY,GetEnemyInfo(ID,ENEMY_X)-GetPlayerX);
		}
	}
	loop(10)
	{
	if(KeyStateSlowMove=="FREE" && KeyStateUp=="FREE" && KeyStateDown=="FREE" && KeyStateLeft=="FREE" && KeyStateRight=="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(KeyStateSlowMove=="PUSH" || KeyStateSlowMove=="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((KeyStateUp=="PUSH" || KeyStateUp=="HOLD") && KeyStateLeft=="FREE" && KeyStateRight=="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((KeyStateDown=="PUSH" || KeyStateDown=="HOLD") && KeyStateLeft=="FREE" && KeyStateRight=="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(KeyStateLeft=="PUSH" || KeyStateLeft=="HOLD")
		{
			if(KeyStateUp=="PUSH" || KeyStateUp=="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(KeyStateDown=="PUSH" || KeyStateDown=="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(KeyStateRight=="PUSH" || KeyStateRight=="HOLD")
		{
			if(KeyStateUp=="PUSH" || KeyStateUp=="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(KeyStateDown=="PUSH" || KeyStateDown=="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);
}
}

function sarch
{
	let TargetID=-1;
	ascent(enemy in EnumEnemyBegin..EnumEnemyBegin+1)
	{
		let enemyID = EnumEnemyGetID(enemy);
		if(TargetID<=enemyID)
		{
			TargetID=enemyID;
		}
	}
	return TargetID;
}

#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"

}
