#TouhouDanmakufu[Stage]
#ScriptVersion[3]
#Title["The True Master of Winter"]
//#BGM["script/resources/music/stage1.ogg"]
#Player["./Aya/Aya.dnh"]
//#Text["Life has many doors and gates, Moon Rabbit!"]
#System["./default_system/Default_System.txt"]
#include"script/default_system/Default_Effect.txt"
#include"./resources/include.txt"
#include"./StageBG.txt"

let frame=0;
let animation=0;
let angle=0;
let scoremode= false;
let difficulty = 2;
let objstg;
let music = 0;

@Event{
	if (GetEventType == EV_PAUSE_ENTER) {
				// stop 7bgm
			ObjSound_Stop(objstg);
			}

		else if (GetEventType == EV_PAUSE_LEAVE) {
			///resume bgm
			ObjSound_Play(objstg);
			}
		}

@Initialize{

	SetPlayData;
	StageControl;
	//Part2
	//FistFairy(GetStgFrameWidth/2, 135, 50, 400, 8, FIRE_RED);
	SetCommonData("Difficulty", difficulty);
	SetCommonData("Score Attack", scoremode);
	}
	
@MainLoop{

	yield;	
	}
	
task SetPlayData{

	SetPlayerLife(20);
	SetPlayerSpell(2);
	
	}
	
task StageControl{
	let StageManageObject = ObjPrim_Create(OBJ_SPRITE_2D);
	//Obj_SetValue(StageManageObject, SpellDetect, false);
	ObjMove_SetPosition(StageManageObject, -60, -60);
	StageBG(StageManageObject);
	SoundCheck(StageManageObject);
	
	wait(100);
	
	Midboss(StageManageObject);
	
	wait(200);
	
	//*/
	///Boss;
	
	///*/
	
	
	wait(60);
	
	//RaiseError("EEEEEEEEEEEEEEEEEEEEEEEH");
	
	CloseStgScene;
	CloseScript(GetOwnScriptID()); //Close the plural.
	
	}
	
function Midboss(tobj){
	let dir=GetCurrentScriptDirectory();
	let obj=ObjEnemyBossScene_Create();
	ObjEnemyBossScene_Add(obj,0,dir~"FreuNon1.txt");
	ObjEnemyBossScene_Add(obj,1,dir~"FreuNon2.txt");
	ObjEnemyBossScene_Add(obj,2,dir~"FreuNon3.txt");
	ObjEnemyBossScene_Add(obj, 3,dir~"FreuNon4.txt");
	ObjEnemyBossScene_Add(obj,0,dir~"FreuSpell1.txt");
	ObjEnemyBossScene_Add(obj,1,dir~"FreuSpell2.txt");
	ObjEnemyBossScene_Add(obj,2,dir~"FreuSpell3.txt");
	ObjEnemyBossScene_Add(obj,3,dir~"FreuSpell4.txt");
	//ObjEnemyBossScene_Add(obj,0,dir~"MidSpell1.txt");
	//ObjEnemyBossScene_Add(obj,1,dir~"MidSpell2.txt");
	ObjEnemyBossScene_LoadInThread(obj);
	ObjEnemyBossScene_Regist(obj);
	
	while(!Obj_IsDeleted(obj)){
		yield;
		}
	
	//Part2;
	}

	
	
task SoundCheck(tobj){
	let dir = GetCurrentScriptDirectory;
	objstg = ObjSound_Create;
	ObjSound_Load(objstg, dir~"bossbgm.ogg");
	ObjSound_SetLoopEnable(objstg, true);
	//ObjSound_SetLoopSampleCount(objstg, 33880, 4061846);
	ObjSound_SetLoopSampleCount(objstg, 221184, 4233216);
	ObjSound_SetRestartEnable(objstg, true);
	let Vol = ObjSound_GetVolumeRate(objstg);
	ObjSound_SetVolumeRate(objstg, Vol*2);
	ObjSound_Play(objstg);
	
	while(!Obj_IsDeleted(tobj)){
		
		
		yield;
		}
	
	
	}
	
function wait(r){
	loop(r){
		yield;
		}
		
	}