#東方弾幕風[Stage]
#ScriptVersion[3]
#Title["Dont Read It!(Stage)"]
//Player["./player/player.txt"]
#Text["By Gusano2314 and Jeshua_morbus"]
#System["./system/Default_System.txt"]

let dir = GetCurrentScriptDirectory();

let bgm = ObjSound_Create;
let finished = false;
let angel= dir ~ "#1plural.txt";
let edotalk= dir~"#1.5plural.txt";
let edorev= dir ~ "#2plural.txt";
let mogetalk= dir~"#2.5plural.txt";
let mogel= dir ~ "#3plural.txt";

let Langel1;
let Ledo1;
let Ledo2;
let Lmog1;
let Lmog2;
@Initialize
{
	
//Boss 1: Angel
LoadTextureInLoadThread(GetCurrentScriptDirectory~"img/dot_angel.png");
LoadTextureInLoadThread(GetCurrentScriptDirectory~"img/angel.png");
LoadTextureInLoadThread(GetCurrentScriptDirectory~"img/magiccircle.png");
//Boss 2: Edorev
LoadTextureInLoadThread(GetCurrentScriptDirectory~"img/dot_edorev.png");
LoadTextureInLoadThread(GetCurrentScriptDirectory~"img/endo.png");
LoadTextureInLoadThread(GetCurrentScriptDirectory~"img/DRI_b2s1.png");
LoadTextureInLoadThread(GetCurrentScriptDirectory~"img/DRI_b2s2.png");
//Boss 3: Mogel
LoadTextureInLoadThread(GetCurrentScriptDirectory~"img/mogel.png");
LoadTextureInLoadThread(GetCurrentScriptDirectory~"img/dot_mogel.png");
LoadTextureInLoadThread(GetCurrentScriptDirectory~"img/DRI_b3s1.png");
LoadTextureInLoadThread(GetCurrentScriptDirectory~"Letra.png");
LoadTextureInLoadThread(GetCurrentScriptDirectory~"Emet.png");
LoadTextureInLoadThread(GetCurrentScriptDirectory~"img/laser01a.png");
//Graphics and Effects
LoadTextureInLoadThread(GetCurrentScriptDirectory~"lib/AllStarShot.png");
LoadTextureInLoadThread(GetCurrentScriptDirectory~"lib/Nuclear.png");
LoadTextureInLoadThread(GetCurrentScriptDirectory~"lib/img/Aura01.png");
LoadTextureInLoadThread(GetCurrentScriptDirectory~"lib/img/dot.png");
LoadTextureInLoadThread(GetCurrentScriptDirectory~"lib/img/eltmas1.png");
LoadTextureInLoadThread(GetCurrentScriptDirectory~"lib/img/Lifebar02.png");
LoadTextureInLoadThread(GetCurrentScriptDirectory~"lib/img/magic01.png");
LoadTextureInLoadThread(GetCurrentScriptDirectory~"lib/img/magic02.png");
TStage();
SetPlayerLife(9);
SetPlayerSpell(2);
Back(15);
 Langel1 = LoadScript(angel);
 Ledo1 = LoadScript(edotalk);
 Ledo2 = LoadScript(edorev);
 Lmog1 = LoadScript(mogetalk);
 Lmog2 = LoadScript(mogel);

}

@MainLoop
{
	yield;
}

@Finalize
{
}
@Event{
alternative(GetEventType())
	case(EV_PAUSE_ENTER)
	{
		ObjSound_Stop(bgm);
	}
	case(EV_PAUSE_LEAVE)
	{
		ObjSound_Play(bgm);
	}
}


task TStage
{
if(!IsReplay) {SaveCommonDataAreaToReplayFile("Datos Del Juego");
}
else {
LoadCommonDataAreaFromReplayFile("Datos Del Juego");
}
StageOver;




	
PlayMusic2(bgm,dir~"bgm/DRI_Stage.ogg",100,5.4,134.9);
loop(300){yield;}
	

	loop(60){yield;}
	
	StartScript(Langel1);
	while(!IsCloseScript(Langel1))
	{
		yield;
	}

	loop(120){yield;}
	
	StartScript(Ledo1);
	while(!IsCloseScript(Ledo1))
	{
		yield;
	}
	
	ObjSound_Stop(bgm);
	PlayMusic2(bgm,dir~"bgm/DRI_Boss1.ogg",100,0,162);
	StartScript(Ledo2);
	while(!IsCloseScript(Ledo2))
	{
		yield;
	}

	loop(120){yield;}
	StartScript(Lmog1);
	while(!IsCloseScript(Lmog1))
	{
		yield;
	}
	ObjSound_Stop(bgm);
	PlayMusic2(bgm,dir~"bgm/DRI_Boss2.ogg",100,0,290.7);
	StartScript(Lmog2);
	while(!IsCloseScript(Lmog2))
	{
		yield;
	}
	//〜〜〜敵の出現やボスの出現を繰り返す。

	loop(240){yield;}

    //ステージ終了
	finished = true;
	ObjSound_Stop(bgm);
	Obj_Delete(bgm);
	CloseStgScene();
}

task Back(Size){
    let SFobj = ObjPrim_Create(OBJ_SPRITE_3D);
    let SFimg = GetCurrentScriptDirectory ~ "stage02a.png";
     let move = 0;
    LoadTexture(SFimg);
    ObjPrim_SetTexture(SFobj,SFimg);
    ObjSprite3D_SetSourceRect(SFobj,0,0,512*Size,128*Size);
    ObjSprite3D_SetDestRect(SFobj,-256*Size,-64*Size,256*Size,64*Size);
  ObjRender_SetScaleXYZ(SFobj,2,2,2);
    ObjRender_SetAngleXYZ(SFobj,-90,75,0);
     
    SetCameraRadius(700);
     
    //SetFogEnable(false);
    //SetFogParam(1100,1500,255,255,255);
     
    Obj_SetRenderPriorityI(SFobj,20);
     
    while(!Obj_IsDeleted(SFobj)){
  ObjSprite3D_SetSourceDestRect(SFobj,0*Size,0*Size,512*Size,128*Size+move);
move += 20.231;
    yield;
    }
}
task PlayMusic2(s,str,v,loopstart,loopend){
	ObjSound_Load(s,str);
	ObjSound_SetSoundDivision(s,SOUND_BGM);
	ObjSound_SetVolumeRate(s,v);
	ObjSound_SetLoopEnable(s,true);
	ObjSound_SetLoopTime(s,loopstart,loopend);
	ObjSound_SetRestartEnable(s,true);
	ObjSound_Play(s);
	
}

task StageOver{//CK Crash
    while(GetPlayerState() != STATE_END){yield;}
    loop(60){yield;}
    ObjSound_Stop(bgm);
    CloseStgScene();
}