script_enemy_main{
      #include_script".\Local.txt"
    let shotData = csd ~ "data_usershot.txt"; 
  /* let arg = GetArgument;
   let difficult = GetCommonDataDefaultEx("","dif",0); */
 let kshot = 0;
 let kmove = 0;
 let movemax = [0,5,3,0,0,0,0,3,0,5,0,9,0,0];
 let movemin = [0,0,0,0,0,0,0,0,0,0,0,0,0,0];
 let kposi = 0;
 let posimax = [0,0,0,0,0,0,1,0,0,0,0,0,0,0];
 let posimin = [0,0,0,0,0,0,0,0,0,0,0,0,0,0];
 let playmode = 0;
 let playercharacter = 0;
 let PracticeStageFrag = GetCommonDataDefaultEx("","psf",[false]);
 let PracticeCardFrag = GetCommonDataDefaultEx("","pcf",[false]);
 let SpellCardHistory = GetCommonDataDefaultEx("","sch",[0]);
 let GetSpellCard = GetCommonDataDefaultEx("","gsc",[0]);
 let psftruenum = 0;
 ascent(a in 0..length(PracticeStageFrag)){
 if(PracticeStageFrag[a]){psftruenum++;}
  else{}
   }

	@Initialize
	{
 SetCommonDataEx("","dif",difficult);
         SetLife(arg[0]);
            SetDamageRate(0,arg[2]);
           LoadUserShotData(shotData);
          SetInvincibility(arg[3]);
   sgrnum = -1;
               Main;
	}
	
	@MainLoop{
    /*    SetCollisionA(GetX(),GetY(),arg[4]);
	SetCollisionB(GetX(),GetY(),arg[4]);*/
      if(GetKeyState(VK_UP) == KEY_PUSH){kmove--; PlaySE(counter);}
      else if(GetKeyState(VK_DOWN) == KEY_PUSH){kmove++; PlaySE(counter);}
      else if(GetKeyState(VK_LEFT) == KEY_PUSH){kposi--; PlaySE(counter);}
      else if(GetKeyState(VK_RIGHT) == KEY_PUSH){kposi++; PlaySE(counter);}
      else if(GetKeyState(VK_SHOT) == KEY_PUSH){
         alternative(kshot)
          case(1){playmode = kmove+1;
            alternative(kmove)
             case(0){}
             case(1){kshot += 2; kshot -= 3; PlaySE(pi2);}
             case(2){kshot += 4; 
                     if(psftruenum < 1){kshot -= 5; PlaySE(pi2);}
                     }
             case(3){kshot = 0; PlaySE(pi2);} 
             case(4){kshot = 0; PlaySE(pi2);}
             case(5){kshot = 12; playmode = -1; VanishEnemy;}
                         }
          case(2){difficult = kmove; VanishEnemy;}
          case(3){playercharacter = kmove;}
          case(4){difficult = kmove;}
          case(5){playercharacter = kmove;}
          case(6){ 
             alternative(kposi)
              case(0){}
              case(1){kshot += 3; kshot++;  /*kshot -= 4;  PlaySE(pi2); */}
             }
          case(7){difficult = kmove;  kshot++;}
          case(8){playercharacter = kmove;}
          case(9){
               if(PracticeStageFrag[100*playercharacter + 10*(kmove+1) + difficult]){playmode = kmove+3; VanishEnemy;}
               else{kshot--; PlaySE(pi2);}
                  }
          case(10){playercharacter = kmove;}
          case(11){
           if(PracticeCardFrag[kmove+1]){
             alternative(kmove)
              case(0){difficult = 2; playmode = 4.11; VanishEnemy;}
              case(1){difficult = 3; playmode = 4.11; VanishEnemy;}
              case(2){difficult = 0; playmode = 4.12; VanishEnemy;}
              case(3){difficult = 1; playmode = 4.12; VanishEnemy;}
              case(4){difficult = 2; playmode = 4.12; VanishEnemy;}
              case(5){difficult = 3; playmode = 4.12; VanishEnemy;}
              case(6){difficult = 0; playmode = 4.13; VanishEnemy;}
              case(7){difficult = 1; playmode = 4.13; VanishEnemy;}
              case(8){difficult = 2; playmode = 4.13; VanishEnemy;}
              case(9){difficult = 3; playmode = 4.13; VanishEnemy;}
                    }
            else{kshot--; PlaySE(pi2);}
                 }
          others{kshot = 0;}
            kshot++; 
     kmove = movemin[kshot];   kposi = posimin[kshot]; 
            PlaySE(push);
                    }

      else if(GetKeyState(VK_BOMB) == KEY_PUSH){
       kshot--; 
   if(kshot < 0){kshot = 1;}
   kmove = movemin[kshot];  kposi = posimin[kshot]; 
   PlaySE(cancel);
           alternative(kshot)
          case(0){kshot++; kmove = movemax[kshot];}
          case(1){playmode = 0;}
          case(2){difficult = 0;}
          case(3){kshot = 1; difficult = 0;}
          case(4){difficult = 0;}
          case(5){kshot = 1; difficult = 0;}
          case(7){difficult = 0;}
          case(8){playercharacter = 0;     kshot = 7;}
          case(9){kshot = 1;}
          case(10){playercharacter = 0; kshot = 6;}
          case(11){kshot = 1;}
             }
      
   if(kmove < movemin[kshot]){kmove = movemax[kshot];}
   else if(kmove > movemax[kshot]){kmove = movemin[kshot];}
   if(kposi < posimin[kshot]){kposi = posimax[kshot];}
   else if(kposi > posimax[kshot]){kposi = posimin[kshot];}
 /*  if(kshot < 0){kshot = 0;} */
		yield;
	}
	
       	@DrawLoop{
    alternative(kshot)
   case(0){SetTexture(Title);
    SetAlpha(255);
    alternative(arg[6])
     case(0){SetColor(255,200,255);}
     case(1){SetColor(255,200,255);}
     case(2){SetColor(255,0,128);}
     case(3){SetColor(255,200,255);}
     case(4){SetColor(255,200,255);}
     case(5){SetColor(255,200,255);}
     case(6){SetColor(224,200,128);}
     case(7){SetColor(200,200,200);}
       }
   case(1){SetTexture(Menu);
     if(arg[6] == kmove){SetAlpha(255);}
     else{SetAlpha(64);}
       }
   case(2,7){SetTexture(Title);
    alternative(arg[6])
     case(0,4){SetColor(64,255,64);
       if(kmove == 0){SetAlpha(255);}
       else{SetAlpha(64);}
              }
     case(1,5){SetColor(64,255,255);
       if(kmove == 1){SetAlpha(255);}
       else{SetAlpha(64);}
              }
     case(2,6){SetColor(64,64,255);
       if(kmove == 2){SetAlpha(255);}
       else{SetAlpha(64);}
              }
     case(3,7){SetColor(255,0,255);
       if(kmove == 3){SetAlpha(255);}
       else{SetAlpha(64);}
              }
      }

   case(6){SetTexture(Menu);
         if(arg[6] == kposi){SetAlpha(255);}
         else{SetAlpha(64);}
           alternative(arg[6])
             case(0){SetColor(255,128,128);}
             case(1){SetColor(255,255,128);}
            }
   case(7){SetTexture(Title);}
   case(9){SetTexture(OutText);
        if(arg[6] == kmove){SetAlpha(255);}
         else{SetAlpha(64);}
        if(PracticeStageFrag[100*playercharacter + 10*(arg[6]+1) + difficult]){SetColor(255,255,255);}
         else{SetColor(128,128,128);}
            }
   case(11){SetTexture(spell1);
         if(arg[6] == kmove){SetAlpha(255);}
         else{SetAlpha(64);}
          if(PracticeCardFrag[arg[6]+1]/* && GetSpellCard[arg[6]+1] > 0*/){
           alternative(arg[6])
            case(0){SetColor(64,64,255);}
            case(1){SetColor(255,0,255);}
            case(2){SetColor(64,255,64);}
            case(3){SetColor(64,255,255);}
            case(4){SetColor(64,64,255);}
            case(5){SetColor(255,0,255);}
            case(6){SetColor(64,255,64);}
            case(7){SetColor(64,255,255);}
            case(8){SetColor(64,64,255);}
            case(9){SetColor(255,0,255);}
               }
          else{SetColor(255,255,255);}
  if(GetSpellCard[arg[6]+1] > 0){
  SetFontColor(255,255,255,255,255,0);
  DrawText(ToString(""),cx+150,cy-150+10+30*arg[6],20,255);
  SetFontColor(255,255,255,255,255,255);
              }
            }

  /* case(3){SetTexture(EnemyYellow);}
   case(4){SetTexture(EnemyEx1);}
   case(5){SetTexture(EnemyEx2);}
   case(6){SetTexture(EnemyOther);}
   case(13){SetTexture(White);}   */
    others{SetTexture(White);}
   
    DrawGraphic(GetX,GetY);
/* DrawText(length(PracticeStageFrag),cx,cy-150+30*arg[6],20,255);
 DrawText(100*playercharacter+10*(arg[6]+1)+difficult,cx-180,cy-150+30*arg[6],20,255);*/
 SetColor(255,255,255);
 SetAlpha(255);
	}

	@Finalize{ 
         SetCommonDataEx("","dif",difficult); 
         SetCommonDataEx("","mode",playmode); 
         SetCommonDataEx("","chr",playercharacter); 
	}

         task Main{
             yield; 
       Move;
     }

     task Move{
   alternative(arg[6])
  case(0){
  loop{
    alternative(kshot)
    case(0){
   SetX(cx-90); SetY(miny+80);
   SetGraphicScale(3,3);
   SetGraphicRect(0,0,30,32);
        }
   case(1){
  SetGraphicScale(1,1);
   SetX(cx+85); SetY(cy);
   SetGraphicRect(0,0,150,32);
           }
  case(2,7){
  SetX(cx-90+90); SetY(cy-120+90-120*kmove);
  SetGraphicScale(2,2);
   SetGraphicRect(0,164,65,190);
        }
   case(6){
  SetGraphicScale(1,1);
   SetX(cx-75); SetY(cy);
   SetGraphicRect(170,0,260,34);
           }
   case(9){
   SetGraphicScale(1,1);
   SetX(cx); SetY(cy-75);
  if(PracticeStageFrag[100*playercharacter + 10*1+ difficult]){SetGraphicRect(0,130,100,170);}
  else{SetGraphicRect(655,130,755,170);}
       }
  case(11){
    SetGraphicScale(0.5,0.5);
    SetX(cx); SetY(cy-15+30*(arg[6]-4));
    if(PracticeCardFrag[arg[6]+1]){SetGraphicRect(0,0,512,32);}
    else{SetGraphicRect(512,0,1024,32);} 
       }
     others{SetGraphicRect(0,0,0,0);}
    wait(1);
           }
        }

 case(1){
   loop{
    alternative(kshot)
  case(0){
   SetX(cx-30+100); SetY(miny+80);
   SetGraphicScale(3,3);
   SetGraphicRect(32,0,60,32);
        }
   case(1){
   SetGraphicScale(1,1);
  SetX(cx+95); SetY(cy+30);
  SetGraphicRect(0,32,150,64);
        }
   case(2,7){
  SetX(cx+90-90); SetY(cy-120+90-120*(kmove-1));
  SetGraphicScale(2,2);
   SetGraphicRect(0,215,65,241);
        }
  case(6){
   SetGraphicScale(1,1);
  SetX(cx+75); SetY(cy);
  SetGraphicRect(170,34,250,64);
        }   
   case(9){
   SetGraphicScale(1,1);
   SetX(cx); SetY(cy-45);
 if(PracticeStageFrag[100*playercharacter + 10*2+ difficult]){SetGraphicRect(110,130,210,170);}
  else{SetGraphicRect(655,130,755,170);}
       }
   case(11){
    SetGraphicScale(0.5,0.5);
    SetX(cx); SetY(cy-15+30*(arg[6]-4));
    if(PracticeCardFrag[arg[6]+1]){SetGraphicRect(0,32,512,64);}
    else{SetGraphicRect(512,32,1024,64);} 
       }
     others{SetGraphicRect(0,0,0,0);} 
      wait(1);
       }
    }

   case(2){ let rad = -1; 
     loop{  rad++; 
    alternative(kshot)
  case(0){
   SetX(cx-130); SetY(miny+160+150*(sin(rad/6))^2);
   SetGraphicScale(-3,-3);
   SetGraphicRect(60,0,88,32-7);
        }
   case(1){
   SetGraphicScale(1,1);
  SetX(cx+105); SetY(cy+60);
   SetGraphicRect(0,64,150,96);
      }
  case(2,7){
  SetX(cx-90+90); SetY(cy-120+90-120*(kmove-2));
  SetGraphicScale(2,2);
   SetGraphicRect(0,267,65,298);
        }
    case(9){
   SetGraphicScale(1,1);
   SetX(cx); SetY(cy-15);
   if(PracticeStageFrag[100*playercharacter + 10*3+ difficult]){SetGraphicRect(220,130,320,170);}
  else{SetGraphicRect(655,130,755,170);}
       }
   case(11){
    SetGraphicScale(0.5,0.5);
    SetX(cx); SetY(cy-15+30*(arg[6]-4));
    if(PracticeCardFrag[arg[6]+1]){SetGraphicRect(0,64,512,96);}
    else{SetGraphicRect(512,64,1024,96);} 
       }
   others{SetGraphicRect(0,0,0,0);}
    wait(1);
         }
        }

   case(3){
     loop{
    alternative(kshot)
   case(0){
   SetX(cx-35); SetY(miny+170);
   SetGraphicScale(3,3);
   SetGraphicRect(90,0,118,32);
        }
   case(1){
   SetGraphicScale(1,1);
  SetX(cx+115); SetY(cy+90);
    SetGraphicRect(0,102,150,134);
        }
   case(2,7){
  SetX(cx+90-90); SetY(cy-120+90-120*(kmove-3));
  SetGraphicScale(2,2);
   SetGraphicRect(0,320,65,350);
        }
    case(9){
   SetGraphicScale(1,1);
   SetX(cx); SetY(cy+15);
   if(PracticeStageFrag[100*playercharacter + 10*4+ difficult]){SetGraphicRect(330,130,430,170);}
  else{SetGraphicRect(655,130,755,170);}
       }
   case(11){
    SetGraphicScale(0.5,0.5);
    SetX(cx); SetY(cy-15+30*(arg[6]-4));
    if(PracticeCardFrag[arg[6]+1]){SetGraphicRect(0,98,512,130);}
    else{SetGraphicRect(512,98,1024,130);} 
       }
     others{SetGraphicRect(0,0,0,0);}
       wait(1);
       }
    }

   case(4){
    loop{
    alternative(kshot)
 case(0){
   SetX(cx+35); SetY(miny+170);
   SetGraphicScale(3,3);
   SetGraphicRect(118,0,142,32);
        }
   case(1){
  SetGraphicScale(1,1);
   SetX(cx+125); SetY(cy+120);
  SetGraphicRect(0,138,150,170);
        }
  case(2,7){
  SetX(cx-90+90); SetY(cy+15-120*kmove);
  SetGraphicScale(1,1);
   SetGraphicRect(100,164,335,190);
        }
    case(9){
   SetGraphicScale(1,1);
   SetX(cx); SetY(cy+45);
  if(PracticeStageFrag[100*playercharacter + 10*5+ difficult]){SetGraphicRect(448,130,548,170);}
  else{SetGraphicRect(655,130,755,170);}
       }
   case(11){
    SetGraphicScale(0.5,0.5);
    SetX(cx); SetY(cy-15+30*(arg[6]-4));
    if(PracticeCardFrag[arg[6]+1]){SetGraphicRect(0,132,512,164);}
    else{SetGraphicRect(512,132,1024,164);} 
       }
    others{SetGraphicRect(0,0,0,0);}
    wait(1);
     }
   }

   case(5){
   loop{
    alternative(kshot)
  case(0){
   SetX(cx+125); SetY(miny+170);
   SetGraphicScale(3,3);
   SetGraphicRect(145,0,175,32);
        }
   case(1){
   SetGraphicScale(1,1);
   SetX(cx+135); SetY(cy+150);
  SetGraphicRect(0,174,150,206);
        }
  case(2,7){
  SetX(cx-90+90); SetY(cy+15-120*(kmove-1));
  SetGraphicScale(1,1);
   SetGraphicRect(100,215,355,241);
        }
    case(9){
   SetGraphicScale(1,1);
   SetX(cx); SetY(cy+75);
  if(PracticeStageFrag[100*playercharacter + 10*6+ difficult]){SetGraphicRect(545,130,645,170);}
  else{SetGraphicRect(655,130,755,170);}
       }
  case(11){
   SetGraphicScale(0.5,0.5);
   SetX(cx); SetY(cy-15+30*(arg[6]-4));
   if(PracticeCardFrag[arg[6]+1]){SetGraphicRect(0,164,512,196);}
   else{SetGraphicRect(512,164,1024,196);} 
       }
     others{SetGraphicRect(0,0,0,0);}
    wait(1); 
    } 
  }

   case(6){
   loop{
    alternative(kshot)
   case(0){
   SetX(cx); SetY(cy+20);
   SetGraphicScale(1,1);
   SetGraphicRect(0,58,32*7,96);
        }
   case(1){
  SetGraphicRect(0,0,0,0);
        }
   case(2,7){
  SetX(cx-90+90); SetY(cy+15-120*(kmove-2));
  SetGraphicScale(1,1);
   SetGraphicRect(100,267,358,298);
        }
   case(11){
   SetGraphicScale(0.5,0.5);
   SetX(cx); SetY(cy-15+30*(arg[6]-4));
   if(PracticeCardFrag[arg[6]+1]){ SetGraphicRect(0,196,512,228);}
   else{ SetGraphicRect(512,196,1024,228);} 
       }
    others{SetGraphicRect(0,0,0,0);}
   wait(1);
    }
   }

   case(7){
    loop{
    alternative(kshot)
   case(0){
    SetX(cx+100); SetY(cy+40);
   SetGraphicScale(0.5,0.5);
   SetGraphicRect(32*7,58,32*12,96);
        }
   case(1){
 SetGraphicRect(0,0,0,0);
        }
   case(2,7){
  SetX(cx-90+90); SetY(cy+15-120*(kmove-3));
  SetGraphicScale(1,1);
   SetGraphicRect(100,320,335,350);
        }
  case(11){
   SetGraphicScale(0.5,0.5);
   SetX(cx); SetY(cy-15+30*(arg[6]-4));
   if(PracticeCardFrag[arg[6]+1]){SetGraphicRect(0,230,512,262);}
   else{SetGraphicRect(512,230,1024,262);} 
       }
   others{SetGraphicRect(0,0,0,0);}
    wait(1);
     }
   }

   case(8){
    loop{
    alternative(kshot)
   case(0,1,2){
  SetGraphicRect(0,0,0,0);
        }
  case(11){
    SetGraphicScale(0.5,0.5);
   SetX(cx); SetY(cy-15+30*(arg[6]-4));
  if(PracticeCardFrag[arg[6]+1]){SetGraphicRect(0,262,512,294);}
  else{SetGraphicRect(512,262,1024,294);} 
       }
    others{SetGraphicRect(0,0,0,0);}
    wait(1);
     } 
   }

   case(9){
    loop{
    alternative(kshot)
   case(0,1,2){
   SetGraphicRect(0,0,0,0);
        }
   case(11){
    SetGraphicScale(0.5,0.5);
   SetX(cx); SetY(cy-15+30*(arg[6]-4));
  if(PracticeCardFrag[arg[6]+1]){SetGraphicRect(0,296,512,328);}
  else{SetGraphicRect(512,296,1024,328);}
       }
    others{SetGraphicRect(0,0,0,0);}
    wait(1);
     }
   }


   wait(1);
   }

     function offsetX(radius,angle){
           return radius * cos(angle);
     }

        function offsetY(radius,angle){
            return radius * sin(angle);
     }           

  function sgr(a,b,c,d){SetGraphicRect(a*c,b*c,(a+1)*c,(b+1)*c);}

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