#e[Stage]
#Title[NWL]
#Text[ϑzx񌴈ẴIWiXe[Wł]
#ScriptVersion[2]

script_stage_main {
 let title = 1; //^CgȂtrue
 let titleimg = GetCurrentScriptDirectory~"img\TitleBack.png"; //^Cg摜
 let count = 1; //J[\̏lPɂ
 let plus = 1;

 @Initialize {
  LoadGraphic(titleimg);

  TStage;
 }

 @MainLoop {
  if(title == 1) {
   ForbidShot(true);
   ForbidBomb(true);
   SetPlayerX(GetCenterX);
   SetPlayerY(GetClipMaxY);
   if(GetKeyState(VK_SHOT) == KEY_PUSH) {
    title = 2;
   }
  }
  else if(title == 2) {
   ForbidShot(true); //Vbg֎~
   ForbidBomb(true); //{֎~
   SetPlayerX(GetCenterX); //vC[xWŒ
   SetPlayerY(GetClipMaxY); //vC[yWŒ
   if(GetKeyState(VK_DOWN) == KEY_PUSH) { //L[ꂽ{}s
    if(count == 1) { //J[\Pꍇ{}s
     count = 2;
    }
    else if(count == 2) { //Qꍇ{}s
     count = 3;
    }
    else if(count == 3) { //Rꍇ{}s
     count = 4;
    }
    else if(count == 4) {
     count = 5;
    }
    else if(count == 5) {
     count = 1;
    }
   }
   else if(GetKeyState(VK_UP) == KEY_PUSH) {
    if(count == 1) {
     count = 5;
    }
    else if(count == 2) {
     count = 1;
    }
    else if(count == 3) {
     count = 2;
    }
    else if(count == 4) {
     count = 3;
    }
    else if(count == 5) {
     count = 4;
    }
   }
   else if(GetKeyState(VK_SHOT) == KEY_PUSH) { //VbgL[ꂽ{}s
    if(count == 1 || count == 2 || count == 3 || count == 4) {
     title = 3; //^CgʏI
    }
    else if(count == 5) {
     ClearStage; //NA
    }
   }
  }
  else if(title == 3) { //^CgȂꍇ
   ForbidShot(false); //Vbg
   ForbidBomb(false); //{
  }

  yield;
 }

 @Finalize {
  DeleteGraphic(titleimg);
 }

 @DrawTopObject {
  if(title == 1) {
   SetTexture(titleimg); //^Cg摜Zbg
   SetGraphicRect(0, 0, 384, 448);
   DrawGraphic(GetCenterX, GetCenterY);
   DrawText("", 70, 80, 150, 255);
   DrawText("", 240, 120, 100, 255);
   DrawText("N", 60, 250, 120, 255);
   DrawText("W", 190, 290, 80, 255);
   DrawText("L", 280, 270, 100, 255);
   DrawText("GAME START", 150, 380, 30, 255);
   DrawText("Let's push shot key", 140, 420, 18, 255);
  }
  else if(title == 2) {
   SetTexture(titleimg);
   SetGraphicRect(0, 0, 384, 448);
   DrawGraphic(GetCenterX, GetCenterY);
   DrawText("", 50, 40 * count, 18, 255);
   DrawText("Easy", 100, 40, 18, 255);
   DrawText("Normal", 100, 80, 18, 255);
   DrawText("Hard", 100, 120, 18, 255);
   DrawText("Lunatic", 100, 160, 18, 255);
   DrawText("pȂĂȂ", 100, 200, 18, 255);
  }
 }

 task TStage {
  loop {
   if(title == 1 || title == 2) { //^CgʒȂ{}s
    yield;
   }
   else if(count == 1 && title == 3) {
    PlayMusic(bgm1);
    wait(30);
    hyousei1E(0);
    wait(180);
    hyousei1e(1);
    wait(180);
    hyousei1ee(4, 1);
    wait(300);
    hyousei2e(1);
    wait(500);
    CreateEnemyBossFromFile(GetCurrentScriptDirectory~"`mʏeP-Easy-.txt", 0, 0, 0, 0, 0);
    wait(500);
    CreateEnemyBossFromFile(GetCurrentScriptDirectory~"Pʃ{X-Easy-.txt", 0, 0, 0, 0, 0);
    waitZero();
    wait(240);
    ClearStage;
   }
   else if(count == 2 && title == 3) {
    PlayMusic(bgm1);
    wait(30);
    hyousei1N(0);
    wait(180);
    hyousei1n(1);
    wait(180);
    hyousei1nn(4, 1);
    wait(300);
    hyousei2n(1);
    wait(500);
    CreateEnemyBossFromFile(GetCurrentScriptDirectory~"`mʏeP-Normal-.txt", 0, 0, 0, 0, 0);
    waitZero();
    wait(240);
    CreateEnemyBossFromFile(GetCurrentScriptDirectory~"Pʃ{X-Normal-.txt", 0, 0, 0, 0, 0);
    waitZero();
    wait(240);
    ClearStage;
   }
   else if(count == 3 && title == 3) {
    PlayMusic(bgm1);
    wait(30);
    hyousei1H(0);
    wait(180);
    hyousei1h(1);
    wait(180);
    hyousei1hh(4, 1);
    wait(300);
    hyousei2h(1);
    wait(500);
    CreateEnemyBossFromFile(GetCurrentScriptDirectory~"Pʒ{X-Hard-.txt", 0, 0, 0, 0, 0);
    waitZero();
    wait(240);
    CreateEnemyBossFromFile(GetCurrentScriptDirectory~"Pʃ{X-Hard-.txt", 0, 0, 0, 0, 0);
    waitZero();
    wait(240);
    ClearStage;
   }
   else if(count == 4 && title == 3) {
    PlayMusic(bgm1);
    wait(30);
    hyousei1L(0);
    wait(180);
    hyousei1l(1);
    wait(180);
    hyousei1ll(4, 1);
    wait(300);
    hyousei2l(1);
    wait(500);
    CreateEnemyBossFromFile(GetCurrentScriptDirectory~"Pʒ{X-Lunatic-.txt", 0, 0, 0, 0, 0);
    waitZero();
    wait(240);
    CreateEnemyBossFromFile(GetCurrentScriptDirectory~"Pʃ{X-Lunatic-.txt", 0, 0, 0, 0, 0);
    waitZero();
    wait(240);
    ClearStage;
   }
  }
 }

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

 function waitZero() {
  while(GetEnemyNum() != 0) { yield; }
 }

 function Select(expr, truenum, falsenum) {
  if(expr) {
   return truenum;
  }
  else {
   return falsenum;
  }
 }

 function hyousei1E(way) {
  plus = 1;
  loop(4) {
   wait(180);
   loop(9) {
    wait(18);
    let x = 40;
    CreateEnemyFromFile(GetCurrentScriptDirectory~"XP-Easy-.txt", Select(plus < 0, GetClipMaxX, GetClipMinX) + (x * plus), 0, 2, 90, Select(plus < 0, 1 + way * 2, way * 2));
    x += 24;
   }
   plus = -plus;
  }
 }

 function hyousei1e(way) {
  loop(4) {
  let x = GetClipMinX + 10;
  let move = 1;
   wait(120);
   loop(10) {
    wait(30);
    CreateEnemyFromFile(GetCurrentScriptDirectory~"XP-Easy-.txt", x, 0, 2, 90, move * way);
    x += (GetClipMaxX - 10) / 10;
    move += 1;
    if(move == 11) {
     move = 1;
     x = GetClipMinX + 10;
    }
   }
  }
 }

 function hyousei1ee(way, way2) {
  let x = 0;
  loop(way) {
   wait(180);
   loop(10) {
    wait(35);
    loop(way2) {
     CreateEnemyFromFile(GetCurrentScriptDirectory~"XP-Easy-.txt", x, GetClipMinY, 2, 90, 0);
     x = rand(GetClipMinX, GetClipMaxX);
    }
   }
  }
 }

 function hyousei1N(way) {
  plus = 1;
  loop(4) {
   wait(180);
   loop(9) {
    wait(18);
    let x = 40;
    CreateEnemyFromFile(GetCurrentScriptDirectory~"XP-Normal-.txt", Select(plus < 0, GetClipMaxX, GetClipMinX) + (x * plus), 0, 2, 90, Select(plus < 0, 1 + way * 2, way * 2));
    x += 24;
   }
   plus = -plus;
  }
 }

 function hyousei1n(way) {
  loop(4) {
  let x = GetClipMinX + 10;
  let move = 1;
   wait(120);
   loop(10) {
    wait(30);
    CreateEnemyFromFile(GetCurrentScriptDirectory~"XP-Normal-.txt", x, 0, 2, 90, move * way);
    x += (GetClipMaxX - 10) / 10;
    move += 1;
    if(move == 11) {
     move = 1;
     x = GetClipMinX + 10;
    }
   }
  }
 }

 function hyousei1nn(way, way2) {
  let x = 0;
  loop(way) {
   wait(180);
   loop(10) {
    wait(35);
    loop(way2) {
     CreateEnemyFromFile(GetCurrentScriptDirectory~"XP-Normal-.txt", x, GetClipMinY, 2, 90, 0);
     x = rand(GetClipMinX, GetClipMaxX);
    }
   }
  }
 }

 function hyousei1H(way) {
  plus = 1;
  loop(4) {
   wait(180);
   loop(9) {
    wait(18);
    let x = 40;
    CreateEnemyFromFile(GetCurrentScriptDirectory~"XP-Hard-.txt", Select(plus < 0, GetClipMaxX, GetClipMinX) + (x * plus), 0, 2, 90, Select(plus < 0, 1 + way * 2, way * 2));
    x += 24;
   }
   plus = -plus;
  }
 }

 function hyousei1h(way) {
  loop(4) {
  let x = GetClipMinX + 10;
  let move = 1;
   wait(120);
   loop(10) {
    wait(30);
    CreateEnemyFromFile(GetCurrentScriptDirectory~"XP-Hard-.txt", x, 0, 2, 90, move * way);
    x += (GetClipMaxX - 10) / 10;
    move += 1;
    if(move == 11) {
     move = 1;
     x = GetClipMinX + 10;
    }
   }
  }
 }

 function hyousei1hh(way, way2) {
  let x = 0;
  loop(way) {
   wait(180);
   loop(10) {
    wait(35);
    loop(way2) {
     CreateEnemyFromFile(GetCurrentScriptDirectory~"XP-Hard-.txt", x, GetClipMinY, 2, 90, 0);
     x = rand(GetClipMinX, GetClipMaxX);
    }
   }
  }
 }

 function hyousei1L(way) {
  plus = 1;
  loop(4) {
   wait(180);
   loop(9) {
    wait(18);
    let x = 40;
    CreateEnemyFromFile(GetCurrentScriptDirectory~"XP-Lunatic-.txt", Select(plus < 0, GetClipMaxX, GetClipMinX) + (x * plus), 0, 2, 90, Select(plus < 0, 1 + way * 2, way * 2));
    x += 24;
   }
   plus = -plus;
  }
 }

 function hyousei1l(way) {
  loop(4) {
  let x = GetClipMinX + 10;
  let move = 1;
   wait(120);
   loop(10) {
    wait(30);
    CreateEnemyFromFile(GetCurrentScriptDirectory~"XP-Lunatic-.txt", x, 0, 2, 90, move * way);
    x += (GetClipMaxX - 10) / 10;
    move += 1;
    if(move == 11) {
     move = 1;
     x = GetClipMinX + 10;
    }
   }
  }
 }

 function hyousei1ll(way, way2) {
  let x = GetCenterX;
  loop(way) {
   wait(180);
   loop(10) {
    wait(35);
    loop(way2) {
     CreateEnemyFromFile(GetCurrentScriptDirectory~"XP-Lunatic-.txt", x, GetClipMinY, 2, 90, 0);
     x = rand(GetClipMinX, GetClipMaxX);
    }
   }
  }
 }

 function hyousei2e(way) {
  CreateEnemyFromFile(GetCurrentScriptDirectory~"XQ-Easy-.txt", GetCenterX, GetClipMinY, 1, 90, way);
 }

 function hyousei2n(way) {
  CreateEnemyFromFile(GetCurrentScriptDirectory~"XQ-Normal-.txt", GetCenterX, GetClipMinY, 1, 90, way);
 }

 function hyousei2h(way) {
  CreateEnemyFromFile(GetCurrentScriptDirectory~"XQ-Hard-.txt", GetCenterX, GetClipMinY, 1, 90, way);
 }

 function hyousei2l(way) {
  CreateEnemyFromFile(GetCurrentScriptDirectory~"XQ-Lunatic-.txt", GetCenterX, GetClipMinY, 1, 90, way);
 }
#include_function ".\ϐW.txt"
}