function GameMainLoopSystem
{
	//-----------
	
	score=GetCommonData("Score");
	
	Extend_LSystem;
	Item_LSystem;
	State_LSystem;
	
	SetCommonData("Score",score);
	
	//-----------
	
	BG_LSystem;
}


function Extend_LSystem
{
	if(itempoint_getcount>=extend_1up)
	{
		CreateEnemyFromFile(GetCurrentScriptDirectory~".\GameData\SystemData\SetExtendItem.txt",0,0,0,0,2);
		itempoint_getcount-=extend_1up;
		SetEffect(1);
	}
	if(itemmulti_getcount>=extend_bomb)
	{
		CreateEnemyFromFile(GetCurrentScriptDirectory~".\GameData\SystemData\SetExtendItem.txt",0,0,0,0,1);
		itemmulti_getcount-=extend_bomb;
		SetEffect(0);
	}
	
	if(GetGraze>=graze_break)
	{
		if(!OnEnemySpell)
		{
			CreateEnemyFromFile(GetCurrentScriptDirectory~".\GameData\SystemData\SetExtendItem.txt",0,0,0,0,0);
			SetEffect(2);
		}
		AddGraze(-graze_break);
	}
	
	task SetEffect(let type)
	{
		PlaySE(se[SE_BREAK]);
		loop(80)
		{
			let sx=cenX;let sy=cenY;
			let angle=rand(0,360);
			let speed=rand(0,4);
			if(type==2){sx=GetPlayerX;sy=GetPlayerY;}
			
			BreakEffectObject(sx,sy,speed,angle,0);
		}	
	}
}

function Item_LSystem
{
	let itemstate=GetCommonDataDefault("ItemState",[]);
	while(length(itemstate)>0)
	{
		let data=itemstate[0];
		let x=data[0];
		let y=data[1];
		let type=data[2];
		SetItem(x,y,type);
		itemstate=erase(itemstate,0);
		SetCommonData("ItemState",itemstate);
	}
	
	if(OnPlayerMissed){itemrate_num-=7;}
	if(!IsBossExisting)
	{
		if(multiply_delay>10000){multiply_delay=10000;}
		if(multiply_delay>1){multiply_delay=ceil(multiply_delay*0.98);}
		if(multiply_num>0)
		{
			multiply_num-=75/ceil(multiply_delay/60);
		}
		else
		{
			multiply_num=0;
			itemrate_num-=5;
		}
	}
	
	if(itemrate_num<1){itemrate_num=1;}
	if(itemrate_num>999){itemrate_num=999;}
	SetCommonData("Rate",itemrate_num);
	SetCommonData("ItemPoint",itempoint);
	
	if(GetKeyState(VK_SHOT)==KEY_HOLD){itemconv_delay=15;}
	if(itemconv_delay==0){ConvCircle;}
	
	if(!menu_flg){DrawBaseCount(itempoint);DrawMultiplyCount(itemrate_num);}
	itemconv_delay--;
}


function State_LSystem
{
	if(GetPlayerLife>=17){ExtendPlayer(-1);}
	if(GetPlayerBomb>=9){AddBomb(-1);}
	
	if(GetPlayerType!=USER_PLAYER)
	{
		if(GetKeyState(VK_SHOT)==KEY_HOLD||GetKeyState(VK_SHOT)==KEY_PUSH){ForbidShot(false);}
		else{ForbidShot(true);}
	}
	let hitcount=GetCommonDataDefault("EnemyHitCount",0);
	if(hitcount>0)
	{
		let rate=GetCommonDataDefault("Rate",1);
		score+=rate*rate*hitcount*floor(itempoint/300);
		multiply_num+=30*hitcount;
		multiply_delay+=2*hitcount;
	}
	SetCommonData("EnemyHitCount",0);
	
	let enemydelflg=GetCommonDataDefault("EnemyDelFlg",0);
	if(enemydelflg)
	{
		multiply_num=1000;
		multiply_delay+=200;
	}
	SetCommonData("EnemyDelFlg",0);
	if(multiply_num>1000){multiply_num=1000;}
/*	
	let e_num=GetEnemyNum*30;
	if(IsBossExisting){e_num=GetEnemyNum*5;}
	if(GetEnemyShotCount+e_num>1200)
	{
		if(GetFps>40&&!IsReplay){Slow(1);}
	}
	else
	{
		Slow(0);
	}*/
	
	if(GetScore==0)
	{
		score=0;
		AddScore(1);
	}
	
	gameloop_count++;
}

