#e[Stage]
#Title[YI]
#Text[]
#Image[]
#BackGround[USER]
#Player[FREE]
#PlayLevel[]
#ScriptVersion[2]


script_stage_main{
 /* #include_script".\Config.txt"
   #include_script".\Local.txt" */
 #include_script".\LocalFunction.txt"
  #include_script".\StageData.txt"

	@Initialize()
	{   
		Stage;
     SetRateScoreSystemEnable(false);
     SetDefaultStatusVisible(false);
        ExpertEx(false,256,3);
	}
	
	@MainLoop()
	{
    if(OnEvent){break;}
    backframe++;
  info_ver = GetCommonDataDefaultEx("","ver",0);
  PracticeStageFrag = GetCommonDataDefaultEx("","psf",[false]);
  PracticeCardFrag = GetCommonDataDefaultEx("","pcf",[false]);
  SpellCardHistory = GetCommonDataDefaultEx("","sch",[0]);
  GetSpellCard = GetCommonDataDefaultEx("","gsc",[0]);
  HighestScore = GetCommonDataDefaultEx("","hs",[1000000]);
		yield;
	}
	
       @DrawLoop{
    } 

	@Finalize()
	{
     DeleteCommonData("timeout");  
     DeleteCommonData("stagelist");
     DeleteCommonData("spellnow");
     DeleteCommonData("gof");
   DeleteCommonData("howmany");
     if(!modesave){
        DeleteCommonData("mode");
        DeleteCommonData("dif");
        DeleteCommonData("chr");
      /*  DeleteCommonData("howmany");*/
          }
   /*  DeleteCommonData("ver");
     DeleteCommonData("hs");*/
       if(!replay){SaveCommonData;}
	}

  @DrawTopObject{
/*  DrawText(info_ver,cx,cy-180,20,255);
  DrawText(length(PracticeStageFrag),cx,cy-150,20,255);
  DrawText(length(PracticeCardFrag),cx,cy-120,20,255);
  DrawText(length(SpellCardHistory),cx,cy-90,20,255);
  DrawText(length(GetSpellCard),cx,cy-60,20,255);  
 if(!replay){ DrawText(continuenum,cx,cy-60,20,255);
  DrawText(GetAllowedContinueCount,cx,cy-30,20,255);  } */
        }

   @BackGround(){
   UseZBuffer(true);
   WriteZBuffer(true);

  BackGraphic;
  SetRenderState(ALPHA);
  SetAlpha(255);
 SetColor(255,255,255);
 SetGraphicScale(1,1);
    }   

     task Stage{
       yield;
 CompileEnemyFromFile(csd~"zako\Enemy0.txt");
 CompileEnemyFromFile(csd~"zako\Enemy1.txt");
 CompileEnemyFromFile(csd~"zako\Enemy2.txt");
 CompileEnemyFromFile(csd~"zako\Enemy3.txt");
 CompileEnemyFromFile(csd~"zako\Enemy4.txt");
 DrawOutFrame; 
 if(IsReplay){replay = true;}
 loop{
   alternative(GetCommonDataDefaultEx("","mode",0))
     case(0){TitleMenu;}
     case(1){Stage1; Stage2; Stage3; Stage4; Stage5; Stage6; ContinueSystem(1,0,-1);}
     case(2){StageEx; SetCommonDataEx("","mode",0);}
     case(2.5){StagePh; SetCommonDataEx("","mode",0);}
     case(2.9){StageMy; ContinueSystem(2.9,0,-1);}
     case(3){Stage1; ContinueSystem(3,0,-1);}
     case(3.2){Stage2; SetCommonDataEx("","mode",0);}
     case(3.3){Stage3; SetCommonDataEx("","mode",0);}
     case(3.4){Stage4; SetCommonDataEx("","mode",0);}
     case(3.5){Stage5; SetCommonDataEx("","mode",0);}
     case(3.6){Stage6; SetCommonDataEx("","mode",0);}
     case(4.11){boss(csd~"itirin\SpellNo.001_002.txt",cx,miny-30,0,0,0);  SpellPractice(1,0,1,1); ContinueSystem(4.11,0,-1);}
     case(4.12){boss(csd~"murasa\SpellNo.003_006.txt",cx,miny-30,0,0,0);  SpellPractice(1,60*36,1,2); ContinueSystem(4.12,0,-1);}
     case(4.13){boss(csd~"murasa\SpellNo.007_010.txt",cx,miny-30,0,0,0);  SpellPractice(1,60*36,1,2); ContinueSystem(4.13,0,-1);}
     others{Clear;}
   wait(1);
    }
 
     }

 function enemy(text,x,y,speed,angle,arg){
       CreateEnemyFromFile(text,x,y,speed,angle,arg);
            }

   function boss(text,x,y,speed,angle,arg){
       CreateEnemyBossFromFile(text,x,y,speed,angle,arg);
            }

   function wait(frame){
	loop(frame){yield};
		}
   function waitnext{
	while(GetEnemyNum() != 0){yield;}
		}
       function stagewait(frame){
	loop(frame){while(GetCommonDataDefaultEx("","gof",false)){yield;} wait(1);}
		}
 }