

	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 MagicCounterLimit=100000;
	let MagicFragment=0;
	let SectionMagicFragment=0;
	let opX=[0,1,2,3,4,5];	//オプションのX座標
	let opY=[0,1,2,3,4,5];	//オプションのY座標
	let OpAngle=0;
	let OpAngle2=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 imgWind=csd ~ "..\img\wind.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 RushFlag=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,false,false];
let TargetX=[-1,-1,-1,-1,-1,-1];
let TargetY=[-1,-1,-1,-1,-1,-1];
let OnOpShot=[0,0,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);
		LoadGraphic(imgWind);
}

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;
		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")
			{

			}
		}
	//	ReplaySaveSystem;
	//	ReplayLoadSystem;
	//	ReplayMove;
	//	EliminateSystem;
}

sub MainLoopTask
{
	SetIntersectionCircle(GetPlayerX, GetPlayerY, 0);//自機の当たり判定
	SetCommonData("MissTime",MissTime);
	if(GetKeyState(VK_BOMB)==KEY_PUSH && GetKeyState(VK_USER)==KEY_HOLD && BurstMode!=0 && GetPlayerBomb==0 && !RushFlag)
	{
		NoBombCanselBomb;
	}
	yield;
}

task NoBombCanselBomb
{
	AddBomb(1);
	CallSpellCard;
	wait(2);
	AddBomb(-1);
}

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);
			SetCommonData("UseCancelBombForNoBomb",GetCommonDataDefault("UseCancelBombForNoBomb",0)+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 && BurstMode!=0 && !RushFlag)
		{
			AddBomb(1);
			StartStar;
			UseCancelBombCount+=1;
			SetCommonData("UseCancelBombForNoBomb",GetCommonDataDefault("UseCancelBombForNoBomb",0)+1);
		//	SetPlayerInvincibility(150);
			BurstMode=0;
		}	
		else if(GetKeyState(VK_SLOWMOVE)==KEY_PUSH || GetKeyState(VK_SLOWMOVE)==KEY_HOLD)
		{
			if(OnBorderOfLife)
			{
				AchievementSet(89);
			}
			OnHiSpeedBomb=false;
			OnLowSpeedBomb=true;
			if(OnBorderOfLife)
			{
				SetCommonDataEx(NsScore,NsAchievement[86],1);
			}
			if(PlayerType=="A")
			{
			SetCommonData("TargetX",[TargetX[0],TargetX[1],TargetX[2],TargetX[3],TargetX[4],TargetX[5]]);
			SetCommonData("TargetY",[TargetY[0],TargetY[1],TargetY[2],TargetY[3],TargetY[4],TargetY[5]]);
			UseSpellCard("StardustPulsar", 0);
			//UseSpellCard("DarkNebura", 0);
			}
			if(PlayerType=="B")
			{
			//UseSpellCard("StardustFixer", 0);
			UseSpellCard("ElectricMS", 0);
			UseMasterSparkCount+=1;
			}
			if(PlayerType=="C")
			{
			//UseSpellCard("ElectricMS", 0);
			UseSpellCard("StellaWind", 0);
			}
			if(PlayerType=="A")
			{
			SetCommonData("TargetX",[TargetX[0],TargetX[1],TargetX[2],TargetX[3],TargetX[4],TargetX[5]]);
			SetCommonData("TargetY",[TargetY[0],TargetY[1],TargetY[2],TargetY[3],TargetY[4],TargetY[5]]);
			UseSpellCard("StardustPulsar", 0);
			}
		}
		else
		{
			if(OnBorderOfLife)
			{
				AchievementSet(89);
			}
			OnHiSpeedBomb=true;
			OnLowSpeedBomb=false;
			UseSpellCard("NeburaReverie", 0);
		}
}

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(UseMasterSparkCount,120,382,12,255);//起動時間の表示
	//DrawText((GetPlayerY-(GetClipMinY+150))/(GetClipMinY+150),120,402,12,255);//起動時間の表示

	atari;
}

}


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]);
}