#TouhouDanmakufu[Stage]
#ScriptVersion[3]
#Title["testest"]
#Text["stage"]
#System["./my_system/My_system.txt"]
#include "script/default_system/Default_ShotConst.txt"
#include "./enemy1.txt"
#include "./enemy2.txt"
#include "./enemy3.txt"
#include "./enemy4.txt"
#include "./enemy8.txt"
#include "./3dstage1.txt"
#include "./titletask.txt"



@Initialize
{
    TStage();
	renderStage;
	scrollStage;
	stagetitle;
	


  SetPlayerLife(5);


}
@MainLoop
{

if (GetPlayerState() == STATE_END) { 
wait(20); CloseStgScene(); }
    yield;
}
@Finalize
{
}
task TStage
 
{  
wait(100);

	   let dir = GetCurrentScriptDirectory();
    //ボス再生
    let path = dir ~ "Plural3.txt";
    let idScript = LoadScriptInThread(path);
    loop(60){yield;}//1秒くらいあれば、コンパイル完了すると思われる。
    StartScript(idScript);
	
    //敵ボスシーンが終了するまで待機
    while(!IsCloseScript(idScript) && GetPlayerState() != STATE_END)
    {
        yield;
    }

	  
}


function SetStageDifficulty{ //Adapted from code used by gtbot
    let selection = 0; //Initialize the player's selection to index 0
    let sdiff = 0; //Selected difficulty
	
    let TextObjects = []; //Container for text objects, so that we can delete them at the end of the function
    let TextNames = ["Normal", "Hard"]; //Supported difficulties (text only)
	
    let diffs = [1, 2]; //Define the values (CommonData) to utilize 
    let Center = [GetStgFrameWidth()/2, GetStgFrameHeight()/2]; //Define the center of the playing field
    ascent(i in 0..length(TextNames)){ //For each difficulty option, handle the text object
        TextObjects = TextObjects ~ [DrawSubMenuText(TextNames[i])]; //Add the Text object to the array
        let locText = TextObjects[i]; //Retrieve text contents
        ObjText_SetHorizontalAlignment(locText, ALIGNMENT_CENTER);
        ObjRender_SetPosition(locText, Center[0] - 100, Center[1] - 150 + i*25, 0);
        ObjText_SetMaxWidth(locText, 200);
        ObjText_SetFontSize(locText, 16);//new
        ObjText_SetFontType(locText, "Helvetica");
        ObjText_SetFontBorderColor(locText, 16, 16, 16);
    }
	
    //Infinite Loop that runs until the player has made a selection.
    loop{
        //Menu controls
        if(GetVirtualKeyState(VK_UP) == KEY_PUSH){selection--;}
        if(GetVirtualKeyState(VK_DOWN) == KEY_PUSH){selection++;}
        if(selection < 0){selection = 1;}
        if(selection > 1){selection = 0;}
        //Make it clear to the player which option is selected
        ascent(i in 0..length(TextObjects)){
            if(selection == i){
                ObjText_SetFontColorTop(TextObjects[i], r[i], g[i], b[i]);
                ObjText_SetFontColorBottom(TextObjects[i], r[i]/1.5, g[i]/1.5, b[i]/1.5);
            } else {
                ObjText_SetFontColorTop(TextObjects[i], r[i]/1.75, g[i]/1.75, b[i]/1.75);
                ObjText_SetFontColorBottom(TextObjects[i], r[i]/2.25, g[i]/2.25, b[i]/2.25);
            }
        }
        //Handle setting Common Data here
        //SEE BELOW
		
		    if(GetVirtualKeyState(VK_SHOT) == KEY_PUSH){
            sdiff = diffs[selection];
            SetCommonData("Difficulty", sdiff); //Set the CommonData here
            break;
        }
		
		  if(selection == 0){SetCommonData("Difficulty", 1);}
        if(selection == 1){SetCommonData("Difficulty", 2);}
	
        yield;
    }
    ascent(i in 0..length(TextObjects)){
        Obj_Delete(TextObjects[i]);
    }
}

function wait(w){
       loop(w) {
	     yield;
		 }
	}