#TouhouDanmakufu[Stage]
#ScriptVersion[3]
#Title["stage2"]
#Text["stage2"]
#System["./my_system/My_system.txt"]
#include "script/default_system/Default_ShotConst.txt"
#include "./enemytrain1.txt"
#include "./enemytrain2.txt"
#include "./enemy2.txt"
#include "./enemy3.txt"
#include "./enemy6.txt"
#include "./enemy7.txt"
#include "./3dstage2.txt"
#include "./titletask2.txt"



@Initialize
{
    TStage();
	renderStage;
	scrollStage;
	stagetitle2;
	
	  SetPlayerLife(8);
}
@MainLoop
{
if (GetPlayerState() == STATE_END) { 
wait(20); CloseStgScene(); }
    yield;
}
@Finalize
{
}
task TStage
{     

wait(100);

let pathmidboss = GetCurrentScriptDirectory() ~ "./midpluraltest.txt";
	  let midbossScript = LoadScriptInThread(pathmidboss);
	  
	  
CreateStageEnemyTrain(510, 100, 4, 180);
CreateStageEnemyTrainEnd2(-100, 20, 4, 0);
wait(76);
CreateStageEnemyTrainMiddle2(-100, 20, 4, 0);
CreateStageEnemyTrainMiddle(510, 100, 4, 180);
wait(70);
CreateStageEnemyTrainEnd(510, 100, 4, 180);
CreateStageEnemyTrain2(-100, 20, 4, 0);
wait(350);
CreateStageEnemy6(100, -20, 5, 90);
CreateStageEnemy6(150, -50, 5, 90);
CreateStageEnemy6(300, -5, 5, 90);
CreateStageEnemy6(222, -28, 5, 90);
CreateStageEnemy6(50, -155, 5, 90);
CreateStageEnemy6(360, -15, 5, 90);
CreateStageEnemy6(115, -180, 5, 90);
CreateStageEnemy6(290, -62, 5, 90);
CreateStageEnemy6(80, -105, 5, 90);
CreateStageEnemy6(190, -200, 5, 90);
CreateStageEnemy6(50, -48, 5, 90);
CreateStageEnemy6(230, -212, 5, 90);
CreateStageEnemy6(180, -290, 5, 90);
CreateStageEnemy6(250, -140, 5, 90);
CreateStageEnemy6(330, -115, 5, 90);
CreateStageEnemy6(200, -112, 5, 90);
wait(450);
CreateStageEnemy6(100, -20, 5, 90);
CreateStageEnemy6(150, -50, 5, 90);
CreateStageEnemy6(300, -5, 5, 90);
CreateStageEnemy6(222, -28, 5, 90);
CreateStageEnemy6(50, -155, 5, 90);
CreateStageEnemy6(360, -15, 5, 90);
CreateStageEnemy6(115, -180, 5, 90);
CreateStageEnemy6(290, -62, 5, 90);
CreateStageEnemy6(80, -105, 5, 90);
CreateStageEnemy6(190, -200, 5, 90);
CreateStageEnemy6(50, -48, 5, 90);
CreateStageEnemy6(230, -212, 5, 90);
CreateStageEnemy6(180, -290, 5, 90);
CreateStageEnemy6(250, -140, 5, 90);
CreateStageEnemy6(330, -115, 5, 90);
CreateStageEnemy6(200, -112, 5, 90);
wait(400);


	   
	 
	    StartScript(midbossScript);
    while(!IsCloseScript(midbossScript) && GetPlayerState() != STATE_END){
      yield;
    }
	
	
	 wait(120);
	   
CreateStageEnemyTrain(510, 100, 7, 180);
CreateStageEnemyTrainEnd2(-100, 20, 7, 0);
CreateStageEnemyTrain(510, 200, 7, 180);
CreateStageEnemyTrainEnd2(-100, 100, 7, 0);
wait(76);
CreateStageEnemyTrainMiddle2(-100, 20, 7, 0);
CreateStageEnemyTrainMiddle(510, 100, 7, 180);
CreateStageEnemyTrainMiddle2(-100, 250, 7, 0);
CreateStageEnemyTrainMiddle(510, 40, 7, 180);
wait(70);
CreateStageEnemyTrainEnd(510, 100, 7, 180);
CreateStageEnemyTrain2(-100, 20, 7, 0);
CreateStageEnemyTrainEnd(510, 50, 7, 180);
CreateStageEnemyTrain2(-100, 160, 7, 0);
CreateStageEnemyTrain(510, 100, 7, 180);
CreateStageEnemyTrainEnd2(-100, 20, 7, 0);
CreateStageEnemyTrain(510, 200, 7, 180);
CreateStageEnemyTrainEnd2(-100, 100, 7, 0);
wait(76);
CreateStageEnemyTrainMiddle2(-100, 20, 7, 0);
CreateStageEnemyTrainMiddle(510, 100, 7, 180);
CreateStageEnemyTrainMiddle2(-100, 250, 7, 0);
CreateStageEnemyTrainMiddle(510, 40, 7, 180);
wait(70);
CreateStageEnemyTrainEnd(510, 100, 7, 180);
CreateStageEnemyTrain2(-100, 20, 7, 0);
CreateStageEnemyTrainEnd(510, 50, 7, 180);
CreateStageEnemyTrain2(-100, 160, 7, 0);
CreateStageEnemyTrain(510, 100, 7, 180);
CreateStageEnemyTrainEnd2(-100, 20, 7, 0);
CreateStageEnemyTrain(510, 200, 7, 180);
CreateStageEnemyTrainEnd2(-100, 100, 7, 0);
wait(76);
CreateStageEnemyTrainMiddle2(-100, 20, 9, 0);
CreateStageEnemyTrainMiddle(510, 100, 9, 180);
CreateStageEnemyTrainMiddle2(-100, 250, 9, 0);
CreateStageEnemyTrainMiddle(510, 40, 9, 180);
wait(70);
CreateStageEnemyTrainEnd(510, 100, 9, 180);
CreateStageEnemyTrain2(-100, 20, 9, 0);
CreateStageEnemyTrainEnd(510, 50, 9, 180);
CreateStageEnemyTrain2(-100, 160, 9, 0);
wait(100);
CreateStageEnemy7(330, 0, 5, 90);
CreateStageEnemy72(50, 0, 5, 90);
wait(300);
CreateStageEnemy62(222, -155, 5, 90);
CreateStageEnemy62(180, -155, 5, 90);
CreateStageEnemy62(320, -155, 5, 90);
CreateStageEnemy62(115, -155, 5, 90);
CreateStageEnemy62(290, -155, 5, 90);
CreateStageEnemy62(80, -155, 5, 90);
CreateStageEnemy7(330, 0, 5, 90);
CreateStageEnemy72(50, 0, 5, 90);
wait(300);
CreateStageEnemy62(222, -155, 5, 90);
CreateStageEnemy62(180, -155, 5, 90);
CreateStageEnemy6(320, -155, 5, 90);
CreateStageEnemy62(115, -155, 5, 90);
CreateStageEnemy62(290, -155, 5, 90);
CreateStageEnemy62(80, -155, 5, 90);
CreateStageEnemy7(330, 0, 5, 90);
CreateStageEnemy72(50, 0, 5, 90);
wait(300);
CreateStageEnemy62(222, -155, 5, 90);
CreateStageEnemy62(180, -155, 5, 90);
CreateStageEnemy62(320, -155, 5, 90);
CreateStageEnemy62(115, -155, 5, 90);
CreateStageEnemy62(290, -155, 5, 90);
CreateStageEnemy7(330, 0, 5, 90);
CreateStageEnemy72(50, 0, 5, 90);
wait(300);
CreateStageEnemy7(330, 0, 5, 90);
CreateStageEnemy72(50, 0, 5, 90);
wait(300);
CreateStageEnemy62(222, -155, 5, 90);
CreateStageEnemy62(180, -155, 5, 90);
CreateStageEnemy62(320, -155, 5, 90);
CreateStageEnemy62(115, -155, 5, 90);
CreateStageEnemy62(290, -155, 5, 90);
CreateStageEnemy62(80, -155, 5, 90);
wait(300);




	
	
	 wait(820);
	  
	   let dir = GetCurrentScriptDirectory();

    let path = dir ~ "Plural4.txt";
    let idScript = LoadScriptInThread(path);
    loop(60){yield;}
    StartScript(idScript);
	

    while(!IsCloseScript(idScript) && GetPlayerState() != STATE_END)
    {
        yield;
    }
	
	loop(240){yield;}


	CloseStgScene();
}

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