 
//[life,color,bombresist,invincible,hit,shotpattern,movepattern,score,item,power,bomb,1up]

 function TitleMenu{
  if(!GetCommonDataDefaultEx("","howmany",false)){
    BombDefaultNum = GetPlayerBomb;
    SetCommonDataEx("","howmany",true);
        }  
 SetCommonDataEx("","stagelist",0);
  SetCommonDataEx("","psf",PracticeStageFrag);
  DeleteCommonData("spellnow");
   PlaySE(pi4);
   PlayMusic(bgm0_1);
     ForbidShot(true);
     ForbidBomb(true);
   ExtendPlayer(3-GetPlayerLife);
   AddScore(-GetScore);
   AddPoint(-GetPoint);
   AddGraze(-GetGraze);
    /*   let BombDefaultNum = GetPlayerBomb; */
   AddBomb(BombDefaultNum-GetPlayerBomb);

 backframe = 0;
 stagenum = 0;
 stagephase = 1;

  ascent(a in 0..10){
 enemy(csd~"zako\Enemy0.txt",cx+120,cy+40*(a-5)+20,0,75,[10000,-1,0,60*60*24*365,8,11,a,0,0,0,0,0]);
  }

  while(GetEnemyNum > 0){SetPlayerX(PlayerDefaultX); SetPlayerY(PlayerDefaultY); wait(1);}
  DeleteMusic(bgm0_1);
         }

 function Stage1{
   if(GetCommonDataDefaultEx("","mode",0) == 1){
  SetCommonDataEx("","stagelist",0);
  ContinueCount(3);
        }
    else if(GetCommonDataDefaultEx("","mode",0) == 3){
  SetCommonDataEx("","stagelist",1);
  ContinueCount(0);
        }
  ScoreRecording;
     ForbidShot(false);
     ForbidBomb(false);
 let difficult = GetCommonDataDefaultEx("","dif",0);
 let playercharacter = GetCommonDataDefaultEx("","chr",0);
 let playmode = GetCommonDataDefaultEx("","mode",0);
 if(playmode == 3){ExtendPlayer(8-GetPlayerLife);}
 backframe = 0;
 stagenum= 1;
 stagephase = 1;

  wait(120);

  PlayMusic(bgm1_1);
    ascent(a in 0..8){
 enemy(csd~"zako\Enemy1.txt",maxx-75-45*a,miny-30,5.7-0.5*a,75,[10,truncate(a/7),100,0,8,11,1,100,1,0,0,0]);
 stagewait(25);
      }
  stagewait(180);  
 ascent(a in 0..60){
   let d = 7*a*(840-a*7)/420/1.5; 
  StageTitle1(minx-20+d,maxy-45,7*a/1.5*(420-7*a/1.5),7*a,7*a,7*a);
    stagewait(7); 
     } 
  stagewait(60);      
 enemy(csd~"zako\Enemy4.txt",cx,miny-30,8,90,[200,0,100,30,12,11,1,300,6,0,0,0]);
  stagewait(180);
   ascent(a in 0..6){
 enemy(csd~"zako\Enemy1.txt",minx+60+15*a,miny-30-5*a,2,90,[10,truncate(a/5),100,0,8,12,3,100,1,0,0,0]);
 enemy(csd~"zako\Enemy1.txt",minx+40+15*a,miny-30-5*a,2,90,[10,truncate(a/5),100,0,8,12,3,100,1,0,0,0]);
  stagewait(25);
      }
  stagewait(125);
 enemy(csd~"zako\Enemy4.txt",minx+120,miny-10,8,90,[200,0,100,30,12,11,1,300,6,0,0,0]);
  stagewait(180);
  ascent(a in 0..6){
 enemy(csd~"zako\Enemy1.txt",maxx-80-15*a,miny-30-5*a,2,90,[10,truncate(a/5),100,0,8,12,2,100,1,0,0,0]);
 enemy(csd~"zako\Enemy1.txt",maxx-60-15*a,miny-30-5*a,2,90,[10,truncate(a/5),100,0,8,12,2,100,1,0,0,0]);
  stagewait(20);
      }
    stagewait(100);
 enemy(csd~"zako\Enemy4.txt",maxx-120,miny-10,8,90,[200,0,100,30,12,11,1,300,6,0,0,0]);
  stagewait(150);
  ascent(a in 0..8){
 enemy(csd~"zako\Enemy1.txt",cx+120-10*a,miny-30+3*a,1.5,90,[10,truncate(a/7),100,0,8,12,2,100,1,0,0,0]);
 enemy(csd~"zako\Enemy1.txt",cx-120+10*a,miny-30+3*a,1.5,90,[10,truncate(a/7),100,0,8,12,3,100,1,0,0,0]);
  stagewait(20);
      }
  stagewait(180);
   ascent(a in 0..18){
 enemy(csd~"zako\Enemy1.txt",minx+40+20*a,miny-30,7-0.3*a,105,[10,truncate(a/15),100,0,8,11,1,100,1,0,0,0]);
  stagewait(10);
      }
  stagewait(120);
  ascent(a in 0..10){
 enemy(csd~"zako\Enemy1.txt",minx-10-5*a,miny+16*(a+1),2.5,0,[10,0,100,0,8,12,3,100,1,0,0,0]);
  stagewait(10);
 enemy(csd~"zako\Enemy1.txt",maxx+10+5*a,miny+16*(a+1),2.5,180,[10,0,100,0,8,12,2,100,1,0,0,0]);
  stagewait(10);
      }
 stagewait(240); 
  DeleteEnemyShotToItem(ALL);
  DeleteAllEnemyWithoutBoss;     
   stagewait(1);
 if(difficult <= 1){boss(csd~"itirin\Plural01.txt",cx+120,miny-60,0,0,0);}
 else if(difficult >= 2){boss(csd~"itirin\Plural02.txt",cx+120,miny-60,0,0,0);}
   let quicktime = 60*36;
   while(quicktime > 0){
   if(!IsBossExisting){
    alternative(quicktime%360)
    case(0){enemy(csd~"zako\Enemy3.txt",maxx+30,miny+rand(60,180),1,180,[100,0,100,0,8,11,1,100,4,0,0,0]);}
    case(180){enemy(csd~"zako\Enemy3.txt",minx-30,miny+rand(60,180),1,0,[100,0,100,0,8,11,1,100,4,0,0,0]);}
    others{}
           }
       quicktime--; 
         stagewait(1);
        }      
  while(IsBossExisting){stagewait(1);}  
  stagewait(120);             
 stagephase = 2;
 backframe = 0;
 enemy(csd~"zako\Enemy4.txt",maxx-120,miny-10,8,90,[200,1,100,30,12,12,1,300,6,0,0,0]);
 enemy(csd~"zako\Enemy4.txt",minx+120,miny-10,8,90,[200,1,100,30,12,12,1,300,6,0,0,0]);
  stagewait(300);
 loop(15){
  enemy(csd~"zako\Enemy1.txt",rand(minx+30,maxx-30),miny-10,1,90,[10,rand_int(0,2),100,0,8,13,0,100,1,0,0,0]);
   stagewait(20);
      }
  stagewait(200);
 enemy(csd~"zako\Enemy4.txt",cx,miny-30,8,90,[200,0,100,30,12,11,1,300,6,0,0,0]);
  stagewait(60);
 enemy(csd~"zako\Enemy4.txt",maxx+10,miny+120,8,180,[200,1,100,30,12,12,1,300,6,0,0,0]);
 enemy(csd~"zako\Enemy4.txt",minx-10,miny+120,8,0,[200,1,100,30,12,12,1,300,6,0,0,0]);
 stagewait(300);
   ascent(a in 0..8){
 enemy(csd~"zako\Enemy1.txt",maxx-75-45*a,miny-10,5,75,[10,0,100,0,8,11,1,100,1,0,0,0]);
      }
  stagewait(30);
  ascent(a in 0..8){
 enemy(csd~"zako\Enemy1.txt",minx+75+45*a,miny-40,5,105,[10,1,100,0,8,11,1,100,1,0,0,0]);
      }
  stagewait(30);
    ascent(a in 0..8){
 enemy(csd~"zako\Enemy1.txt",maxx-75-45*a,miny-70,5,75,[10,2,100,0,8,11,1,100,1,0,0,0]);
      }
   stagewait(20);
    ascent(a in 0..8){
 enemy(csd~"zako\Enemy1.txt",maxx-75-45*a,miny-100,5,75,[10,1,100,0,8,11,1,100,1,0,0,0]);
      }
   stagewait(10);
    ascent(a in 0..8){
 enemy(csd~"zako\Enemy1.txt",maxx-75-45*a,miny-130,5,75,[10,0,100,0,8,11,1,100,1,0,0,0]);
      }
  stagewait(60*10);
  FadeOutMusic(bgm1_1,-20);
  stagewait(60*2);
  DeleteEnemyShotToItem(ALL);
  DeleteAllEnemyWithoutBoss;
  DeleteMusic(bgm1_1);
  stagewait(1);
  boss(csd~"murasa\Plural.txt",cx+120,miny-60,0,0,0);
   PlayMusic(bgm1_2);
  waitnext;
  stagewait(210);
  PracticeStageFrag[100*playercharacter + 10*stagenum + difficult] = true;
  SetCommonDataEx("","psf",PracticeStageFrag);
  stagephase = 0;
  backframe = 0;
   FadeOutMusic(bgm1_2,60);
   stagewait(90);
   DeleteMusic(bgm1_2);   
    }



function Stage2{
 
    }	

function Stage3{
  
    }	

function Stage4{
   
    }	

function Stage5{
  
    }	

function Stage6{
   
    }	

function StageEx{
   
    }	

function StagePh{
  
    }	

 function StageMy{
  
    }	

 function SpellPractice(k,l,m,n){ 
 backframe = l;
 stagenum = m;
 stagephase = n;
 AddBomb(0-GetPlayerBomb);
 ExtendPlayer(0-GetPlayerLife);

  alternative(k)
   case(1){PlayMusic(bgmSP_1);}

   waitnext;
   FadeOutMusic(bgmSP_1,20);
   wait(120);
  stagenum = -1;
  DeleteMusic(bgmSP_1);
    }	

 task ScoreRecording{
    while(GetCommonDataDefaultEx("","mode",0) < 4 && GetCommonDataDefaultEx("","mode",0) > 0){
    if(GetScore > HighestScore[100*GetCommonDataDefaultEx("","chr",0) + 10*GetCommonDataDefaultEx("","stagelist",0) + GetCommonDataDefaultEx("","dif",0)]){
     HighestScore[100*GetCommonDataDefaultEx("","chr",0) + 10*GetCommonDataDefaultEx("","stagelist",0) + GetCommonDataDefaultEx("","dif",0)] = GetScore;
     SetCommonDataEx("","hs",HighestScore);
               }
      else{}
      wait(1);
            }
         }