

	let THdot=0;



let NsScore = "SAVE_SCORE";	//スコア
let NsHi = "HI_SCORE";	//ハイスコア(NsScore)

let NsAchievement=[];
ascent(i in 0..100)
{
NsAchievement=NsAchievement~["Achievement_"~NumToStringNoComplete(i)];
}

	let MagicAbsorbShortRange=60;
	let MagicAbsorbLongRange=150;

	let AutoReCharge=0.625;
	let GrazeRadius=0;
	let AutoItemCollectLine=176;
	let BurstErazeCircleRangeRate=2.0;
	let LightMode=0;
	let count=0;
	let Power=0;		//Power管理変数
	let ReChargePower=0;	//リチャージPower管理変数
	let MagicCounter=0;	//マジックカウンター管理変数
	let MagicFragment=0;
	let SectionMagicFragment=0;
	let opX=[0,1,2,3];	//オプションのX座標
	let opY=[0,1,2,3];	//オプションのY座標
	let OpAngle=0;
	let csd = GetCurrentScriptDirectory();
//	let img = csd~"..\img\STG_Player11.png";
//	let THimg=csd~"..\img\pl01.png";
	let imgPlayer;

	let imgKekkai = csd~"..\img\circle.png";
	let imgShot3 = csd~"..\img\Reimu_shots.png";
	let imgMarisaShot = csd~"..\img\Marisa_shots.png";
	let imgBorderLine = csd~"..\img\SampleEC01a.png";
	let imgWhite = csd~"..\img\White.png";
	let imgBer = csd~"..\img\ber.png";
	let imgNebura = csd~"..\img\nebura.png";
	let imgNumber = csd~"..\img\Number.png";
	let imgNumberDraw = csd~"..\img\NumberDraw.png";
	let imgItem = csd~"..\img\Item.png";
	let imgAtari = csd~"..\img\Atari.png";
	let imgThunder = csd~"..\img\Thunder.png";
	let imgLight = csd~"..\img\Light.png";
	let imgWhite = csd~"..\img\White.png";
	let imgBreakCircleEffect=csd ~ "..\..\img/circle.png";
	let imgItemStar = csd~"..\img\ItemStar.png";

	let imgIneDeltaLine=csd ~ "..\img/IneDeltaLine.png";

	let shotCount = -1;
	let ShotCountIncrease=0;

	let RaiseAutoBomb=false;

	let BurstMode=0;//バースト発動中かどうかの変数
	let BurstModeCount=0;//バーストが発動できるまでの時間
	let DeleteBulletReCharge=0;
	let MagicOpAnglePlus=0;
	let RushGauge=0;
	let OnCansellBomb=0;

	let OnWeak=0;
	let WeaknessCount=0;
let RashFlag=false;
let CoolFlag=false;

let PurityRate=1;
let PurityRateCount=0;

let EliminateMode=false;
let EliminateIntensity=1000;

let PNRate=0;

let OnHiSpeedBomb=false;
let OnLowSpeedBomb=false;

	let miss=0;
	let BurstLevel=0;
	let BurstRank=0;
	let BL3=4/3;

	let BorderTime=0;
	let BorderTimeCount=0;

	let ColorRed=255;
	let ColorGreen=0;
	let ColorBlue=0;

	let Sol=0;
	let Luna=0;
	let Stella=0;
	let Terra=0;
	let Mare=0;
	let Caelum=0;

	let PlayerRectLeft=10;
	let PlayerRectUp=38;
	let PlayerRectRight=2;
	let PlayerRectDown=48;

	let OptionRectLeft;
	let OptionRectUp;
	let OptionRectRight;
	let OptionRectDown;

let CharaDrawCount=0;
let DrawFrame=6;
let CharaLeftMoveDrawCount=0;
let CharaRightMoveDrawCount=0;


let UseMasterSparkCount=0;
let UseCancelBombCount=0;
let UseBurstCount=0;
let UseRushBurstCount=0;
let UseAutoBombCount=0;

let KakaeBombNum=0;

let MissTime=0;

let OnShot=1;
let OnSlow=1;

let RockOnAvailable=false;
let RockOnAvailableCounter=0;
let RockON=[false,false,false,false];
let TargetX=[-1,-1,-1,-1];
let TargetY=[-1,-1,-1,-1];
let OnOpShot=[0,0,0,0];

sub IntializeTask
{
	LoadPlayerShotData(csd~"..\txt\ShotData.txt");
	SetItemCollectLine(AutoItemCollectLine);//アイテム回収されるy座標
	SetGrazeCircle(GrazeRadius);//自機のかすり判定
	SetRebirthFrame(BorderTime+1);//食らいボムの有効フレーム
	SetRebirthFrameReduction(0);//食らいボムの減少フレーム
}

sub IntializeLoading
{
		if(THdot)
		{
		imgPlayer=csd~"..\img\pl01.png";
		}
		else
		{
		imgPlayer=csd~"..\img\STG_Player11.png";
		}
		LoadGraphic(imgPlayer);

		LoadGraphic(imgKekkai);
		LoadGraphic(imgShot3);
		LoadGraphic(imgMarisaShot);
		LoadGraphic(imgBorderLine);
		LoadGraphic(imgBer);
		LoadGraphic(imgNebura);
		LoadGraphic(imgNumber);
		LoadGraphic(imgItem);
		LoadGraphic(imgAtari);
		LoadGraphic(imgThunder);
		LoadGraphic(imgLight);
		LoadGraphic(imgWhite);
		LoadGraphic(imgBreakCircleEffect);
		LoadGraphic(imgItemStar);
		LoadGraphic(imgIneDeltaLine);
}

sub IntializeTmain
{
		if(!IsCommonDataAreaExists(NsScore))
		{
		CreateCommonDataArea(NsScore);
		}
		SetCommonData("MSDPlayer",true);
		SetCommonData("MagicAbsorbShortRange",MagicAbsorbShortRange);
		SetCommonData("MagicAbsorbLongRange",MagicAbsorbLongRange);
		SetCommonData("BurstErazeCircleRangeRate",BurstErazeCircleRangeRate);
		CommonDataSetting;
		optionmove;//オプション位置決定タスク
		HueDifine;//グローバル色相変化タスク
	//	OptionShot;//オプションのオーラ撃ちタスク
		BurstGaugeDisplay;//バーストゲージ２種
		DeleteBulletCheck;

		if(THdot)
		{
			ThPlayerRect;//プレイヤー切抜き範囲決定タスク
			PlayerDrawCount;
		}
		else
		{
			PlayerRect;//プレイヤー切抜き範囲決定タスク
		}
		NormalShadow;
		DrawOption;
		Setting;
		BombCheck;
		SlowKeyCheck;
		MissJudg;//ミスエフェクトのタスク
		BorderTimeDifine;//喰らいボム受付時間変動
		wait(3);
		Shot;//メインショットのタスク
		SubShot;//サブショットのタスク
		INEffect;

		if(GetCommonDataDefault("SELECTEDDIFFICULT","None")!="Arrange")
		{
			Pdraw;//バーストカウンタ表示タスク
			Bdraw;//マジックカウンタ表示
			BurstRankAndRushGaugeDraw;
			BombExtend;//ボムエクステンド
			Powor;//パワー変動タスク
			CheckMagicItem;//アイテム生成配列をチェックする
			CheckAchievement;
			Rankdraw;//総フラグメント表示
			SectionRankdraw;//セクションフラグメント表示
			if(GetCommonDataDefault("SELECTEDDIFFICULT","None")=="Apocalypse")
			{
			CheckPurityRate;
			PurityRateDifine;
			PRdraw;
			PRCdraw;
			}
		}
	//	ReplaySaveSystem;
	//	ReplayLoadSystem;
	//	ReplayMove;
	//	EliminateSystem;
}

sub MainLoopTask
{
	SetIntersectionCircle(GetPlayerX, GetPlayerY, 0);//自機の当たり判定
	if(WeaknessCount>0)
	{
		WeaknessCount-=1;
	}
	SetCommonData("MissTime",MissTime);
	yield;
}

sub MissLoopTask
{
	MainLoop;
	BorderTimeCount+=1;
	if(BorderTimeCount>BorderTime)
	{
	if(GetPlayerBomb>=1 && GetCommonDataDefault("AutoBombMode",0)!=0)
	{
		RaiseAutoBomb=true;
		CallSpellCard;
	}
	else
	{
		BurstMode=0;
	}
	}
	if(OnBorderOfLife)
	{
	ObjPlayerDraw;
	}
}

sub SpellCardTask
{
		OnHiSpeedBomb=false;
		OnLowSpeedBomb=false;
		if(OnCansellBomb==1)
		{
			AddBomb(1);
		}
		else if(RaiseAutoBomb)
		{
			if(GetCommonDataDefault("AutoBombMode",0)==0.5){AddBomb(-1);}
			RaiseAutoBomb=false;
			UseSpellCard("MicroHole", 0);
			UseAutoBombCount+=1;
			SetCommonData("UseAutoBombCount",UseAutoBombCount);
		}
		else if(GetKeyState(VK_USER)==KEY_HOLD)
		{
			StartStar;
			UseCancelBombCount+=1;
			SetPlayerInvincibility(150);
			BurstMode=0;
		}	
		else if(GetKeyState(VK_SLOWMOVE)==KEY_PUSH || GetKeyState(VK_SLOWMOVE)==KEY_HOLD)
		{
			OnHiSpeedBomb=false;
			OnLowSpeedBomb=true;
			if(OnBorderOfLife)
			{
				SetCommonDataEx(NsScore,NsAchievement[86],1);
			}
			if(PlayerType=="A")
			{
			UseSpellCard("DarkNebura", 0);
			}
			if(PlayerType=="B")
			{
			UseSpellCard("StardustFixer", 0);
			}
			if(PlayerType=="C")
			{
			UseSpellCard("ElectricMS", 0);
			UseMasterSparkCount+=1;
			}
			if(PlayerType=="D")
			{
			SetCommonData("TargetX",[TargetX[0],TargetX[1],TargetX[2],TargetX[3]]);
			SetCommonData("TargetY",[TargetY[0],TargetY[1],TargetY[2],TargetY[3]]);
			UseSpellCard("StardustPulsar", 0);
			}
		}
		else
		{
			if(OnBorderOfLife)
			{
				SetCommonDataEx(NsScore,NsAchievement[86],1);
			}
			OnHiSpeedBomb=true;
			OnLowSpeedBomb=false;
			UseSpellCard("NeburaReverie", 0);
		}
}
let hhhh=false;
sub DrawLoopTask
{
if(MissTime==0)
{
	SetTexture(imgPlayer);
	SetColor(255,255,255);
	SetAlpha(255);
	SetGraphicScale(1.0,1.0);
	SetGraphicRect(PlayerRectLeft,PlayerRectUp, PlayerRectRight, PlayerRectDown);
	if(WeaknessCount>0)
	{
		SetColor(100,100,255);
	}
	else
	{
		SetColor(255,255,255);
	}
	DrawGraphic(GetPlayerX(), GetPlayerY());//自機の描画
	//DrawText(PNRate,120,382,12,255);//起動時間の表示
	//DrawText((GetPlayerY-(GetClipMinY+150))/(GetClipMinY+150),120,402,12,255);//起動時間の表示

	atari;
}
/*
	if((GetPlayerY>GetClipMinY+150))
	{
	SetAlpha(240);
	if(Power>=1000)
	{
	SetColor(ColorRed,ColorGreen,ColorBlue);
	}

	//SetRenderState(ADD);
	SetTexture(imgNumberDraw);
	SetGraphicScale(0.8,0.8);
	let num=[0,0,0,0];
	num[0]=trunc(Power%10);
	num[1]=trunc(Power%100/10);
	num[2]=trunc(Power%1000/100);
	num[3]=trunc(Power%10000/1000);

	SetGraphicRect(40*num[0],6,26+40*num[0],38);
	DrawGraphic(GetClipMinX+55-0*15+0.5,GetClipMaxY-416+5+1);
	ascent(i in 1..4)
	{
	if(Power>=10^i)
	{
	SetGraphicRect(40*num[i],6,26+40*num[i],38);
	DrawGraphic(GetClipMinX+55-i*15+0.5,GetClipMaxY-416+5+1);
	}
	}

	}
*/

}


function MagicHueDifine(HueCount)
{
let ColorRed=0;
let ColorGreen=0;
let ColorBlue=0;
let MinColor=0;
while(HueCount>360){HueCount-=360;}
while(HueCount<=0){HueCount+=360;}
	if(0<HueCount && HueCount<=60)
	{
		ColorRed=255;
		ColorGreen=255*(HueCount)/60;
		ColorBlue=0;
	}
	else if(HueCount<=120)
	{
		ColorRed=255*(120-HueCount)/60;
		ColorGreen=255;
		ColorBlue=0;
	}
	else if(HueCount<=180)
	{
		ColorRed=0;
		ColorGreen=255;
		ColorBlue=255*(HueCount-120)/60;
	}
	else if(HueCount<=240)
	{
		ColorRed=0;
		ColorGreen=255*(240-HueCount)/60;
		ColorBlue=255;
	}
	else if(HueCount<=300)
	{
		ColorRed=255*(HueCount-240)/60;
		ColorGreen=0;
		ColorBlue=255;
	}
	else if(HueCount<=360)
	{
		ColorRed=255;
		ColorGreen=0;
		ColorBlue=255*(360-HueCount)/60;
	}
	return([ColorRed,ColorGreen,ColorBlue]);
}