#TouhouDanmakufu[Stage]
#ScriptVersion[3]
#Title["AJS"]
#System["./script/system/Default_System.txt"]
#Background["./script/system/Background.txt"]

#include"./script/system/package_sound.txt"

let life = 1000;
let music = [];

@Initialize
{
	SetPlayerLife(life);
	SetShotAutoDeleteClip(8,8,8,8);
	TStage();
}

@MainLoop
{
	if(GetPlayerLife < life)
		{
		life = GetPlayerLife;	
		SetCommonData("DEATH_COUNT",GetCommonData("DEATH_COUNT",0)+1);
		}
	yield;
}
@Event
{
	alternative(GetEventType())
		case(EV_SOUND_PLAY)
			{
			TSound(GetEventArgument(0)[0],GetEventArgument(0)[1]);
			}
		case(EV_SOUND_STOP)
			{
			ObjSound_Stop(GetEventArgument(0)[0]);
			}
		case(EV_MUSIC_PLAY)
			{
			TMusic(GetEventArgument(0)[0]);
			}
		case(EV_MUSIC_STOP)
			{
			TMusicStop(GetEventArgument(0)[0]);
			}
		case(EV_MUSIC_FADE)
			{
			TMusicFade(GetEventArgument(0)[0],GetEventArgument(0)[1]);
			}
		case(EV_MUSIC_VOL)
			{
			TMusicVol(GetEventArgument(0)[0],GetEventArgument(0)[1]);
			}
		case(EV_PAUSE_ENTER)
			{
			ascent(i in 0..length(musicObj))
				{
				if(ObjSound_IsPlaying(musicObj[i]))
					{
					music = music ~ [i];
					TMusicPause(i);
					}
				}
			}
		case(EV_PAUSE_LEAVE)
			{
			ascent(i in 0..length(music))
				{
				TMusicResume(music[i]);
				}
			music = [];
			}
}

@Finalize
{
}


task TStage
{
	InitializeMusic;
	InitializeSound;
	InitializeLoad;

	let dir = GetCurrentScriptDirectory ~ "script/";

	let obj = ObjEnemyBossScene_Create();
	ObjEnemyBossScene_Add(obj, 0, dir ~ "Init.txt");
	ObjEnemyBossScene_Add(obj, 1, dir ~ "Spell1.txt");
	ObjEnemyBossScene_Add(obj, 2, dir ~ "Spell2.txt");
	ObjEnemyBossScene_Add(obj, 3, dir ~ "Spell3.txt");
	ObjEnemyBossScene_Add(obj, 4, dir ~ "Spell4.txt");
	ObjEnemyBossScene_Add(obj, 5, dir ~ "End.txt");
	ObjEnemyBossScene_LoadInThread(obj);
	ObjEnemyBossScene_Regist(obj);

	let bgm = 0;

	while(!Obj_IsDeleted(obj))
		{
		if(GetPlayerLife < 0)
			{
			loop(60){yield;}
			break;
			}
		yield;
		}

	PlaySound("se_Die",70);
	loop(120){yield;}
	CloseScript(GetOwnScriptID());
	CloseStgScene();
}

function InitializeLoad
{
	let dir = GetCurrentScriptDirectory ~ "script/img/";
	LoadTexture(dir ~ "Boss/rise.png");
	LoadTexture(dir ~ "Boss/main.png");
	LoadTexture(dir ~ "Boss/Oku.png");
	LoadTexture(dir ~ "Boss/Koi.png");
	LoadTexture(dir ~ "Boss/koi_player.png");
	LoadTexture(dir ~ "Boss/Yukari.png");
	LoadTexture(dir ~ "Boss/AJS.png");

	LoadTexture(dir ~ "bubble.png");
	LoadTexture(dir ~ "train.png");
	LoadTexture(dir ~ "survival.png");
	LoadTexture(dir ~ "ran.png");
	LoadTexture(dir ~ "rave.png");
	LoadTexture(dir ~ "nuke1.png");
	LoadTexture(dir ~ "nuke2.png");
	LoadTexture(dir ~ "sprk.png");
	LoadTexture(dir ~ "globe.png");

	LoadTexture(dir ~ "rave/rin.png");
	LoadTexture(dir ~ "rave/iku.png");
	LoadTexture(dir ~ "rave/tenji.png");
	LoadTexture(dir ~ "rave/clown.png");
}