#TouhouDanmakufu[Stage]
#Title[Juuni Jumon - Summer Interlude]
#Player[player\Masahiro\Masahiro.txt]
#ScriptVersion[2]

script_stage_main{

SetClearFrameEffectEnable(false);
SetRateScoreSystemEnable(false);
SetDefaultStatusVisible(false);

#include_function "script/Functions/Stages/MainVariables.txt";
#include_function "script/Functions/Stages/StageVariables.txt";
#include_function "script/Functions/Stages/CommonData.txt";

//Main Menu
#include_function "script/Functions/Main Menu/MainScreenLoad.txt";
#include_function "script/Functions/Main Menu/PlayerSelectLoad.txt";
#include_function "script/Functions/Main Menu/SpellcardPractiseLoad.txt";
#include_function "script/Functions/Main Menu/HighScoreLoad.txt";


//===============================================================================================================
//===============================================================================================================

@MainLoop{

if(GetCommonData("PlayMusic")==99){ FadeMusic(90,120); }

if(GetCommonData("InStagePractise")>0){
	if(GetPlayerLife<8){ ExtendPlayer(1); }
	if(GetPlayerBomb<8){ AddBomb(1); }
}

#include_function "script/Functions/Stages/GlobalData.txt";

if(GetCommonData("NextStage")>0){

let i=0; while(i<length(bush)){ Obj_Delete(bush[i]); Obj_Delete(bushscroll[i]); Obj_Delete(bushrandomx[i]); i++; }
let i=0; while(i<length(tree)){ Obj_Delete(tree[i]); Obj_Delete(treescroll[i]); Obj_Delete(treerandomx[i]); i++; }
let i=0; while(i<length(rock)){ Obj_Delete(rock[i]); Obj_Delete(rockscroll[i]); Obj_Delete(rockrandomx[i]); i++; }
let i=0; while(i<length(lightray)){ Obj_Delete(lightray[i]); Obj_Delete(lightraytimer[i]); Obj_Delete(lightrayfade[i]); Obj_Delete(lightrayscroll[i]); i++; }
let i=0; while(i<length(leaves)){ Obj_Delete(leaves[i]); Obj_Delete(leaftimer[i]); i++; }

	SetCommonData("FadeOut",0);
	SetCommonData("InEvent",1);
	SetCommonData("BackgroundStop",0); 

	stage=GetCommonData("NextStage");
	SetCommonData("Stage",GetCommonData("NextStage"));
	SetCommonData("NextStage",0);

	instage=false;
	stageloaded=0;
	SetCommonData("StageLoaded",0);
}

//===============================================================================================================
//==STG-1===Main Menu============================================================================================
//===============================================================================================================

if(stage==0){

	if(GetCommonData("PlayMusic")==1){ PlayDelayedMusic(MU1b,10,false); }
	if(GetCommonData("PlayMusic")==2){ PlayDelayedMusic(MU2b,10,false); }
	if(GetCommonData("PlayMusic")==3){ PlayDelayedMusic(MU3b,10,false); }
	if(GetCommonData("PlayMusic")==4){ PlayDelayedMusic(MU4b,10,false); }
	if(GetCommonData("PlayMusic")==5){ PlayDelayedMusic(MU5b,10,false); }
	if(GetCommonData("PlayMusic")==6){ PlayDelayedMusic(MU6b,10,false); }
	if(GetCommonData("PlayMusic")==7){ PlayDelayedMusic(MU7b,10,false); }
	if(GetCommonData("PlayMusic")==8){ PlayDelayedMusic(MU8b,10,false); }
	if(GetCommonData("PlayMusic")==9){ PlayDelayedMusic(MUtrump,10,false); }
	if(GetCommonData("PlayMusic")==10){ PlayDelayedMusic(MUmain,10,true); }

	if(mainmenu==1){ #include_function "script/Functions/Main Menu/MainScreen.txt";	}
	if(mainmenu==2){ #include_function "script/Functions/Main Menu/PlayerSelect.txt";}
	if(mainmenu==3){ #include_function "script/Functions/Main Menu/SpellcardPractise.txt"; }	
	if(mainmenu==4){ #include_function "script/Functions/Main Menu/HighScore.txt"; }	
time++;
}

if(stage<7){ ExpertEx(false,999,3); } //Removing this line is disrespectful to all the effort that went into this game.
if(stage>=7){ ExpertEx(false,0,3); } //You cheater. No cake for you.

//===============================================================================================================
//==STG1=========================================================================================================
//===============================================================================================================


if(stage==1){

if(GetCommonData("PlayMusic")==1){ PlayMusic(MU1a); SetCommonData("PlayMusic",0); }
if(GetCommonData("PlayMusic")==2){ FadeOutMusic(MU1a,60); PlayMusic(MU1b); SetCommonData("PlayMusic",0); }

if(stageloaded==0){
	SetCommonData("Power",0);
	CreateEnemyFromFile("script\Functions\loadstage.txt",0,0,0,0,1);
	stageloaded=1;
}
if(GetCommonData("StageLoaded")==1){
	#include_function "script/Functions/Stages/Stage 1/LoadStage.txt";
	stageloaded=2;
	instage=true;
	SetCommonData("StageLoaded",0);
	SetCommonData("FreezeTime",0);
	SetCommonData("InEvent",0);
}

#include_function "script/Functions/Stages/Stage 1/Enemies1.txt";
#include_function "script/Functions/Stages/Stage 1/MidBoss.txt";
#include_function "script/Functions/Stages/Stage 1/Enemies2.txt";
#include_function "script/Functions/Stages/Stage 1/EndBoss.txt";

#include_function "script/Functions/Stages/Stage 1/BackgroundData.txt";


//STAGE 1 BOSS MOVEMENT

if(GetCommonData("Boss1Move")==1){ BossMove1(true,GRtomoko,1,cx+200,maxy+50,cx,miny+100,120); }
if(GetCommonData("Boss1Move")==2){ BossMove1(true,GRtomoko,1,GetCommonData("Boss1X"),GetCommonData("Boss1Y"),cx,miny+100,60); }
if(GetCommonData("Boss1Move")==3){ BossMove1(true,GRtomoko,1,0,0,cx+200,maxy+50,120); }

if(GetCommonData("Boss1Move")==4){ BossMove1(true,GRsetsuko,1,cx-140,miny-50,cx-60,miny+100,90); }
if(GetCommonData("Boss2Move")==4){ BossMove2(true,GRshinichi,1,cx+140,miny-50,cx+60,miny+100,90); }
if(GetCommonData("Boss2Move")==5){ BossMove2(true,GRshinichi,1,0,0,maxx+150,miny-50,90); }
if(GetCommonData("Boss1Move")==6){ BossMove1(true,GRsetsuko,1,GetCommonData("Boss1X"),GetCommonData("Boss1Y"),minx-150,miny-50,90); }

SetCommonData("Boss1Move",0);
SetCommonData("Boss2Move",0);

//visible true/false, graphic, outfit, startx, starty, (0=null) movetox, movetoy, movetime


//STAGE 1 ITEMS

if(GetCommonData("ItemSpawn")==1){
	loop(10){ CreateEnemyFromFile("script\Functions\itempoint.txt",cx+rand(-40,40),cy+rand(-40,40),0,0,0); }
	loop(8){ CreateEnemyFromFile("script\Functions\itempower.txt",cx+rand(-40,40),cy+rand(-40,40),0,0,0); }
SetCommonData("ItemSpawn",0);
}
if(GetCommonData("ItemSpawn")==2){
let anglex=rand(0,360);
	loop(15){
	CreateEnemyFromFile("script\Functions\itempoint.txt",cx+60*cos(anglex),cy+60*sin(anglex),0,0,0);
	anglex+=360/15;
	}
anglex+=360/20;
	loop(10){
	CreateEnemyFromFile("script\Functions\itempower.txt",cx+40*cos(anglex),cy+40*sin(anglex),0,0,0);
	anglex+=360/10;
	}
SetCommonData("ItemSpawn",0);
}

if(GetCommonDataDefault("FreezeTime",0)==0){
	frame++;
	time++;
}

} //END STAGE 1 MAINLOOP


//===============================================================================================================
//==STG2=========================================================================================================
//===============================================================================================================

if(stage==2){

if(GetCommonData("PlayMusic")==1){ PlayMusic(MU2a); SetCommonData("PlayMusic",0); }
if(GetCommonData("PlayMusic")==2){ FadeOutMusic(MU2a,60); PlayMusic(MU2b); SetCommonData("PlayMusic",0); }

if(stageloaded==0){
	CreateEnemyFromFile("script\Functions\loadstage.txt",0,0,0,0,2);
	stageloaded=1;
}
if(GetCommonData("StageLoaded")==1){
	#include_function "script/Functions/Stages/Stage 2/LoadStage.txt";
	stageloaded=2;
	instage=true;
	SetCommonData("StageLoaded",0);
	SetCommonData("FreezeTime",0);
	SetCommonData("InEvent",0);
}

#include_function "script/Functions/Stages/Stage 2/LoadStage.txt";

#include_function "script/Functions/Stages/Stage 2/Enemies1.txt";
#include_function "script/Functions/Stages/Stage 2/MidBoss.txt";
#include_function "script/Functions/Stages/Stage 2/Enemies2.txt";
#include_function "script/Functions/Stages/Stage 2/EndBoss.txt";

#include_function "script/Functions/Stages/Stage 2/BackgroundData.txt";


//STAGE 2 BOSS MOVEMENT

if(GetCommonData("Boss1Move")==1){ BossMove1(true,GRyouko,1,minx-50,miny-50,cx,miny+100,120); }
if(GetCommonData("Boss1Move")==2){ BossMove1(true,GRamaya,1,minx-50,miny+150,cx,miny+100,180); }

SetCommonData("Boss1Move",0);
SetCommonData("Boss2Move",0);

//visible true/false, graphic, outfit, startx, starty, (0=null) movetox, movetoy, movetime


//STAGE 2 ITEMS

if(GetCommonData("ItemSpawn")==1){
	loop(10){ CreateEnemyFromFile("script\Functions\itempoint.txt",cx+rand(-40,40),cy+rand(-40,40),0,0,0); }
	loop(8){ CreateEnemyFromFile("script\Functions\itempower.txt",cx+rand(-40,40),cy+rand(-40,40),0,0,0); }
SetCommonData("ItemSpawn",0);
}
if(GetCommonData("ItemSpawn")==2){
	CreateEnemyFromFile("script\Functions\itembomb.txt",cx,cy,0,0,0);
SetCommonData("ItemSpawn",0);
}

if(GetCommonDataDefault("FreezeTime",0)==0){
	frame++;
	time++;
}

} //END STAGE 2 MAINLOOP


//===============================================================================================================
//==STG3=========================================================================================================
//===============================================================================================================

if(stage==3){

if(GetCommonData("PlayMusic")==1){ PlayMusic(MU3a); SetCommonData("PlayMusic",0); }
if(GetCommonData("PlayMusic")==2){ FadeOutMusic(MU3a,60); PlayMusic(MU3b); SetCommonData("PlayMusic",0); }

if(stageloaded==0){
	CreateEnemyFromFile("script\Functions\loadstage.txt",0,0,0,0,3);
	stageloaded=1;
}
if(GetCommonData("StageLoaded")==1){
	#include_function "script/Functions/Stages/Stage 3/LoadStage.txt";
	stageloaded=2;
	instage=true;
	SetCommonData("StageLoaded",0);
	SetCommonData("FreezeTime",0);
	SetCommonData("InEvent",0);
}

#include_function "script/Functions/Stages/Stage 3/LoadStage.txt";

#include_function "script/Functions/Stages/Stage 3/Enemies1.txt";
#include_function "script/Functions/Stages/Stage 3/MidBoss.txt";
#include_function "script/Functions/Stages/Stage 3/Enemies2.txt";
#include_function "script/Functions/Stages/Stage 3/EndBoss.txt";

#include_function "script/Functions/Stages/Stage 3/BackgroundData.txt";


//STAGE 3 BOSS MOVEMENT

if(GetCommonData("Boss1Move")==1){ BossMove1(true,GRayano,1,cx,miny-50,cx,miny+100,120); }

if(GetCommonData("Boss1Move")==2){ BossMove1(true,GRsayuri,1,maxx+50,miny-70,cx-100,miny+100,120); }
if(GetCommonData("Boss2Move")==2){ BossMove2(true,GRmai,1,minx-50,miny-50,cx+100,miny+100,140); }
if(GetCommonData("Boss1Move")==3){ BossMove1(true,GRsayuri,1,GetCommonData("Boss1X"),GetCommonData("Boss1Y"),minx-50,miny-50,60); }
if(GetCommonData("Boss2Move")==4){ BossMove2(true,GRmai,1,GetCommonData("Boss2X"),GetCommonData("Boss2Y"),maxx+50,miny-50,60); }

SetCommonData("Boss1Move",0);
SetCommonData("Boss2Move",0);

//visible true/false, graphic, outfit, startx, starty, (0=null) movetox, movetoy, movetime

//===============================================================================================================

//STAGE 3 ITEMS

if(GetCommonData("ItemSpawn")==1){
	loop(10){ CreateEnemyFromFile("script\Functions\itempoint.txt",cx+rand(-40,40),cy+rand(-40,40),0,0,0); }
	loop(8){ CreateEnemyFromFile("script\Functions\itempower.txt",cx+rand(-40,40),cy+rand(-40,40),0,0,0); }
SetCommonData("ItemSpawn",0);
}
if(GetCommonData("ItemSpawn")==2){
let anglex=rand(0,360);
	loop(25){
	CreateEnemyFromFile("script\Functions\itempoint.txt",cx+60*cos(anglex),cy+60*sin(anglex),0,0,0);
	anglex+=360/25;
	}
anglex+=360/40;
	loop(20){
	CreateEnemyFromFile("script\Functions\itempower.txt",cx+40*cos(anglex),cy+40*sin(anglex),0,0,0);
	anglex+=360/20;
	}
SetCommonData("ItemSpawn",0);
}

if(GetCommonDataDefault("FreezeTime",0)==0){
	frame++;
	time++;
}

} // END MAINLOOP STAGE 3


//===============================================================================================================
//==STG4=========================================================================================================
//===============================================================================================================

if(stage==4){

if(GetCommonData("PlayMusic")==1){ PlayMusic(MU4a); SetCommonData("PlayMusic",0); }
if(GetCommonData("PlayMusic")==2){ FadeOutMusic(MU4a,60); PlayMusic(MU4b); SetCommonData("PlayMusic",0); }

if(stageloaded==0){
	CreateEnemyFromFile("script\Functions\loadstage.txt",0,0,0,0,4);
	stageloaded=1;
}
if(GetCommonData("StageLoaded")==1){
	#include_function "script/Functions/Stages/Stage 4/LoadStage.txt";
	stageloaded=2;
	instage=true;
	SetCommonData("StageLoaded",0);
	SetCommonData("FreezeTime",0);
	SetCommonData("InEvent",0);
}

#include_function "script/Functions/Stages/Stage 4/LoadStage.txt";

#include_function "script/Functions/Stages/Stage 4/Enemies1.txt";
#include_function "script/Functions/Stages/Stage 4/MidBoss.txt";
#include_function "script/Functions/Stages/Stage 4/Enemies2.txt";
#include_function "script/Functions/Stages/Stage 4/EndBoss.txt";

#include_function "script/Functions/Stages/Stage 4/BackgroundData.txt";


//STAGE 4 BOSS MOVEMENT

if(GetCommonData("Boss1Move")==1){ BossMove1(true,GRryo,4,maxx+50,miny,cx,miny+100,80); }

if(GetCommonData("Boss1Move")==2){ BossMove1(true,GRkurumi,6,cx-30,miny-50,cx-80,miny+70,60); }
if(GetCommonData("Boss2Move")==2){ BossMove2(true,GRhotaru,6,maxx+50,miny+200,cx+80,miny+120,90); }
if(GetCommonData("Boss1Move")==3){ BossMove1(true,GRkurumi,6,GetCommonData("Boss1X"),GetCommonData("Boss1Y"),minx-100,cy,90); }
if(GetCommonData("Boss2Move")==4){ BossMove2(true,GRhotaru,6,GetCommonData("Boss2X"),GetCommonData("Boss2Y"),maxx+100,cy,90); }

SetCommonData("Boss1Move",0);
SetCommonData("Boss2Move",0);

//visible true/false, graphic, outfit, startx, starty, (0=null) movetox, movetoy, movetime

//===============================================================================================================

//STAGE 4 ITEMS

if(GetCommonData("ItemSpawn")==1){
	loop(12){ CreateEnemyFromFile("script\Functions\itempoint.txt",cx+rand(-40,40),cy+rand(-40,40),0,0,0); }
	loop(10){ CreateEnemyFromFile("script\Functions\itempower.txt",cx+rand(-40,40),cy+rand(-40,40),0,0,0); }
SetCommonData("ItemSpawn",0);
}
if(GetCommonData("ItemSpawn")==2){
	CreateEnemyFromFile("script\Functions\itemlife.txt",cx,cy,0,0,0);
SetCommonData("ItemSpawn",0);
}

if(GetCommonDataDefault("FreezeTime",0)==0){
	frame++;
	time++;
}

} // END MAINLOOP STAGE 4


//===============================================================================================================
//==STG5=========================================================================================================
//===============================================================================================================

if(stage==5){

if(GetCommonData("PlayMusic")==1){ PlayMusic(MU5a); SetCommonData("PlayMusic",0); }
if(GetCommonData("PlayMusic")==2){ FadeOutMusic(MU5a,60); PlayMusic(MU5b); SetCommonData("PlayMusic",0); }

if(stageloaded==0){
	CreateEnemyFromFile("script\Functions\loadstage.txt",0,0,0,0,5);
	stageloaded=1;
}
if(GetCommonData("StageLoaded")==1){
	#include_function "script/Functions/Stages/Stage 5/LoadStage.txt";
	stageloaded=2;
	instage=true;
	SetCommonData("StageLoaded",0);
	SetCommonData("FreezeTime",0);
	SetCommonData("InEvent",0);
}

#include_function "script/Functions/Stages/Stage 5/LoadStage.txt";

#include_function "script/Functions/Stages/Stage 5/Enemies1.txt";
#include_function "script/Functions/Stages/Stage 5/MidBoss.txt";
#include_function "script/Functions/Stages/Stage 5/Enemies2.txt";
#include_function "script/Functions/Stages/Stage 5/EndBoss.txt";

#include_function "script/Functions/Stages/Stage 5/BackgroundData.txt";


//STAGE 5 BOSS MOVEMENT

if(GetCommonData("Boss1Move")==1){ BossMove1(true,GRmidori,1,maxx+30,miny,cx,miny+100,90); }

if(GetCommonData("Boss1Move")==2){ BossMove1(true,GRtomomi,1,cx-40,miny-70,cx,miny+150,90); }
if(GetCommonData("Boss2Move")==2){ BossMove2(true,GRtakeo,1,cx+80,miny-50,cx+60,miny+90,150); }
if(GetCommonData("Boss1Move")==3){ BossMove1(true,GRtomomi,1,GetCommonData("Boss1X"),GetCommonData("Boss1Y"),cx-80,miny-70,90); }
if(GetCommonData("Boss2Move")==4){ BossMove2(true,GRtakeo,1,GetCommonData("Boss2X"),GetCommonData("Boss2Y"),cx+80,miny-70,90); }


SetCommonData("Boss1Move",0);
SetCommonData("Boss2Move",0);

//visible true/false, graphic, outfit, startx, starty, (0=null) movetox, movetoy, movetime

//===============================================================================================================

//STAGE 5 ITEMS

if(GetCommonData("ItemSpawn")==1){
	loop(16){ CreateEnemyFromFile("script\Functions\itempoint.txt",cx+rand(-40,40),cy+rand(-40,40),0,0,0); }
	loop(12){ CreateEnemyFromFile("script\Functions\itempower.txt",cx+rand(-40,40),cy+rand(-40,40),0,0,0); }
SetCommonData("ItemSpawn",0);
}
if(GetCommonData("ItemSpawn")==2){
let anglex=rand(0,360);
	loop(40){
	CreateEnemyFromFile("script\Functions\itempoint.txt",cx+60*cos(anglex),cy+60*sin(anglex),0,0,0);
	anglex+=360/40;
	}
anglex+=360/60;
	loop(25){
	CreateEnemyFromFile("script\Functions\itempower.txt",cx+40*cos(anglex),cy+40*sin(anglex),0,0,0);
	anglex+=360/25;
	}
SetCommonData("ItemSpawn",0);
}

if(GetCommonDataDefault("FreezeTime",0)==0){
	frame++;
	time++;
}

} // END MAINLOOP STAGE 5


//===============================================================================================================
//==STG6=========================================================================================================
//===============================================================================================================

if(stage==6){

if(GetCommonData("PlayMusic")==1){ PlayMusic(MU6a); SetCommonData("PlayMusic",0); }
if(GetCommonData("PlayMusic")==2){ FadeOutMusic(MU6a,60); PlayMusic(MU6b); SetCommonData("PlayMusic",0); }
if(GetCommonData("PlayMusic")==3){ PlayMusic(MUcredits); SetCommonData("PlayMusic",0); }

if(stageloaded==0){
	CreateEnemyFromFile("script\Functions\loadstage.txt",0,0,0,0,6);
	stageloaded=1;
}
if(GetCommonData("StageLoaded")==1){
	#include_function "script/Functions/Stages/Stage 6/LoadStage.txt";
	stageloaded=2;
	instage=true;
	SetCommonData("StageLoaded",0);
	SetCommonData("FreezeTime",0);
	SetCommonData("InEvent",0);
}

#include_function "script/Functions/Stages/Stage 6/LoadStage.txt";

#include_function "script/Functions/Stages/Stage 6/Enemies1.txt";
#include_function "script/Functions/Stages/Stage 6/MidBoss.txt";
#include_function "script/Functions/Stages/Stage 6/Enemies2.txt";
#include_function "script/Functions/Stages/Stage 6/EndBoss.txt";

#include_function "script/Functions/Stages/Stage 6/BackgroundData.txt";


//STAGE 6 BOSS MOVEMENT

if(GetCommonData("Boss1Move")==1){ BossMove1(true,GRharuna,1,cx+50,miny-50,cx,miny+100,120); }
if(GetCommonData("Boss1Move")==3){ BossMove1(true,GRtomoko,1,cx,miny-50,cx,miny+100,180); }


SetCommonData("Boss1Move",0);
SetCommonData("Boss2Move",0);

//visible true/false, graphic, outfit, startx, starty, (0=null) movetox, movetoy, movetime

//===============================================================================================================

//STAGE 6 ITEMS

if(GetCommonData("ItemSpawn")==1){
	loop(20){ CreateEnemyFromFile("script\Functions\itempoint.txt",cx+rand(-50,50),cy+rand(-50,50),0,0,0); }
	loop(14){ CreateEnemyFromFile("script\Functions\itempower.txt",cx+rand(-50,50),cy+rand(-50,50),0,0,0); }
SetCommonData("ItemSpawn",0);
}
if(GetCommonData("ItemSpawn")==2){
	CreateEnemyFromFile("script\Functions\itemlife.txt",cx,cy,0,0,0);
SetCommonData("ItemSpawn",0);
}

if(GetCommonDataDefault("FreezeTime",0)==0){
	frame++;
	time++;
}

} // END MAINLOOP STAGE 6

//===============================================================================================================
//==STG7=========================================================================================================
//===============================================================================================================

if(stage==7){

if(GetCommonData("PlayMusic")==1){ PlayMusic(MU7a); SetCommonData("PlayMusic",0); }
if(GetCommonData("PlayMusic")==2){ FadeOutMusic(MU7a,60); PlayMusic(MU7b); SetCommonData("PlayMusic",0); }
if(GetCommonData("PlayMusic")==3){ FadeOutMusic(MU7b,60); PlayMusic(MUtrump); SetCommonData("PlayMusic",0); }

SetAllowedContinueCount(0);

if(stageloaded==0){
	SetCommonData("Power",70);
	SetCommonData("Difficulty",5);
	CreateEnemyFromFile("script\Functions\loadstage.txt",0,0,0,0,7);
	stageloaded=1;
}
if(GetCommonData("StageLoaded")==1){
	#include_function "script/Functions/Stages/Extra/LoadStage.txt";
	stageloaded=2;
	instage=true;
	SetCommonData("StageLoaded",0);
	SetCommonData("FreezeTime",0);
	SetCommonData("InEvent",0);
}


#include_function "script/Functions/Stages/Extra/LoadStage.txt";

#include_function "script/Functions/Stages/Extra/Enemies1.txt";
#include_function "script/Functions/Stages/Extra/MidBoss.txt";
#include_function "script/Functions/Stages/Extra/Enemies2.txt";
#include_function "script/Functions/Stages/Extra/EndBoss.txt";

#include_function "script/Functions/Stages/Extra/BackgroundData.txt";


//STAGE 7 BOSS MOVEMENT

if(GetCommonData("Boss1Move")==1){ BossMove1(true,GRnanami,1,maxx+50,miny-50,cx,miny+100,120); }
if(GetCommonData("Boss1Move")==2){ BossMove1(true,GRtomoko,5,minx-50,miny-50,cx,miny+100,120); }

if(GetCommonData("Boss2Move")==3){ BossMove2(true,GRtomoko,5,GetCommonData("Boss1X"),GetCommonData("Boss1Y"),minx-50,miny+200,120); }
if(GetCommonData("Boss1Move")==3){ BossMove1(true,GRyouko,5,maxx+50,miny+200,cx,miny+100,120); }
if(GetCommonData("Boss2Move")==4){ BossMove2(true,GRyouko,5,GetCommonData("Boss1X"),GetCommonData("Boss1Y"),minx-50,miny+200,120); }
if(GetCommonData("Boss1Move")==4){ BossMove1(true,GRhotaru,5,maxx+50,miny+200,cx,miny+100,120); }
if(GetCommonData("Boss2Move")==5){ BossMove2(true,GRhotaru,5,GetCommonData("Boss1X"),GetCommonData("Boss1Y"),minx-50,miny+200,120); }
if(GetCommonData("Boss1Move")==5){ BossMove1(true,GRmai,5,maxx+50,miny+200,cx,miny+100,120); }
if(GetCommonData("Boss2Move")==6){ BossMove2(true,GRmai,5,GetCommonData("Boss1X"),GetCommonData("Boss1Y"),minx-50,miny+200,120); }
if(GetCommonData("Boss1Move")==6){ BossMove1(true,GRamaya,5,maxx+50,miny+200,cx,miny+100,120); }
if(GetCommonData("Boss2Move")==7){ BossMove2(true,GRamaya,5,GetCommonData("Boss1X"),GetCommonData("Boss1Y"),minx-50,miny+200,120); }
if(GetCommonData("Boss1Move")==7){ BossMove1(true,GRayano,5,maxx+50,miny+200,cx,miny+100,120); }
if(GetCommonData("Boss2Move")==8){ BossMove2(true,GRayano,5,GetCommonData("Boss1X"),GetCommonData("Boss1Y"),minx-50,miny+200,120); }
if(GetCommonData("Boss1Move")==8){ BossMove1(true,GRmidori,5,maxx+50,miny+200,cx,miny+100,120); }
if(GetCommonData("Boss2Move")==9){ BossMove2(true,GRmidori,5,GetCommonData("Boss1X"),GetCommonData("Boss1Y"),minx-50,miny+200,120); }
if(GetCommonData("Boss1Move")==9){ BossMove1(true,GRtomomi,5,maxx+50,miny+200,cx,miny+100,120); }
if(GetCommonData("Boss2Move")==10){ BossMove2(true,GRtomomi,5,GetCommonData("Boss1X"),GetCommonData("Boss1Y"),minx-50,miny+200,120); }
if(GetCommonData("Boss1Move")==10){ BossMove1(true,GRkurumi,5,maxx+50,miny+200,cx,miny+100,120); }
if(GetCommonData("Boss2Move")==11){ BossMove2(true,GRkurumi,5,GetCommonData("Boss1X"),GetCommonData("Boss1Y"),minx-50,miny+200,120); }
if(GetCommonData("Boss1Move")==11){ BossMove1(true,GRsetsuko,5,maxx+50,miny+200,cx,miny+100,120); }
if(GetCommonData("Boss2Move")==12){ BossMove2(true,GRsetsuko,5,GetCommonData("Boss1X"),GetCommonData("Boss1Y"),minx-50,miny+200,120); }
if(GetCommonData("Boss1Move")==12){ BossMove1(true,GRsayuri,5,maxx+50,miny+200,cx,miny+100,120); }
if(GetCommonData("Boss2Move")==13){ BossMove2(true,GRsayuri,5,GetCommonData("Boss1X"),GetCommonData("Boss1Y"),minx-50,miny+200,120); }
if(GetCommonData("Boss1Move")==13){ BossMove1(true,GRharuna,5,maxx+50,miny+200,cx,miny+100,120); }
if(GetCommonData("Boss2Move")==14){ BossMove2(true,GRharuna,5,GetCommonData("Boss1X"),GetCommonData("Boss1Y"),minx-50,miny+200,120); }
if(GetCommonData("Boss1Move")==14){ BossMove1(true,GRtomoko,5,maxx+50,miny+200,cx,miny+100,120); }

SetCommonData("Boss1Move",0);
SetCommonData("Boss2Move",0);

//visible true/false, graphic, outfit, startx, starty, (0=null) movetox, movetoy, movetime

//===============================================================================================================

//STAGE 7 ITEMS

if(GetCommonData("ItemSpawn")==1){
	let itemangle=rand(0,360);
		loop(12){
		CreateEnemyFromFile("script\Functions\itempower.txt",cx+30*cos(itemangle),cy+30*sin(itemangle),0,0,0);
		itemangle+=360/12;
		}
	let itemangle=rand(0,360);
		loop(25){
		CreateEnemyFromFile("script\Functions\itempoint.txt",cx+55*cos(itemangle),cy+55*sin(itemangle),0,0,0);
		itemangle+=360/25;
		}
	SetCommonData("ItemSpawn",0);
}

if(GetCommonData("ItemSpawn")==2){
let anglex=90;
	loop(3){
	CreateEnemyFromFile("script\Functions\itembigpower.txt",cx+50*cos(anglex),cy+50*sin(anglex),0,0,0);
	anglex+=360/3;
	}
	CreateEnemyFromFile("script\Functions\itembomb.txt",cx-30,cy,0,0,0);
	CreateEnemyFromFile("script\Functions\itemlife.txt",cx+30,cy,0,0,0);
SetCommonData("ItemSpawn",0);
}

if(GetCommonData("ItemSpawn")==3){
	let itemangle=rand(0,360);
		loop(16){
		CreateEnemyFromFile("script\Functions\itempower.txt",cx+30*cos(itemangle),cy+30*sin(itemangle),0,0,0);
		itemangle+=360/16;
		}
	let itemangle=rand(0,360);
		loop(25){
		CreateEnemyFromFile("script\Functions\itempoint.txt",cx+55*cos(itemangle),cy+55*sin(itemangle),0,0,0);
		itemangle+=360/25;
		}
	CreateEnemyFromFile("script\Functions\itembomb.txt",cx,cy,0,0,0);
SetCommonData("ItemSpawn",0);
}

frame++;
time++;

} // END MAINLOOP STAGE EXTRA


//===============================================================================================================
//==STG8=========================================================================================================
//===============================================================================================================

if(stage==8){

if(GetCommonData("PlayMusic")==1){ PlayMusic(MU8a); SetCommonData("PlayMusic",0); }
if(GetCommonData("PlayMusic")==2){ PlayMusic(MU8b); SetCommonData("PlayMusic",0); }

SetAllowedContinueCount(0);

if(stageloaded==0){
	SetCommonData("Power",0);
	SetCommonData("Difficulty",6);
	CreateEnemyFromFile("script\Functions\loadstage.txt",0,0,0,0,8);
	stageloaded=1;
}
if(GetCommonData("StageLoaded")==1){
	#include_function "script/Functions/Stages/Nightmare/LoadStage.txt";
	stageloaded=2;
	instage=true;
	SetCommonData("StageLoaded",0);
	SetCommonData("FreezeTime",0);
	SetCommonData("InEvent",0);
}

#include_function "script/Functions/Stages/Nightmare/LoadStage.txt";

#include_function "script/Functions/Stages/Nightmare/Enemies1.txt";
#include_function "script/Functions/Stages/Nightmare/EndBoss.txt";

#include_function "script/Functions/Stages/Nightmare/BackgroundData.txt";

//STAGE 8 ITEMS

if(GetCommonData("ItemSpawn")==1){
	let itemangle=rand(0,360);
		loop(24){
		CreateEnemyFromFile("script\Functions\itempower.txt",cx+40*cos(itemangle),cy+40*sin(itemangle),0,0,0);
		itemangle+=360/24;
		}
	let itemangle=rand(0,360);
		loop(40){
		CreateEnemyFromFile("script\Functions\itempoint.txt",cx+80*cos(itemangle),cy+80*sin(itemangle),0,0,0);
		itemangle+=360/40;
		}
	SetCommonData("ItemSpawn",0);
}

if(GetCommonData("ItemSpawn")==3){
	let itemangle=rand(0,360);
		loop(24){
		CreateEnemyFromFile("script\Functions\itempower.txt",cx+40*cos(itemangle),cy+40*sin(itemangle),0,0,0);
		itemangle+=360/24;
		}
	let itemangle=rand(0,360);
		loop(40){
		CreateEnemyFromFile("script\Functions\itempoint.txt",cx+80*cos(itemangle),cy+80*sin(itemangle),0,0,0);
		itemangle+=360/40;
		}
	CreateEnemyFromFile("script\Functions\itembomb.txt",cx,cy,0,0,0);
SetCommonData("ItemSpawn",0);
}

frame++;
time++;

} // END MAINLOOP STAGE NIGHTMARE

//===============================================================================================================

SetCommonData("Graze",GetGraze);
SetCommonData("Lives",GetPlayerLife);
SetCommonData("Bombs",GetPlayerBomb);
SetCommonData("Score",GetScore);
if(GetScore>=GetCommonDataDefault("Highscore",0)){ SetCommonData("Highscore",GetScore); }

blackscreenalpha=GetCommonDataDefault("BlackScreenFade",255);
ObjEffect_SetVertexColor(EFblack,0,blackscreenalpha,0,0,0); ObjEffect_SetVertexColor(EFblack,1,blackscreenalpha,0,0,0);
ObjEffect_SetVertexColor(EFblack,2,blackscreenalpha,0,0,0); ObjEffect_SetVertexColor(EFblack,3,blackscreenalpha,0,0,0);

if(GetCommonDataDefault("EndGame",0)==1){ ClearStage; }

yield;

} //END MAINLOOP

//===============================================================================================================
//===============================================================================================================


@BackGround{

if(instage==true){

#include_function "script/Functions/Stages/Stage 1/Background.txt";
#include_function "script/Functions/Stages/Stage 2/Background.txt";
#include_function "script/Functions/Stages/Stage 3/Background.txt";
#include_function "script/Functions/Stages/Stage 4/Background.txt";
#include_function "script/Functions/Stages/Stage 5/Background.txt";
#include_function "script/Functions/Stages/Stage 6/Background.txt";
#include_function "script/Functions/Stages/Extra/Background.txt";
#include_function "script/Functions/Stages/Nightmare/Background.txt";

} //instage

} //@ Background

//===============================================================================================================
//===============================================================================================================

@Finalize{
}

task PlayDelayedMusic(mu,delay,delete){
	SetCommonData("PlayMusic",0);
	if(mu!=MUmain && delete==true){ DeleteMusic(mu); }
	loop(delay){ yield; }
	LoadMusic(mu);
	PlayMusic(mu);
	if(mu!=MUmain){ DeleteMusic(MUmain); }
}

task FadeMusic(duration,delay){
	SetCommonData("PlayMusic",0);
	FadeOutMusic(MU1b,duration); FadeOutMusic(MU2b,duration); FadeOutMusic(MU3b,duration);
	FadeOutMusic(MU4b,duration); FadeOutMusic(MU5b,duration); FadeOutMusic(MU6b,duration);
	FadeOutMusic(MU7b,duration); FadeOutMusic(MU8b,duration);
	loop(delay){ yield; }
}

}