function Stage3{
   if(phase==0){
      PlayMusic( bgmst3 );
      phase=1;
      time=0;
   }
   if(phase==1){

      if(time==100){Tzakoheli1( 0, 1, 10, 20, 4);}
      if(time==100){Tzakoheli1( 0, 0, 10, 20, 4);}
      if(time==100){Tzakoheli1( 0, -1, 10, 20, 4);}

      if(time==0){Tzakotank1( 224+240, 30, 180, 9, 4);}
      if(time==30){Tzakotank1( 224+240, 70, 180, 9, 4);}
      if(time==0){Tzakotank1( 224+240, 110, 180, 9, 4);}
      if(time==0){Tzakogun301;}

      if(time==400){Tzakoheli1( 1, 1, 7, 6, 4);}
      if(time==470){Tzakoheli1( 1, -1, 7, 6, 4);}
      if(time==600){Tzakoheli1( 1, -1, 7, 6, 4);}
      if(time==670){Tzakoheli1( 1, 1, 7, 6, 4);}

      if(time==380){Tzakocannon1a( 224-80, 380, -1, 9, 4);}

      if(time==970-10){CreateEnemyFromFile( sky3, 224-20, 0, 0, 80, 0);}
      if(time==1070){CreateEnemyFromFile( sky3, 224+224, 30, 0, 140, 0);}
      if(time==1170+10){CreateEnemyFromFile( sky3, 224-150, 0, 0, 60, 0);}
      if(time==1270-10){CreateEnemyFromFile( sky3, 224+224, 0, 0, 135, 0);}
      if(time==1370){CreateEnemyFromFile( sky3, 224-224, 140, 0, 20, 0);}

      if(time==1300){Tzakogun302;}
      if(time==1570){Tzakoheli3( 224+270, 140, 180, 6, 15, 4);}
      if(time==1720){Tzakoheli3( 224-240, 0, 40, 6, 15, 4);}

      if(time==1850){CreateEnemyFromFile( sky1, 224+240, 230, 4, 200, 2);}
      if(time==1900){CreateEnemyFromFile( tank4, 224-100, 1170, 4, 90, 120);}
      if(time==2100){CreateEnemyFromFile( sky1, 224+240, 230, 4, 200, 2);}

      if(time==2000){Tzakocannon1a( 224+20, 1260, 1, 5, 2);}
      if(time==2300){Tzakoheli3( 224+240, 0, 140, 6, 15, 4);}
      if(time==2400){CreateEnemyFromFile( sky1, 224-240, 230, 4, -20, 2);}
      if(time==2550){Tzakoheli3( 224-270, 140, 0, 6, 15, 4);}

      if(time==2560){CreateEnemyFromFile( tank4, 224-120, 1566, 4, 90, 120);}
      if(time==2640){CreateEnemyFromFile( tank4, 224+120, 1614, 4, 90, 120);}
      if(time==2720){CreateEnemyFromFile( tank4, 224, 1662, 4, 90, 120);}

      if(time==3050){Tzakoheli3( 224-100, -30, 50, 8, 10, 4);}
      if(time==3100){Tzakoheli3( 224-200, -30, 50, 8, 10, 4);}
      if(time==3150){Tzakoheli3( 224+100, -30, 130, 8, 10, 4);}
      if(time==3200){Tzakoheli3( 224+200, -30, 130, 8, 10, 4);}

      if(time==2950){Tzakotank1( 224-240, 1600, -20, 9, 4);}
      if(time==2840){Tzakotank1( 224+240, 1820, 160, 15, 4);}
      if(time==3000){Tzakocannon1a( 224-160, 1790, 1, 5, 2);}

      if(time==3350){CreateEnemyFromFile( sky2, 224-30, -30, 2, 90, 0);}
      if(time==3500){CreateEnemyFromFile( sky2, 224-100, -30, 2, 90, 0);}
      if(time==3620){CreateEnemyFromFile( sky2, 224+30, -30, 2, 90, 0);}

      if(time==3750){CreateEnemyFromFile( sky2, 224+100, -30, 2, 90, 0);}
      if(time==3820){CreateEnemyFromFile( sky2, 224-0, -30, 2, 90, 0);}
      if(time==3890){CreateEnemyFromFile( sky2, 224-100, -30, 2, 90, 0);}

      if(time==4030){CreateEnemyFromFile( item, 224, 0, 2, 90, 0);}

      if(time==3600){CreateEnemyFromFile( st3semiboss, 224, 2050, 0, 0, 0);}

      if(time==4740&&GetCommonData("haya")==1){CreateEnemyFromFile( sky2, 224+0, -30, 2, 90, 0);}
      if(time==4840&&GetCommonData("haya")==1){CreateEnemyFromFile( sky2, 224-60, -30, 2, 90, 0);}
      if(time==4940&&GetCommonData("haya")==1){CreateEnemyFromFile( sky2, 224+60, -30, 2, 90, 0);}
      if(time==5040&&GetCommonData("haya")==1){CreateEnemyFromFile( sky2, 224-100, -30, 2, 90, 0);}
      if(time==5140&&GetCommonData("haya")==1){CreateEnemyFromFile( sky2, 224+0, -30, 2, 90, 0);}
      if(time==5240&&GetCommonData("haya")==1){CreateEnemyFromFile( sky2, 224+100, -30, 2, 90, 0);}

      if(time==4900){CreateEnemyFromFile( zakocannon1, 224+170, 2640, 4, 0, 0);}
      if(time==4900){CreateEnemyFromFile( zakocannon1, 224+125, 2660, 4, 0, 0);}
      if(time==4900){CreateEnemyFromFile( zakocannon1, 224+75, 2680, 4, 0, 0);}
      if(time==4900){CreateEnemyFromFile( zakocannon1, 224+25, 2680, 4, 0, 0);}
      if(time==4900){CreateEnemyFromFile( zakocannon1, 224-25, 2680, 4, 0, 0);}
      if(time==4900){CreateEnemyFromFile( zakocannon1, 224-75, 2680, 4, 0, 0);}
      if(time==4900){CreateEnemyFromFile( zakocannon1, 224-125, 2660, 4, 0, 0);}
      if(time==4900){CreateEnemyFromFile( zakocannon1, 224-170, 2640, 4, 0, 0);}


      if(time<1000){SetCommonData("bgy",time*0.6);}
      if(time>=1000&&time<1500){SetCommonData("bgy",600+(time-1000)*0.4);}
      if(time>=1500&&time<3200){SetCommonData("bgy",800+(time-1500)*0.6);}
      if(time>=3200&&time<5450){SetCommonData("bgy",1820+(time-3200)*0.4);}
      if(time>=5450&&time<5550){SetCommonData("bgy",2720+(time-5450)*0.2);}
      if(time==5550){phase=2;time=0;}

   }
   if(phase==2){
      if(time==0){Tzakogun303;}
      if(time==0){CreateEnemyFromFile( sky3, 224-224, 30, 2, 40, 0);}
      if(time==100-10){CreateEnemyFromFile( sky3, 224+224, 30, 2, 140, 0);}
      if(time==200+10){CreateEnemyFromFile( sky3, 224-150, 0, 2, 60, 0);}
      if(time==320-10){CreateEnemyFromFile( sky3, 224+224, 0, 2, 135, 0);}
      if(time==440+10){CreateEnemyFromFile( sky3, 224-224, 140, 2, 20, 0);}
      if(time==560-20){CreateEnemyFromFile( sky3, 224+224, 140, 2, 160, 0);}

      if(time==600){CreateEnemyFromFile( lift, 224-240, 2070, 4, 32, 290);}
      if(time==680){CreateEnemyFromFile( lift, 224+240, 2030, 4, 148, 300);}
      if(time==820){CreateEnemyFromFile( lift, 224-240, 1730, 4, -32, 280);}
      if(time==840){CreateEnemyFromFile( lift, 224+240, 1675, 4, -148, 310);}

      if(time==1300){CreateEnemyFromFile( lift, 224+240, 1855, 4, 148, 500);}
      if(time==1550){CreateEnemyFromFile( lift, 224+240, 1855, 4, 148, 240);}
      if(time==1520){CreateEnemyFromFile( lift, 224-240, 1855, 4, 32, 280);}
      if(time==1620){CreateEnemyFromFile( lift, 224+240, 1555, 4, -148, 300);}
      if(time==1630){CreateEnemyFromFile( lift, 224-240, 1465, 4, -32, 350);}

      if(time==2100){Tzakoheli2( 224-240, 0, 40, 8, 10, 4);}
      if(time==2140){Tzakoheli2( 224-200, -40, 40, 8, 10, 4);}
      if(time==2180){Tzakoheli2( 224-280, 40, 40, 8, 10, 4);}

      if(time==2250){Tzakoheli2( 224+240, 0, 140, 8, 10, 4);}
      if(time==2290){Tzakoheli2( 224+200, -40, 140, 8, 10, 4);}
      if(time==2330){Tzakoheli2( 224+280, 40, 140, 8, 10, 4);}

      if(time==2400){Tzakoheli2a( 40, 8, 10, 4);}
      if(time==2430){Tzakoheli2a( 80, 8, 10, 4);}
      if(time==2460){Tzakoheli2a( 120, 8, 10, 4);}
      if(time==2490){Tzakoheli2a( 160, 8, 10, 4);}
      if(time==2520){Tzakoheli2a( 200, 8, 10, 4);}
      if(time==2550){Tzakoheli2a( 240, 8, 10, 4);}
      if(time==2580){Tzakoheli2a( 280, 8, 10, 4);}
      if(time==2610){Tzakoheli2a( 320, 8, 10, 4);}


      if(time<100){SetCommonData("bgy",2740-time*0.2);}
      if(time>=100&&time<200){SetCommonData("bgy",2720-(time-100)*0.6);}
      if(time>=200&&time<600){SetCommonData("bgy",2660-(time-200)*1.2);}
      if(time>=600&&time<2100){SetCommonData("bgy",2180-(time-600)*0.2);}
      if(time>=2100&&time<2700){SetCommonData("bgy",1880-(time-2100)*0.6);}
      if(time>=2700&&time<2800){SetCommonData("bgy",1520-(time-2700)*0.2);}
      if(time==2800){phase=3;time=0;}
   }
   if(phase==3){
      if(time==0){Tzakogun304;}

      if(time==0){Tzakogun305;}
      /*if(time==740){Tzakogun306;}*/
      if(time==400){CreateEnemyFromFile( tank1, 224, 1690, 4, 90, 600);}
      if(time==700){CreateEnemyFromFile( tank1, 224, 1810, 4, 90, 600);}
      if(time==1000){CreateEnemyFromFile( tank1, 224, 1930, 4, 90, 600);}

      if(time==400){Tzakosky1b( -1, 10, 13, 4);}
      if(time==550-20){Tzakosky1a( -1, 10, 11, 4);}
      if(time==700){Tzakosky1b( 1, 10, 13, 4);}
      if(time==850-20){Tzakosky1a( 1, 10, 11, 4);}
      if(time==1000){Tzakosky1b( -1, 10, 13, 4);}
      if(time==1150-20){Tzakosky1a( -1, 10, 11, 4);}
      /*if(time==450){Tzakosky1b( -1, 10, 13, 2);}
      if(time==700){Tzakosky1a( -1, 10, 13, 2);}
      if(time==900){Tzakosky1b( 1, 10, 13, 2);}
      if(time==1150){Tzakosky1a( 1, 10, 13, 2);}*/

      if(time==1350){Tzakosky1b( -1, 10, 18, 4);}
      if(time==1370){Tzakosky1a( 1, 10, 18, 4);}
      if(time==1450){Tzakosky1a( -1, 10, 18, 4);}
      if(time==1470){Tzakosky1b( 1, 10, 18, 4);}

      if(time==1700-30){CreateEnemyFromFile( skybig1, 224+280, -100, 4, 1, 0);}
      if(time==2000-20){CreateEnemyFromFile( skybig1, 224-280, -100, 4, -1, 0);}
      if(time==2250-10){CreateEnemyFromFile( skybig1, 224+280, -100, 4, 1, 0);}
      if(time==2500-0){CreateEnemyFromFile( skybig1, 224-280, -100, 4, -1, 0);}

      if(time==3000){CreateEnemyFromFile( item, 224, 0, 4, 90, 0);}




      if(time==3400&&GetCommonData("ex")==0){CreateEnemyBossFromFile( st3boss, 224, 200, 0, 0, 0);}
      if(time==3400&&GetCommonData("ex")==1){CreateEnemyBossFromFile( st3exboss, 224, 200, 0, 0, 0);}

      if(time==3200){DeleteMusic(bgmst3);PlaySE( se4 );}
      if(time==3400){PlayMusic(bgmlastboss);}

      if(time<100){SetCommonData("bgy",1500+time*0.2);}
      if(time>=100&&time<3400){SetCommonData("bgy",1520+(time-100)*0.4);}


      if(time>3500&&GetCommonData("bossphase")==0){DeleteMusic(bgmlastboss);}
      if(time>3500&&IsBossExisting==false&&clear==false){
         if(GetCommonData("ex")==0){Tclear2}
         else{phase=4;time=0;}
      }
      if(time>3500&&GetCommonData("ex")==1&&GetCommonData("bossphase")==1){
         phase=4;time=0;
      }
      
   }
   if(phase==4){
      if(GetCommonData("ex")==0){
         SetCommonData("bgy",2840);
      }
      else{


      if(speed==1){
         if(time>=780){time-=300;}
         if(GetCommonData("bossphase")==0){DeleteMusic(bgmlastboss);}
         if(IsBossExisting==false&&clear==false){
            if(stageselect==true){Tclear;}
            else{
               speed=12;
               CreateEnemyBossFromFile( trueboss, 224, 400, 0, 0, 0);
               PlayMusic(bgmtruelastboss);
            }
         }
      }
      if(speed>1){
         if(GetCommonData("bossphase")==0){DeleteMusic(bgmtruelastboss);}
         if(IsBossExisting==false&&clear==false){
            Tclear3;
         }
      }
      SetCommonData("bgy",2840+time);
      time+=-1+speed/2;



      }
   }
}