#TouhouDanmakufu[Stage]
#Title[Ten Desires - Extra Stage]
#Text[By Shockman2.]
#Player[FREE]
#ScriptVersion[2]

script_stage_main{

let SP = GetCurrentScriptDirectory~"Enemy\sp\sp.png";
   let m = -1400;
   let n = -700;
   let o = -1000;
   let l = 0;
   let f2 = 0;
   let f3 = 0;
   let f4 = 0;
   let f5 = 0;
   let f6 = 0;
   let f7 = 0;
   let f = 0;
   let nbg = GetCurrentScriptDirectory ~ "ef\nbg1.png";
   let nbg2 = GetCurrentScriptDirectory ~ "ef\nbg2.png";
   let nbg3 = GetCurrentScriptDirectory ~ "ef\nbg3.png";
   let ex = GetCurrentScriptDirectory ~ "ef\EXTRA.png";
   let Frame = GetCurrentScriptDirectory ~ "ef\Frame.png";
   let ST = GetCurrentScriptDirectory ~ "mu\stbgm.png";
   let BO  = GetCurrentScriptDirectory ~ "Boss\mu\bgm.png";
   let depth_buffer_enable = false;

 function Wait(let frames){
   loop(frames*2){yield;}
 }
 function WaitForZeroEnemy{
  while(GetEnemyNum != 0){yield;}
 }
 task stage{
  Wait(120);
loop(10){
  Wait(60);
  CreateEnemyFromFile(GetCurrentScriptDirectory~"Enemy\BF1.txt", rand(GetClipMinX + 10,GetClipMaxX - 10), GetClipMinY - 10, 0, 0, 0);
}
loop(20){
  Wait(30);
  CreateEnemyFromFile(GetCurrentScriptDirectory~"Enemy\BYYE2.txt", rand(GetClipMinX + 10,GetClipMaxX - 10), GetClipMinY - 10, 0, 0, 0);
}
  Wait(60);
loop(3){
  Wait(3);
  CreateEnemyFromFile(GetCurrentScriptDirectory~"Enemy\RF2.txt", rand(GetClipMinX + 10,GetClipMaxX - 10), GetClipMinY - 10, 0, 0, 0);
}
  Wait(120);
loop(4){
  Wait(3);
  CreateEnemyFromFile(GetCurrentScriptDirectory~"Enemy\RF2.txt", rand(GetClipMinX + 10,GetClipMaxX - 10), GetClipMinY - 10, 0, 0, 0);
}
  Wait(120);
loop(10){
  Wait(3);
  CreateEnemyFromFile(GetCurrentScriptDirectory~"Enemy\RF2.txt", rand(GetClipMinX + 10,GetClipMaxX - 10), GetClipMinY - 10, 0, 0, 0);
}
  Wait(100);
loop(20){
  Wait(20);
  CreateEnemyFromFile(GetCurrentScriptDirectory~"Enemy\BYYE.txt", GetClipMinX - 10, GetClipMinY + rand(10,100), 0, 0, 0);
  CreateEnemyFromFile(GetCurrentScriptDirectory~"Enemy\RYYE.txt", GetClipMaxX + 10, GetClipMinY + rand(10,100), 0, 0, 0);
}
  WaitForZeroEnemy;
loop(10){
  Wait(70);
  CreateEnemyFromFile(GetCurrentScriptDirectory~"Enemy\RF1.txt", rand(GetClipMinX + 10,GetClipMinX + 30), GetClipMinY - 10, 0, 0, 0);
  CreateEnemyFromFile(GetCurrentScriptDirectory~"Enemy\BF1.txt", rand(GetClipMaxX - 200,GetClipMaxX - 10), GetClipMinY - 10, 0, 0, 0);
}
Wait(60);
loop(3){
Wait(10);
  CreateEnemyFromFile(GetCurrentScriptDirectory~"Enemy\BYYE2.txt", rand(GetClipMinX + 10,GetClipMaxX - 10), GetClipMinY - 10, 0, 0, 0);
}
  WaitForZeroEnemy;
loop(10){
  Wait(10);
  CreateEnemyFromFile(GetCurrentScriptDirectory~"Enemy\BF2.txt", GetClipMinX - 10, GetClipMinY + rand(10,100), 0, 0, 0);
}
  WaitForZeroEnemy;   
CreateEnemyBossFromFile(GetCurrentScriptDirectory~"Miyako\MidBoss.txt", 0, 0, 0, 0, 0);
  WaitForZeroEnemy;  
  Wait(30);
loop(3){
  Wait(100);
  CreateEnemyFromFile(GetCurrentScriptDirectory~"Enemy\LF1.txt", rand(GetClipMinX + 10,GetClipMaxX - 10), GetClipMinY - 10, 0, 0, 0);
}
  WaitForZeroEnemy;  
  Wait(60);
loop(3){
  Wait(3);
  CreateEnemyFromFile(GetCurrentScriptDirectory~"Enemy\RF2.txt", rand(GetClipMinX + 10,GetClipMaxX - 10), GetClipMinY - 10, 0, 0, 0);
}
  Wait(120);
loop(4){
  Wait(3);
  CreateEnemyFromFile(GetCurrentScriptDirectory~"Enemy\RF2.txt", rand(GetClipMinX + 10,GetClipMaxX - 10), GetClipMinY - 10, 0, 0, 0);
}
  Wait(120);
loop(7){
  Wait(3);
  CreateEnemyFromFile(GetCurrentScriptDirectory~"Enemy\RF2.txt", rand(GetClipMinX + 10,GetClipMaxX - 10), GetClipMinY - 10, 0, 0, 0);
}
  Wait(120);
loop(7){
  Wait(3);
  CreateEnemyFromFile(GetCurrentScriptDirectory~"Enemy\RF2.txt", rand(GetClipMinX + 10,GetClipMaxX - 10), GetClipMinY - 10, 0, 0, 0);
}
  Wait(100);
loop(10){
Wait(50);
  CreateEnemyFromFile(GetCurrentScriptDirectory~"Enemy\RF2.txt", rand(GetClipMinX + 10,GetClipMinX + 30), GetClipMinY - 10, 0, 0, 0);
  CreateEnemyFromFile(GetCurrentScriptDirectory~"Enemy\RYYE3.txt", rand(GetClipMinX + 10,GetClipMaxX - 10), GetClipMinY - 10, 0, 0, 0);
}
loop(10){
Wait(50);
  CreateEnemyFromFile(GetCurrentScriptDirectory~"Enemy\RF1.txt", rand(GetClipMaxX - 100,GetClipMaxX - 10), GetClipMinY - 10, 0, 0, 0);
  CreateEnemyFromFile(GetCurrentScriptDirectory~"Enemy\RYYE3.txt", rand(GetClipMinX + 10,GetClipMaxX - 10), GetClipMinY - 10, 0, 0, 0);
}
loop(10){
Wait(20);
  CreateEnemyFromFile(GetCurrentScriptDirectory~"Enemy\BYYE2.txt", rand(GetClipMinX + 10,GetClipMaxX - 10), GetClipMinY - 10, 0, 0, 0);
}
loop(3){
  Wait(100);
  CreateEnemyFromFile(GetCurrentScriptDirectory~"Enemy\LF2.txt", rand(GetClipMinX + 10,GetClipMaxX - 10), GetClipMinY - 10, 0, 0, 0);
}
  Wait(10);
loop(10){
Wait(20);
  CreateEnemyFromFile(GetCurrentScriptDirectory~"Enemy\BYYE2.txt", rand(GetClipMinX + 10,GetClipMaxX - 10), GetClipMinY - 10, 0, 0, 0);
}
loop(15){
  Wait(20);
  CreateEnemyFromFile(GetCurrentScriptDirectory~"Enemy\RF2.txt", rand(GetClipMinX + 10,GetClipMaxX - 10), GetClipMinY - 10, 0, 0, 0);
}
  WaitForZeroEnemy; 
  Wait(20);
loop(20){
  Wait(20);
  CreateEnemyFromFile(GetCurrentScriptDirectory~"Enemy\BYYE.txt", GetClipMinX - 10, GetClipMinY + rand(10,100), 0, 0, 0);
  CreateEnemyFromFile(GetCurrentScriptDirectory~"Enemy\RYYE.txt", GetClipMaxX + 10, GetClipMinY + rand(10,100), 0, 0, 0);
}
loop(3){
  Wait(10);
  CreateEnemyFromFile(GetCurrentScriptDirectory~"Enemy\LF1.txt", rand(GetClipMinX + 10,GetClipMaxX - 10), GetClipMinY - 10, 0, 0, 0);
}
  Wait(140);
loop(15){
  Wait(60);
  CreateEnemyFromFile(GetCurrentScriptDirectory~"Enemy\RF1.txt", rand(GetClipMinX + 10,GetClipMinX + 30), GetClipMinY - 10, 0, 0, 0);
  CreateEnemyFromFile(GetCurrentScriptDirectory~"Enemy\BF1.txt", rand(GetClipMaxX - 200,GetClipMaxX - 10), GetClipMinY - 10, 0, 0, 0);
}
  WaitForZeroEnemy; 
  Wait(70);
  CreateEnemyFromFile(GetCurrentScriptDirectory~"Enemy\PYYE.txt", rand(GetClipMinX + 10,GetClipMaxX - 10), GetClipMinY - 10, 0, 0, 0);
  WaitForZeroEnemy; 
  Wait(200);
  CreateEnemyBossFromFile(GetCurrentScriptDirectory~"Boss\Boss.txt", rand(GetClipMinX + 10,GetClipMaxX - 10), GetClipMinY - 10, 0, 0, 0);
  Wait(10);
  FadeOutMusic(ST,100);
  PlayMusic(BO);
  WaitForZeroEnemy; 
  Wait(200);
  Clear;
 }

	task Extra{
let obj=Obj_Create(OBJ_EFFECT);
Obj_SetX(obj,510);
Obj_SetY(obj,20);
ObjEffect_SetLayer(obj,8);
ObjEffect_SetRenderState(obj,ALPHA);
ObjEffect_SetTexture(obj,ex);
ObjEffect_SetPrimitiveType(obj,PRIMITIVE_TRIANGLEFAN);
ObjEffect_SetScale(obj,1,1);
ObjEffect_SetAngle(obj,0,0,0);
ObjEffect_CreateVertex(obj,4);
ObjEffect_SetVertexUV(obj,0,0,0);
ObjEffect_SetVertexUV(obj,1,52,0);
ObjEffect_SetVertexUV(obj,2,52,19);
ObjEffect_SetVertexUV(obj,3,0,19);
ObjEffect_SetVertexXY(obj,0,0,0);
ObjEffect_SetVertexXY(obj,1,52,0);
ObjEffect_SetVertexXY(obj,2,52,19);
ObjEffect_SetVertexXY(obj,3,0,19);

yield;
	}


  @Initialize{
      LoadGraphic(nbg);
      LoadGraphic(nbg2);
      LoadGraphic(nbg3);
      LoadGraphic(ex);
      LoadGraphic(SP);
      LoadGraphic(Frame);
LoadMusic(ST);
PlayMusic(ST);
LoadMusic(BO);
 stage;
  }
 @MainLoop{
      m += 5;
      n += 5;
      o += 5;
f += 5;
   yield;
  }
  @BackGround{
if (f5 == 0){
 Extra;
}
   yield;
      WriteZBuffer(depth_buffer_enable);
      UseZBuffer(depth_buffer_enable);  

      SetViewTo(0, -60, 80);
      SetViewFrom(400, 80, 35);     

      SetAlpha(255);
      SetTexture(nbg);
      SetGraphicRect(0, 0, 1000, 1000000);
      SetGraphicAngle(90, 0, 0);
      SetGraphicScale(1,1);
      DrawGraphic3D(0, -168, f);

      SetAlpha(255);
      SetTexture(nbg2);
      SetGraphicRect(0, 0, 128, 128);

      SetGraphicAngle(90, 0, 0);
      SetGraphicScale(1,1);
      DrawGraphic3D(0, -128, m+l);

      SetGraphicAngle(0, 90, 0);
      SetGraphicScale(1,0.4);
      DrawGraphic3D(0 + 64, -144, m+l);

      SetGraphicAngle(0, 0, 0);
      SetGraphicScale(1,0.4);
      DrawGraphic3D(0, -144, m + 64+l);

      SetGraphicAngle(0, 0, 0);
      SetGraphicScale(0.5,1);
      DrawGraphic3D(0, -64, m - 32+l);

      SetGraphicAngle(0, 90, 0);
      SetGraphicScale(0.5,1);
      DrawGraphic3D(0 - 32, -64, m+l);

      SetGraphicAngle(0, 90, 0);
      SetGraphicScale(0.5,1);
      DrawGraphic3D(0 + 32, -64, m+l);

      SetGraphicAngle(0, 0, 0);
      SetGraphicScale(0.5,1);
      DrawGraphic3D(0, -64, m + 32+l);

      SetGraphicAngle(90, 0, 0);
      SetGraphicScale(0.5,0.5);
      DrawGraphic3D(0, 0, m+l);






      SetGraphicAngle(90, 0, 0);
      SetGraphicScale(1,1);
      DrawGraphic3D(100, -128, n+l);

      SetGraphicAngle(0, 90, 0);
      SetGraphicScale(1,0.4);
      DrawGraphic3D(100 + 64, -144, n+l);

      SetGraphicAngle(0, 0, 0);
      SetGraphicScale(1,0.4);
      DrawGraphic3D(100, -144, n + 64+l);

      SetGraphicAngle(0, 0, 0);
      SetGraphicScale(0.5,1);
      DrawGraphic3D(100, -64, n - 32+l);

      SetGraphicAngle(0, 90, 0);
      SetGraphicScale(0.5,1);
      DrawGraphic3D(100 - 32, -64, n+l);

      SetGraphicAngle(0, 90, 0);
      SetGraphicScale(0.5,1);
      DrawGraphic3D(100 + 32, -64, n+l);

      SetGraphicAngle(0, 0, 0);
      SetGraphicScale(0.5,1);
      DrawGraphic3D(100, -64, n + 32+l);

      SetGraphicAngle(90, 0, 0);
      SetGraphicScale(0.5,0.5);
      DrawGraphic3D(100, 0, n+l);





      SetGraphicAngle(90, 0, 0);
      SetGraphicScale(1,1);
      DrawGraphic3D(-300, -128, o+l);

      SetGraphicAngle(0, 90, 0);
      SetGraphicScale(1,0.4);
      DrawGraphic3D(-300 + 64, -144, o+l);

      SetGraphicAngle(0, 0, 0);
      SetGraphicScale(1,0.4);
      DrawGraphic3D(-300, -144, o + 64+l);

      SetGraphicAngle(0, 0, 0);
      SetGraphicScale(0.5,1);
      DrawGraphic3D(-300, -64, o - 32+l);

      SetGraphicAngle(0, 90, 0);
      SetGraphicScale(0.5,1);
      DrawGraphic3D(-300 - 32, -64, o+l);

      SetGraphicAngle(0, 90, 0);
      SetGraphicScale(0.5,1);
      DrawGraphic3D(-300 + 32, -64, o+l);

      SetGraphicAngle(0, 0, 0);
      SetGraphicScale(0.5,1);
      DrawGraphic3D(-300, -64, o + 32+l);

      SetGraphicAngle(90, 0, 0);
      SetGraphicScale(0.5,0.5);
      DrawGraphic3D(-300, 0, o+l);


      SetAlpha(200);
      SetTexture(nbg3);
      SetGraphicRect(0, 0, 256, 256);

      SetGraphicAngle(0, 0, 270);
      SetGraphicScale(1,1);
      DrawGraphic(GetClipMinX+50, GetClipMinY+20+30*cos(f5));

      SetGraphicAngle(0, 0, 270);
      SetGraphicScale(1,1);
      DrawGraphic(GetClipMinX+128, GetClipMinY+20-30*cos(f5));

      SetGraphicAngle(0, 0, 270);
      SetGraphicScale(1,-1);
      DrawGraphic(GetClipMaxX-50, GetClipMinY+20+30*cos(f5));

      SetGraphicAngle(0, 0, 270);
      SetGraphicScale(1,-1);
      DrawGraphic(GetClipMaxX-128, GetClipMinY+20-30*cos(f5));



if (f2 == 400){
m = -1400;
f2 = 0;
}
if (f3 == 200){
n = -1400;
f3 = -200;
}
if (f4 == 300){
o = -1400;
f4 = -100;
}
f2++;
f3++;
f4++;
f5 += 0.4;
}
  @Finalize{
}
}