#東方弾幕風[Stage]
#Title[東方幻闘記　-Phantasm Duels-]
#Text[難易度　Normal or
　　　　Lunatic]
#Image[]
#BackGround[USER]
#Player[FREE]
#PlayLevel[]
#ScriptVersion[2]

script_event Mode{
  let dif = 0;
    @Initialize{}
    @MainLoop{
    /*   Select("\c[BLUE]Normal","\c[RED]Lunatic");
 if(Select("\c[BLUE]Normal","\c[RED]Lunatic") == 1){dif = 1;}
 else if(Select("\c[BLUE]Normal","\c[RED]Lunatic") == 2){dif = 2;} */
 SetCommonData("Dif",Select("\c[BLUE]Normal","\c[RED]Lunatic"));
     Wait(10);
       End;
      }
   @Finalize{}
    }

  script_event Try{
    @Initialize{}
    @MainLoop{
 SetCommonData("Play",Select("\c[YELLOW]Dream","\c[YELLOW]Power"));
     Wait(10);
       End;
      }
   @Finalize{}
    }

script_stage_main{
      let beginx = GetCenterX;
      let beginy = GetCenterY+150;
         let csd = GetCurrentScriptDirectory;
	let cx=GetCenterX();
        let cy=GetCenterY();
        let Enemy=csd~"img\dot-kaze-ti.png"; 
        let se1 = csd~"bgm\power33.wav" ; 
        let se2 = csd~"bgm\bom13.wav" ;
        let se3 = csd~"bgm\cursor02.wav" ;  
	@Initialize()
	{
  CreateEventFromScript("Mode");
                LoadMusic(se1); 
                LoadMusic(se2); 
                  LoadMusic(se3);  
		StageTask();
       ExpertEx(false,3,3); 
	}
	
	@MainLoop()
	{
  if(OnEvent){break;}
		yield;
	}
	
 /*      @DrawLoop{
    } */

	@Finalize()
	{
           DeleteSE(se1);DeleteSE(se2);DeleteSE(se3);
                DeleteGraphic(Enemy);  
          DeleteCommonData("Dif");    
	}

   	@BackGround()
	{
	 //@BackGroundが存在すると
	 //#BackGround[Default]より優先されて描画される
	}   


      task StageTask{	
               yield; 

  let dif = GetCommonData("Dif");
/* if(dif == 1){qqq = 0;}
 else if(dif == 2){qqq = 100;}  */
        Bonus;
        Border;
    Con;
      BulletDelete;
       task Bonus{
          let extend = 1000;
           SetNormPoint(extend);
          loop{
              if(GetPoint >= extend){
               ExtendPlayer(1); 
              PlaySE(se1);
               extend += 1000;
               SetNormPoint(extend);
                 wait(600);
               }
             else{wait(1);}
             }
         }     
       task Border{
    if(dif == 2){SEse;}
            let border = 300;
          let bordertime = 300;
            loop{
     let borderbonus = 0;
              if(GetGraze >= border){
               SuperNaturalBorder(bordertime); 
          
      if(dif == 2){Slow(1);}
            while(GetTimeOfSuperNaturalBorder!=0){
            CollectItems;
         borderbonus += 1;
                 wait(1);
                 }
         if(borderbonus >= bordertime-1){ AddBomb(1); PlaySE(se1);}
      if(dif == 2){Slow(0);}
    border += 300;
             bordertime += 60;
        if(bordertime >= 600 && dif == 1){bordertime = 600;} 
    if(bordertime >= 600 && dif == 2){bordertime -= 30;}
    if(bordertime >= 900 && dif == 2){bordertime -= 15;}
    if(bordertime >= 1200 && dif == 2){bordertime -= 10;}
     if(bordertime >= 1800 && dif == 2){bordertime -= 5;}
               }
             else{wait(1);}
             }
       task SEse{
           loop{
             if(GetTimeOfSuperNaturalBorder!=0){
               PlaySE(se3);
               wait(60);
               }
             wait(1);
               }
             }
         }   
   task BulletDelete{
       loop{
      if(GetTimeOfPlayerInvincibility!=0){
           DeleteEnemyShotImmediatelyInCircle(SHOT,GetPlayerX,GetPlayerY,10);
          }
        wait(1);
          }
      }

   task Con{
      let con = GetAllowedContinueCount;
    loop{
      while(GetAllowedContinueCount == con){
       wait(1);
       }
   wait(1);
    ExtendPlayer(6); AddBomb(6);
   con = GetAllowedContinueCount;
   wait(1);
     }
  }

      //Stage1
     let b = 7;
         ascent(i in 0..3){
                waitnext;	
		wait(60);
          loop(8){
             enemy(csd~"Enemy01.txt",GetClipMinX-20,GetClipMinY+90+i*30,1.5,0,0);
              wait(30);
               }
          wait(90);
          loop(8){
             enemy(csd~"Enemy01.txt",GetClipMaxX+20,GetClipMinY+90+i*30,1.5,180,0);
              wait(30);
               }
          wait(90);
        ascent(i in 0..b){
           enemy(csd~"Enemy02.txt",GetCenterX-30*(b-1)/2+30*i,GetClipMinY,2,90,11);
            }
        b += 2;
          }   
           wait(300);  
     let t = 1;
     loop(3){
       ascent(i in 0..7){
           enemy(csd~"Enemy03.txt",GetCenterX-180+60*i,GetClipMinY,1,90,t);
      wait(20);
            }
         waitnext;
         wait(120);
       t += 2;
         }      
        wait(120);  
          boss(csd~"MiddleBossRumia01.txt",GetCenterX,GetClipMinY+120,0.5,0,28);
          waitnext; 
        PlaySE(se2); 
    wait(120);
        Enemy1;
      wait(240);
    let ww = 10; let wa = 0; let n = 8;
    if(dif == 2){ww = 0; wa = 160; let n = 20;}
        ascent(i in 0..n){
           enemy(csd~"Enemy02.txt",GetCenterX+30*(i-(n-1)/2),GetClipMinY,2,90,11);
         wait(ww);
            }
     wait(wa);
       ascent(i in 0..n){
           enemy(csd~"Enemy02.txt",GetCenterX-30*(i-(n-1)/2),GetClipMinY,2,90,11);
         wait(ww);
            } 
        waitnext;        
       wait(240);  
     ascent(i in 0..10){
        enemy(csd~"Enemy04.txt",GetClipMinX+40,GetClipMinY-20,2,90,30+i*10);
        wait(10);
        }
       wait(120);
        ascent(i in 0..10){
        enemy(csd~"Enemy04.txt",GetClipMaxX-40,GetClipMinY-20,2,90,30+i*10);
        wait(10);
        }
      wait(240);
       ascent(i in 0..24){
        enemy(csd~"Enemy04.txt",GetClipMinX+40,GetClipMinY-20,2,90,30+i*4);
        enemy(csd~"Enemy04.txt",GetClipMaxX-40,GetClipMinY-20,2,90,30+i*4);
        wait(10);
        }
         waitnext;    
         wait(240);   
       boss(csd~"BossRumia.txt",GetCenterX,GetClipMinY+120,0,0,28);
         waitnext;
       PlaySE(se2);
      wait(180);
       SetPlayerX(beginx); SetPlayerY(beginy);   
       wait(180);  
  
   DeleteEnemyShotToItem(ALL);
      DeleteAllEnemyWithoutBoss; 

     //Stage2
    loop(10){
      enemy(csd~"Enemy21.txt",GetClipMinX-40,GetClipMinY,3,0,3);
       wait(20);
        }
         waitnext;
        wait(120);
      loop(10){
      enemy(csd~"Enemy21.txt",GetClipMaxX+40,GetClipMinY,3,180,-3);
       wait(20);
        }
       waitnext;
        wait(120);
     loop(10){
      enemy(csd~"Enemy21.txt",GetClipMinX-40,GetClipMinY,3,0,6);
      wait(10);
      enemy(csd~"Enemy21.txt",GetClipMaxX+40,GetClipMinY,3,180,-6);
       wait(10);
        }     
        waitnext;
        wait(120);  
      enemy(csd~"Enemy22.txt",GetCenterX,GetClipMinY-20,0.8,90,120);   
       waitnext;
        wait(300);    
    ascent(i in 0..6){
      enemy(csd~"Enemy23.txt",GetClipMaxX+40+i*10,GetClipMinY+120+i*10,5,180+i*5,36);
       wait(20);
        }
     wait(90);
     ascent(i in 0..6){
      enemy(csd~"Enemy23.txt",GetClipMinX-40-i*10,GetClipMinY+120+i*10,5,0-i*5,146);
      wait(20);
       }
      wait(120);
   loop(3){
     ascent(i in 0..10){
      enemy(csd~"Enemy23.txt",GetClipMaxX+40+i*10,GetClipMinY+120+i*10,5,180+i*5,36);
      wait(10);
      enemy(csd~"Enemy23.txt",GetClipMinX-40-i*10,GetClipMinY+120+i*10,5,0-i*5,146);
       wait(10);
        }
      }
      waitnext;
       wait(180);
      DeleteEnemyShot(ALL);    
       wait(180);    
  if(dif == 1){
    boss(csd~"MiddleBossKisume01.txt",GetCenterX,GetClipMinY+120,0,0,0);
       }
   else if(dif == 2){
     boss(csd~"MiddleBossKisume.txt",GetCenterX,GetClipMinY+120,0,0,0);
       }
       waitnext;   
   PlaySE(se2);
       wait(240);   
    loop(30){
     enemy(csd~"Enemy24.txt",rand(GetClipMinX,GetClipMaxX),GetClipMinY-60,3,0,0);
      wait(10);
        }
   ascent(i in 0..4){
     enemy(csd~"Enemy25.txt",GetCenterX,GetClipMinY-20,0.8,90,30-5*i); 
     loop(30){
     enemy(csd~"Enemy24.txt",rand(GetClipMinX,GetClipMaxX),GetClipMinY-60,3,0,0);
      wait(10);
        }  
      waitnext;
        }        
     wait(120);     
     ascent(i in 0..12){
      enemy(csd~"Enemy23.txt",GetClipMaxX+40+i*5,GetClipMinY+120+i*5,5,180+i*5/2,36);
       wait(10);
        }
      ascent(i in 0..12){
      enemy(csd~"Enemy23.txt",GetClipMinX-40-i*5,GetClipMinY+120+i*5,5,0-i*5/2,146);
      wait(10);
       }
      waitnext;
      wait(60);
     enemy(csd~"Enemy25.txt",GetCenterX+90,GetClipMinY-20,0.8,90,30);
     enemy(csd~"Enemy25.txt",GetCenterX-90,GetClipMinY-20,0.8,90,30);
      waitnext;       
      wait(180);   
     boss(csd~"BossPalucy.txt",GetClipMaxX+60,GetClipMinY+30,0,0,0);
     waitnext;      
    PlaySE(se2); 
       wait(180);
       SetPlayerX(beginx); SetPlayerY(beginy);   
       wait(180); 
   
 DeleteEnemyShotToItem(ALL);
      DeleteAllEnemyWithoutBoss; 
   
  //Stage3
    Enemy10(14,90);       
      wait(600);  
    enemy(csd~"Enemy31.txt",GetCenterX,GetClipMinY-90,0,0,5);
      wait(599);  
     DeleteAllEnemyWithoutBoss;
       wait(121);  
    loop(6){
     enemy(csd~"Enemy32.txt",rand(GetClipMinX+30,GetClipMaxX-30),GetClipMinY-30,0,0,75);
      wait(90);
    }
     wait(120);
     loop(10){
     enemy(csd~"Enemy32.txt",rand(GetClipMinX+30,GetClipMaxX-30),GetClipMinY-rand(30,30),0,0,40);
     enemy(csd~"Enemy32.txt",rand(GetClipMinX+30,GetClipMaxX-30),GetClipMinY-rand(30,30),0,0,40);
      wait(150);
    }     
      wait(480);      
     Enemy10(30,120);
      enemy(csd~"MiddleBossHina01.txt",GetCenterX-120,GetClipMinY-120,0,0,0);
      wait(1800);
     enemy(csd~"Enemy31.txt",GetCenterX,GetClipMinY-90,0,0,5);
      wait(1800);
      DeleteEnemyShotToItem(ALL);
      DeleteAllEnemyWithoutBoss;  
     boss(csd~"MiddleBossHinaSpell01.txt",GetCenterX-120,GetClipMinY-120,0,0,0);
     waitnext;     
    PlaySE(se2);  
      wait(300);    
     ascent(i in 0..6){
         enemy(csd~"Enemy01.txt",GetClipMinX-60,GetClipMinY+60+i*15,2,0,2);
        wait(30);
       }
     wait(120);   
     ascent(i in 0..6){
         enemy(csd~"Enemy01.txt",GetClipMaxX+60,GetClipMinY+60+i*15,2,180,2);
        wait(30);
       }
     wait(120);
     enemy(csd~"Enemy33.txt",GetCenterX+100,GetClipMinY-20,1.5,90,0);
     enemy(csd~"Enemy33.txt",GetCenterX-100,GetClipMinY-20,1.5,90,0);
    wait(120);
   ascent(i in 0..8){
         enemy(csd~"Enemy01.txt",GetClipMinX-60,GetClipMinY+60+i*15,2,0,2);
        wait(30);
       }
     wait(120);
     ascent(i in 0..8){
         enemy(csd~"Enemy01.txt",GetClipMaxX+60,GetClipMinY+60+i*15,2,180,2);
        wait(30);
       }
     wait(120);  
     enemy(csd~"Enemy33.txt",GetCenterX+160,GetClipMinY-40,3,90,0);
     enemy(csd~"Enemy33.txt",GetCenterX-160,GetClipMinY-40,3,90,0);
    wait(60);
     enemy(csd~"Enemy33.txt",GetCenterX+80,GetClipMinY-20,2,90,0);
     enemy(csd~"Enemy33.txt",GetCenterX-80,GetClipMinY-20,2,90,0);
    wait(60);
     enemy(csd~"Enemy33.txt",GetCenterX+20,GetClipMinY-10,1.5,90,0);
     enemy(csd~"Enemy33.txt",GetCenterX-20,GetClipMinY-10,1.5,90,0);
     wait(120);
   ascent(i in 0..16){
         enemy(csd~"Enemy01.txt",GetClipMinX-60,GetClipMinY+60+i*10,2,0,2);
        wait(15);
       }
     ascent(i in 0..16){
         enemy(csd~"Enemy01.txt",GetClipMaxX+60,GetClipMinY+60+i*15,2,180,2);
        wait(15);  
       }           
     wait(240);  
     enemy(csd~"Enemy33.txt",GetCenterX+60,GetClipMinY-10,1.5,90,1);
     enemy(csd~"Enemy33.txt",GetCenterX-60,GetClipMinY-10,1.5,90,1);
    waitnext;
    wait(90);
   ascent(a in 0..3){
     enemy(csd~"Enemy33.txt",GetCenterX+60+45*a,GetClipMinY-10,1.5,90,1);
     enemy(csd~"Enemy33.txt",GetCenterX-60-45*a,GetClipMinY-10,1.5,90,1);
     }
    waitnext;
    wait(180);    
    Enemy10(10,10);   
   ascent(a in 0..3){
    enemy(csd~"Enemy31.txt",GetCenterX-100*(a-1),GetClipMinY-90,0,0,5);
     }
    waitnext;   
  if(dif == 2){enemy(csd~"Enemy31.txt",GetCenterX,GetClipMinY-30,0,0,1);}
   waitnext;
   DeleteEnemyShotToItem(ALL);
    wait(300);      
    boss(csd~"BossHina.txt",GetCenterX-120,GetClipMinY-120,0,0,0); 
     waitnext;
   PlaySE(se2);
    wait(180);
       SetPlayerX(beginx); SetPlayerY(beginy);   
       wait(180); 
       
  DeleteEnemyShotToItem(ALL);
      DeleteAllEnemyWithoutBoss; 


  //Stage4
  CreateEventFromScript("Try");
  wait(1);
   loop(2){
     loop(8){
          enemy(csd~"Enemy41.txt",GetClipMaxX-30,GetClipMinY-60,1.5,90,0);
          enemy(csd~"Enemy41.txt",GetClipMaxX-70,GetClipMinY-60,1.5,90,0);
         wait(30);
        }
       if(dif == 1){wait(60);}
       loop(8){
          enemy(csd~"Enemy41.txt",GetClipMinX+30,GetClipMinY-60,1.5,90,1);
          enemy(csd~"Enemy41.txt",GetClipMinX+70,GetClipMinY-60,1.5,90,1);
         wait(30);
        }
      if(dif == 1){wait(60);}
      }             
     wait(180);    
   ascent(i in 0..6){
    enemy(csd~"Enemy42.txt",GetClipMaxX-30+(GetClipMinX-GetClipMaxX)/6*i,GetClipMinY-60,0,0,0);
       wait(10);
      }
     wait(120);
    ascent(i in 0..6){
    enemy(csd~"Enemy42.txt",GetClipMinX+30-(GetClipMinX-GetClipMaxX)/6*i,GetClipMinY-60,0,0,0);
       wait(10);
      }
   wait(240);
   ascent(i in 0..10){
    enemy(csd~"Enemy42.txt",GetClipMaxX-30+(GetClipMinX-GetClipMaxX)/10*i,GetClipMinY-60,0,0,0);
       wait(8);
      }
     wait(90);
    ascent(i in 0..10){
    enemy(csd~"Enemy42.txt",GetClipMinX+30-(GetClipMinX-GetClipMaxX)/10*i,GetClipMinY-60,0,0,0);
       wait(8);
      }
    wait(180);
  loop(2){
   ascent(i in 0..12){
    enemy(csd~"Enemy42.txt",GetClipMaxX-10+(GetClipMinX-GetClipMaxX)/12*i,GetClipMinY-60,0,0,0);
       wait(6);
      }
     wait(30);
    }
 loop(2){
    ascent(i in 0..12){
    enemy(csd~"Enemy42.txt",GetClipMinX+10-(GetClipMinX-GetClipMaxX)/12*i,GetClipMinY-60,0,0,0);
       wait(6);
      }    
   wait(30);
   }       
    wait(120);    
    enemy(csd~"Enemy43.txt",GetCenterX,GetClipMinY-60,0,0,0);
    waitnext;
    wait(180);
    enemy(csd~"Enemy43.txt",GetCenterX+60,GetClipMinY-60,0,0,0);
    waitnext;
    enemy(csd~"Enemy43.txt",GetCenterX-60,GetClipMinY-60,0,0,0);
    waitnext;
    wait(120);
    enemy(csd~"Enemy43.txt",GetCenterX+120,GetClipMinY-60,0,0,0);
    enemy(csd~"Enemy43.txt",GetCenterX-120,GetClipMinY-60,0,0,0);
    waitnext;   
    wait(240);
   boss(csd~"MiddleBossFlan.txt",GetCenterX,GetClipMinY+120,0,0,0);
   waitnext;  
  PlaySE(se2); 
   wait(300);    
  loop(8){
          enemy(csd~"Enemy41.txt",GetClipMaxX-30,GetClipMinY-60,1.5,90,2);
          enemy(csd~"Enemy41.txt",GetClipMaxX-70,GetClipMinY-60,1.5,90,2);
         wait(15);
        }
       wait(30);
       loop(8){
          enemy(csd~"Enemy41.txt",GetClipMinX+30,GetClipMinY-60,1.5,90,3);
          enemy(csd~"Enemy41.txt",GetClipMinX+70,GetClipMinY-60,1.5,90,3);
         wait(15);
        }
    wait(180);
   enemy(csd~"Enemy44.txt",rand(GetClipMinX+20,GetClipMaxX-20),rand(GetClipMinY,GetCenterY),0,0,36);
   waitnext;
     ascent(a in 0..12){
         enemy(csd~"Enemy44.txt",rand(GetClipMinX+20,GetClipMaxX-20),rand(GetClipMinY,GetCenterY),0,0,36+3*a);
        wait(60-5*a);
      }
    waitnext;
    wait(180);    
    ascent(a in 0..6){
     enemy(csd~"Enemy45.txt",GetCenterX,GetCenterY-120,0,60*a,0);
     }
    if(dif == 2){
    wait(15);
   ascent(a in 0..6){
     enemy(csd~"Enemy45.txt",GetCenterX,GetCenterY-120,0,60*a+30,1);
     }
     wait(15);
   ascent(a in 0..6){
     enemy(csd~"Enemy45.txt",GetCenterX,GetCenterY-120,0,60*a-30,2);
     }
   wait(15);
   ascent(a in 0..6){
     enemy(csd~"Enemy45.txt",GetCenterX,GetCenterY-120,0,60*a-30,3);
     }
       }
    
    waitnext;
    wait(180); 
   ascent(a in 0..4){
     enemy(csd~"Enemy46.txt",GetCenterX,GetCenterY,0,90*a,216);
     }
  if(dif == 2){
      ascent(a in 0..4){
     enemy(csd~"Enemy46.txt",GetCenterX,GetCenterY,0,90*a+45,108);
     }
    }
   waitnext;   
    wait(180);  
   enemy(csd~"Enemy47.txt",GetClipMinX-10,GetClipMinY,0,0,60);
    wait(3600);  
   DeleteEnemyShot(ALL);  
    boss(csd~"MiddleBossLargeFairy.txt",GetClipMinX,GetClipMinY-120,0,0,0);
    waitnext;
  PlaySE(se2);
    wait(120);    
    loop(4){
    enemy(csd~"Enemy42.txt",rand(GetClipMaxX-30,GetCenterX+60),GetClipMinY-60,0,0,0);
       wait(30);
      }
    enemy(csd~"Enemy43.txt",GetCenterX-120,GetClipMinY-60,0,0,0);
    loop(8){
    enemy(csd~"Enemy42.txt",rand(GetClipMaxX-30,GetCenterX+60),GetClipMinY-60,0,0,0);
       wait(30);
      }
     waitnext;
     wait(60);
     loop(4){
    enemy(csd~"Enemy42.txt",rand(GetClipMinX+30,GetCenterX-60),GetClipMinY-60,0,0,0);
       wait(30);
      }
    enemy(csd~"Enemy43.txt",GetCenterX+120,GetClipMinY-60,0,0,0);
    loop(8){
    enemy(csd~"Enemy42.txt",rand(GetClipMinX+30,GetCenterX-60),GetClipMinY-60,0,0,0);
       wait(30);
      }
     waitnext;
     wait(60);
    enemy(csd~"Enemy43.txt",GetCenterX+60,GetClipMinY-60,0,0,0);
    enemy(csd~"Enemy43.txt",GetCenterX-60,GetClipMinY-60,0,0,0);
    ascent(a in 0..20){
       enemy(csd~"Enemy44.txt",rand(GetClipMinX+20,GetClipMaxX-20),rand(GetClipMinY,GetCenterY),0,0,45);
        wait(30);
      }
     waitnext;   
     wait(180); 
     loop(8){
          enemy(csd~"Enemy41.txt",GetClipMaxX-30,GetClipMinY-60,1.5,90,2);
          enemy(csd~"Enemy41.txt",GetClipMaxX-70,GetClipMinY-60,1.5,90,2);
        enemy(csd~"Enemy42.txt",rand(GetClipMinX+30,GetCenterX-60),GetClipMinY-60,0,0,0);
         wait(15);
        }
     loop(8){
          enemy(csd~"Enemy41.txt",GetClipMinX+30,GetClipMinY-60,1.5,90,3);
          enemy(csd~"Enemy41.txt",GetClipMinX+70,GetClipMinY-60,1.5,90,3);
        enemy(csd~"Enemy42.txt",rand(GetClipMaxX-30,GetCenterX+60),GetClipMinY-60,0,0,0);
         wait(15);
        }
      waitnext;
      wait(240);    
       boss(csd~"BossFlan.txt",GetCenterX-400,GetClipMinY+120,0,0,0);
       waitnext;
   PlaySE(se2);   
      wait(180);   
       SetPlayerX(beginx); SetPlayerY(beginy);   
       wait(180);   

 DeleteEnemyShotToItem(ALL);
      DeleteAllEnemyWithoutBoss; 

//Stage5
     let root = 0;
   let tttt = GetCommonData("Play");
  if(tttt == 1){root = 0;}
  else if(tttt == 2){root = 3;}
  if(dif == 1){loop(4){
    enemy(csd~"Enemy51.txt",GetClipMinX-20,GetClipMinY+rand(80,150),2.5,-10,0);
      wait(90);
      }
     waitnext;
      wait(60);
      loop(4){
    enemy(csd~"Enemy51.txt",GetClipMaxX+20,GetClipMinY+rand(80,150),2.5,-170,0);
      wait(90);
      }
     }
   else if(dif == 2){
      loop(10){
    enemy(csd~"Enemy51.txt",GetClipMinX-20,GetClipMinY+rand(80,150),2.5,-10,0);
      wait(30);
      }
     waitnext;
      loop(10){
    enemy(csd~"Enemy51.txt",GetClipMaxX+20,GetClipMinY+rand(80,150),2.5,-170,0);
      wait(30);
      }
     }
      waitnext;
      wait(120);  
   loop(16){
    enemy(csd~"Enemy52.txt",GetClipMaxX-40,GetClipMaxY+20,0.5,-90,0);
      wait(30);
      }
    wait(60);
    loop(16){
    enemy(csd~"Enemy52.txt",GetClipMinX+40,GetClipMaxY+30,0.75,-90,0);
      wait(30);
      }
  wait(60);  
  if(dif == 2){loop(16){
    enemy(csd~"Enemy52.txt",GetClipMaxX-40,GetClipMaxY+30,0.75,-90,0);
    enemy(csd~"Enemy52.txt",GetClipMinX+40,GetClipMinY-30,0.75,90,0);
    enemy(csd~"Enemy52.txt",GetClipMaxX+40,GetClipMinY+30,0.75,180,0);
    enemy(csd~"Enemy52.txt",GetClipMinX-40,GetClipMaxY-30,0.75,0,0);
      wait(30);
      }
    }
    waitnext;  
     wait(60);   
  enemy(csd~"Enemy59.txt",GetClipMinX+100,GetClipMinY-30,2.5,0,0);
    loop(6){
    enemy(csd~"Enemy52.txt",GetClipMaxX-40,GetClipMaxY+20,0.75,-90,0);
      wait(60);
      }
   wait(180);
  enemy(csd~"Enemy59.txt",GetClipMaxX-100,GetClipMinY-30,2.5,0,0);
    loop(6){
    enemy(csd~"Enemy52.txt",GetClipMinX+40,GetClipMaxY+30,0.75,-90,0);
      wait(60);
      }
      waitnext;   
      wait(150);   
 if(dif == 1){
    loop(4){
    enemy(csd~"Enemy58.txt",GetClipMaxX+20,GetClipMinY+90,2.5,-170,1);
    enemy(csd~"Enemy58.txt",GetClipMinX-20,GetClipMinY+90,2.5,-10,2);
      wait(90);
    enemy(csd~"Enemy58.txt",GetClipMaxX+20,GetClipMinY+90,2.5,-170,2);
    enemy(csd~"Enemy58.txt",GetClipMinX-20,GetClipMinY+90,2.5,-10,1);
      wait(90);
      }
    }
  else if(dif == 2){
   loop(12){
    enemy(csd~"Enemy58.txt",GetClipMaxX+20,GetClipMinY+90,2.5,-170,1);
    enemy(csd~"Enemy58.txt",GetClipMinX-20,GetClipMinY+90,2.5,-10,2);
      wait(30);
    enemy(csd~"Enemy58.txt",GetClipMaxX+20,GetClipMinY+90,2.5,-170,2);
    enemy(csd~"Enemy58.txt",GetClipMinX-20,GetClipMinY+90,2.5,-10,1);
      wait(30);
      }
    }
    waitnext;
    wait(60); 
  enemy(csd~"Enemy59.txt",GetClipMaxX-120,GetClipMinY-60,2.5,0,0);
  enemy(csd~"Enemy59.txt",GetClipMaxX-60,GetClipMinY-10,2.5,0,0);
  enemy(csd~"Enemy59.txt",GetClipMinX+60,GetClipMinY-10,2.5,0,0);
  enemy(csd~"Enemy59.txt",GetClipMinX+120,GetClipMinY-60,2.5,0,0);
     waitnext;  
   wait(120);    
    boss(csd~"MiddleBossSakuya.txt",GetCenterX-400,GetClipMaxY-60,0,0,0); 
     waitnext;  
   PlaySE(se2);    
     wait(180);     
     loop(10){
          enemy(csd~"Enemy03.txt",rand(GetClipMinX+40,GetClipMaxX-40),GetClipMinY+10,rand(0.5,3),90,2);
        wait(6);
           }
     loop(3){
     enemy(csd~"Enemy54.txt",rand(GetClipMinX+40,GetClipMaxX-40),GetClipMinY+rand(10,90),0,0,0);
        wait(45);
         }
       wait(1200);
        loop(3){
     enemy(csd~"Enemy54.txt",rand(GetClipMinX+40,GetClipMaxX-40),GetClipMinY+rand(10,90),0,0,0);
        wait(45);
         }
       wait(600);     
      DeleteEnemyShotToItem(ALL);
      DeleteAllEnemyWithoutBoss;  
     enemy(csd~"Enemy55.txt",GetCenterX,GetClipMinY+120,0,0,0);
     wait(180);
     enemy(csd~"Enemy55.txt",GetCenterX-100,GetClipMinY+150,0,0,0);
     enemy(csd~"Enemy55.txt",GetCenterX+100,GetClipMinY+150,0,0,0);
     wait(60);
   if(dif == 2){
   enemy(csd~"Enemy55.txt",GetCenterX-50,GetClipMinY+250,0,0,0);
     enemy(csd~"Enemy55.txt",GetCenterX+50,GetClipMinY+250,0,0,0);
       }   
  let num = 2;
  if(dif == 2){num = 5;}
     loop(40){
           if(GetEnemyNum < num){
            enemy(csd~"Enemy55.txt",rand(GetClipMinX+60,GetClipMaxX-60),GetClipMinY+150,0,0,0);
              }
          else{}
            wait(30);
            }
      DeleteEnemyShotToItem(ALL); 
      DeleteAllEnemyWithoutBoss; 
          wait(180);         
        boss(csd~"MiddleBossSanae.txt",GetCenterX+400,GetClipMaxY-60,0,0,0); 
        waitnext;     
     PlaySE(se2);
        wait(180);       
         loop(10){
        enemy(csd~"Enemy56.txt",GetClipMinX-rand(20,40),GetClipMinY+rand(60,120),1.5,0,0);
         enemy(csd~"Enemy56.txt",GetClipMaxX+rand(20,40),GetClipMinY+rand(60,120),1.5,180,0); 
         wait(60);
         }
        waitnext;
        wait(240);    
        enemy(csd~"Enemy57.txt",GetCenterX,GetClipMinY-60,0,0,0);
        waitnext;
        wait(60);
     enemy(csd~"Enemy57.txt",GetCenterX-100,GetClipMinY-90,0,0,0);
     enemy(csd~"Enemy57.txt",GetCenterX+100,GetClipMinY-90,0,0,0);
        waitnext;
        wait(60);
       enemy(csd~"Enemy57.txt",GetCenterX,GetClipMinY-60,0,0,0);
       enemy(csd~"Enemy57.txt",GetCenterX-300,GetClipMinY+120,0,0,1);
       enemy(csd~"Enemy57.txt",GetCenterX+300,GetClipMinY+120,0,0,2);
       waitnext;
      wait(240);      
     if(root == 0){
       boss(csd~"BossAlice.txt",GetCenterX,GetClipMinY-30,0,0,0); 
       }
      else if(root == 3){
       boss(csd~"BossYukari.txt",GetCenterX,GetClipMinY-30,0,0,0); 
       }
      waitnext;   
   PlaySE(se2);
   wait(180);
       SetPlayerX(beginx); SetPlayerY(beginy);   
       wait(180); 
         
   DeleteEnemyShotToItem(ALL);
      DeleteAllEnemyWithoutBoss;   

//Stage6
   enemy(csd~"Enemy61.txt",GetCenterX-300,GetClipMinY+60,0.5,rand(30,150),2);
     enemy(csd~"Enemy61.txt",GetCenterX+300,GetClipMinY+60,0.5,rand(30,150),3);
     wait(180);
     enemy(csd~"Enemy61.txt",GetCenterX-300,GetClipMinY+120,0.5,rand(30,150),0);
     enemy(csd~"Enemy61.txt",GetCenterX+300,GetClipMinY+120,0.5,rand(30,150),1);
     wait(180);
     enemy(csd~"Enemy61.txt",GetCenterX-300,GetClipMinY+60,0.5,rand(30,150),4);
     enemy(csd~"Enemy61.txt",GetCenterX+300,GetClipMinY+60,0.5,rand(30,150),5);
     wait(10);
     enemy(csd~"Enemy61.txt",GetCenterX-300,GetClipMinY+60,0.5,rand(30,150),6);
     enemy(csd~"Enemy61.txt",GetCenterX+300,GetClipMinY+60,0.5,rand(30,150),7);
     wait(10);
     enemy(csd~"Enemy61.txt",GetCenterX-300,GetClipMinY+60,0.5,rand(30,150),8);
     enemy(csd~"Enemy61.txt",GetCenterX+300,GetClipMinY+60,0.5,rand(30,150),9);
     wait(10);
     enemy(csd~"Enemy61.txt",GetCenterX-300,GetClipMinY+60,0.5,rand(30,150),0);
     enemy(csd~"Enemy61.txt",GetCenterX+300,GetClipMinY+60,0.5,rand(30,150),1);
     wait(10);
     enemy(csd~"Enemy61.txt",GetCenterX-300,GetClipMinY+60,0.5,rand(30,150),10);
     enemy(csd~"Enemy61.txt",GetCenterX+300,GetClipMinY+60,0.5,rand(30,150),11);
     wait(10);
     enemy(csd~"Enemy61.txt",GetCenterX-300,GetClipMinY+60,0.5,rand(30,150),12);
     enemy(csd~"Enemy61.txt",GetCenterX+300,GetClipMinY+60,0.5,rand(30,150),13);
     wait(180);
    loop(6){
      loop(4){
        let a = rand_int(0,6)*2;
        let b = rand_int(0,6)*2+1;
     enemy(csd~"Enemy61.txt",GetCenterX-300,GetClipMinY+60,0.5,rand(30,150),a);
     wait(5);
     enemy(csd~"Enemy61.txt",GetCenterX+300,GetClipMinY+60,0.5,rand(30,150),b);
      wait(5);
      }
     wait(30);
       }
      wait(240); 
     
 ascent(a in 0..3){
  loop(3){
    enemy(csd~"Enemy63.txt",rand(GetClipMinX+32,GetClipMinX+192)+32*a,GetClipMinY-60,0.5+a/2,90,0);
    wait(120-a*30);
    enemy(csd~"Enemy63.txt",rand(GetCenterX-96,GetCenterX+96),GetClipMinY-60,0.5+a/2,90,0);
    wait(120-a*30);
    enemy(csd~"Enemy63.txt",rand(GetClipMaxX-192,GetClipMaxX-32)-32*a,GetClipMinY-60,0.5+a/2,90,0);
    wait(120-a*30);
     }
    wait(30);
   }   
      wait(120);  
   ascent(a in 0..3){
   enemy(csd~"Enemy63.txt",GetClipMinX+64,GetClipMinY-60,0.5+a/3,90,0);
   enemy(csd~"Enemy63.txt",GetCenterX,GetClipMinY-60,0.5+a/3,90,0);
   enemy(csd~"Enemy63.txt",GetClipMaxX-64,GetClipMinY-60,0.5+a/3,90,0);
    waitnext;
    wait(60);
    }
   waitnext;   
    wait(180);   
    enemy(csd~"Enemy64.txt",GetCenterX,GetClipMinY-60,0,0,0);
   waitnext;   
    wait(360);     
    DeleteEnemyShotToItem(ALL);
  if(root == 0){
       boss(csd~"BossReimu.txt",GetCenterX,GetClipMinY-30,0,0,0); 
       }
      else if(root == 3){
       boss(csd~"BossMarisa.txt",GetCenterX,GetClipMinY-30,0,0,0); 
       }
     waitnext;   
  PlaySE(se2);    
    if(Continued){SetClearFrameEffectEnable(false);}
    wait(240);
	  	Clear();   
	}
      

       task Enemy1{
             loop(8){
         enemy(csd~"Enemy01.txt",GetClipMinX-20,GetClipMinY+90,1.5,0,1);
        wait(30);
         enemy(csd~"Enemy01.txt",GetClipMaxX+20,GetClipMinY+90,1.5,180,1);
        wait(30);
          }
      }

       task Enemy10(con,next){
             loop(con){
           let arg = rand_int(0,2);
                enemy(csd~"Enemy10.txt",rand(GetClipMinX,GetClipMaxX),rand(GetClipMinY,GetClipMinY+100),0.1,0,arg);
            wait(next);
              }
       }

        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;}
		}	
}