#“Œ•û’e–‹•—[Stage]
#ScriptVersion[3]
#Title["Shou!"]
#Text["By TalosMistake"]
#Player[DEFAULT]
#System["./system/Default_System.txt"]
#include"./Shot/ZUNShot_Const.txt"
#include"./system/Default_Effect.Txt"
let dir = GetCurrentScriptDirectory();
let dirCurrent = GetCurrentScriptDirectory();
let song = ObjSound_Create;
let MainSTG = GetCurrentScriptDirectory();

@Initialize
{
	SetPlayerLife(4);
	DifficultyMenu();
	StartScript(LoadScriptInThread(dir ~ "BG.txt"));
	LoadTexture(dirCurrent~"img/Cutin.png");
	LoadTexture(dirCurrent~"img/effbreak.png");
	LoadTexture(dirCurrent~"img/Marisa1.png");
	LoadTexture(dirCurrent~"img/stg3bg1.png");
	LoadTexture(dirCurrent~"img/boss.png");
	LoadTexture(dirCurrent~"Shot/ZUNShot.png");
	LoadTexture(dirCurrent~"system/img/front01.png");
	LoadTexture(dirCurrent~"system/img/front00.png");
	LoadTexture(dirCurrent~"img/Dot.png");
	LoadTexture(dirCurrent~"img/Cutin.png");
	LoadTexture(dirCurrent~"img/cdbg05a.png");
	LoadTexture(dirCurrent~"img/cdbg05b.png");
}

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

@MainLoop
{
	yield;
}

@Finalize
{
}

task DifficultyMenu{
	let selection = 0;
	SetForbidPlayerShot(true);
	SetForbidPlayerSpell(true);
	SetCommonData("Difficulty","Easy");
	loop(60){
	yield;
	}
	let menuItems = 2;
	let press = 0;
	DrawDifficulty(192,185,"Hard",0);
	DrawDifficulty(193,285,"Lunatic",1);
	DrawText(60,75,18,"RED","Choose the Difficulty (Press X).");
	loop(60){yield;}
	while(press==0){
    if(GetVirtualKeyState(VK_UP)==KEY_PUSH){ 
	selection--;
	PlaySound("select",100,0);
	}
    if(GetVirtualKeyState(VK_DOWN)==KEY_PUSH){
	selection++;
	PlaySound("select",100,0);
	}
    if(GetVirtualKeyState(VK_BOMB)==KEY_PUSH){
	PlaySound("ok",100,0);
	press++;
	}
    if(selection >= menuItems){ selection = 0; }
    if(selection < 0){ selection = menuItems-1; }
	yield;
	}
	TStage;
		task DrawDifficulty(px,py,text,num){
		let path = GetCurrentScriptDirectory() ~ "system/img/front00.png";
		let obj = ObjPrim_Create(OBJ_SPRITE_2D);
		let value = 0;
		let alpha = 0;
		if(text=="Hard"){value=2;}
		if(text=="Lunatic"){value=3;}
		ObjPrim_SetTexture(obj, path);
		ObjRender_SetScaleXYZ(obj,0.8,0.8,1);
		ObjRender_SetPosition(obj,px,py,0);
		ObjSprite2D_SetSourceRect(obj, 520, 608+32*value, 520+144, 640+32*value);
		ObjSprite2D_SetDestCenter(obj);
			while(press==0){
			if(alpha<255){alpha+=10;}
			if(selection==num){
			ObjRender_SetAlpha(obj,alpha);
			}
			else{
			ObjRender_SetAlpha(obj,alpha/2);
			}
			yield;
			}
			if(selection==num){SetCommonData("Difficulty",text);}
			Obj_Delete(obj);
		}
		task DrawText(x,y,size,colort,text){
			let objTxt=ObjText_Create;
			let color = ReturnColor(colort);
			let alpha = 0;
			ObjText_SetText(objTxt,text);
			ObjText_SetFontSize(objTxt,size);
			ObjText_SetFontColorTop(objTxt,255,255,255);
			ObjText_SetFontColorBottom(objTxt,255,255,255);
			ObjText_SetFontBorderWidth(objTxt,1);
			ObjText_SetFontBorderType(objTxt,BORDER_FULL);
			ObjText_SetFontBorderColor(objTxt,color[0],color[1],color[2]);
			ObjText_SetMaxWidth(objTxt,500);
			ObjText_SetMaxHeight(objTxt,100);
			ObjText_SetHorizontalAlignment(objTxt,ALIGNMENT_LEFT);
			ObjRender_SetPosition(objTxt,x,y,0);
			while(press==0){
			if(alpha<255){alpha+=10;}
			ObjRender_SetAlpha(objTxt,alpha);
			yield;
			}
			Obj_Delete(objTxt);
			}
	}


task TStage
{
	let path;
	let idScript;
	Sound(dir ~ "Stage.mp3");
	if(GetCommonData("Difficulty","Easy")=="Hard"){path = dir ~ "NazrinH.txt";}
	else if(GetCommonData("Difficulty","Easy")=="Lunatic"){path = dir ~ "NazrinL.txt";}
	idScript = LoadScriptInThread(path);
	loop(150){yield;};
	StartScript(idScript);
	while(!IsCloseScript(idScript) && GetPlayerState() != STATE_END)
	{
		yield;
	}
	
	
	if(GetCommonData("Difficulty","Easy")=="Hard"){path = dir ~ "ShouH.txt";}
	else if(GetCommonData("Difficulty","Easy")=="Lunatic"){path = dir ~ "ShouL.txt";}
	idScript = LoadScriptInThread(path);
	loop(80){yield;};
	StopS(song);
	loop(100){yield;}
	StartScript(idScript);
		while(!IsCloseScript(idScript) && GetPlayerState() != STATE_END)
	{
		yield;
	}
	loop(240){yield;}
	
	CloseStgScene();
}

function Sound(path){
	ObjSound_Load(song,path);
	ObjSound_SetSoundDivision(song, SOUND_BGM);
	ObjSound_SetRestartEnable(song, true);
	ObjSound_SetLoopEnable(song, true);
	ObjSound_SetLoopTime(song, 0,600);
	ObjSound_Play(song);
	ObjSound_SetVolumeRate(song,100);
	}
	
task StopS(obj){
	descent(i in 0..100){
	ObjSound_SetVolumeRate(song,i);
	loop(2){yield;}
	}
	ObjSound_Stop(song);
	}
	
task PlaySound(str,v,w){
	let s = ObjSound_Create;
	if(str == "select"){ObjSound_Load(s,MainSTG~"sound/select.wav");}
	if(str == "ok"){ObjSound_Load(s,MainSTG~"sound/ok.wav");}
	loop(w){yield;}
	ObjSound_SetSoundDivision(s,SOUND_SE);
	ObjSound_SetVolumeRate(s,v);
	ObjSound_Play(s);
}

function ReturnColor(type){
	if(type=="RED"){return [255,0,0];}
	if(type=="ORANGE"){return [255,128,0];}
	if(type=="YELLOW"){return [255,255,0];}
	if(type=="GREEN"){return [0,255,0];}
	if(type=="BLUE"){return [0,0,255];}
	if(type=="PURPLE"){return [255,0,255];}
	if(type=="WHITE"){return [255,255,255];}
	}

