script_enemy_main{
      #include_script".\Local.txt"
    let shotData = csd ~ "data_usershot.txt"; 
  /* let arg = GetArgument;
   let difficult = GetCommonDataDefaultEx("","dif",0); */
	@Initialize
	{
 SetCommonDataEx("","dif",difficult);
         SetLife(arg[0]);
            SetDamageRate(100,arg[2]);
           LoadUserShotData(shotData);
          SetInvincibility(arg[3]);
   sgrnum = 1;
               Main;
	}
	
	@MainLoop{
  if(GetCommonDataDefaultEx("","gof",false)){
       SetDamageRate(0,0);
      SetSpeed(0);
       break;
       }
        SetCollisionA(GetX(),GetY(),arg[4]);
	SetCollisionB(GetX(),GetY(),arg[4]);
		yield;
	}
	
       	@DrawLoop{
    alternative(arg[1])
   case(0){SetTexture(EnemyBlue);}
   case(1){SetTexture(EnemyRed);}
   case(2){SetTexture(EnemyGreen);}
   case(3){SetTexture(EnemyYellow);}
   case(4){SetTexture(EnemyEx1);}
   case(5){SetTexture(EnemyEx2);}
   case(6){SetTexture(EnemyOther);}
    others{SetTexture(EnemyBlue);}
   GraphicTurn;
    DrawGraphic(GetX,GetY);
/* DrawText(ToString(EnemyBlue),cx-180,cy+90,20,255);*/
	}

	@Finalize{ 
         if(!BeVanished){
             AddScore(arg[7]); 
      ascent(a in 0..arg[8]){
     let x = GetX; 
     let y = GetY;
       CreateItem(ITEM_SCORE,x,y);
       x = GetX+offsetX(rand(3,15),rand(-180,180));
       y = GetY+offsetY(rand(3,15),rand(-180,180));
                }
  /*   ascent(a in 0..arg[9]){
     let x = GetX;  let y = GetY;
       CreateItem(ITEM_SCORE,x,y);
       x = GetX+offsetX(rand(3,15),rand(-180,180));
       y = GetY+offsetY(rand(3,15),rand(-180,180));
                }  */
      ascent(a in 0..arg[10]){
     let x = GetX;   let y = GetY;
       CreateItem(ITEM_BOMB,x,y);
                }
       ascent(a in 0..arg[11]){
     let x = GetX;   let y = GetY;
       CreateItem(ITEM_1UP,x,y);
                }
            }
	}

         task Main{
             yield; 
    alternative(difficult)
   case(0){Easy;}
   case(1){Normal;}
   case(2){Hard;}
   case(3){Lunatic;}
       Move;
   wait(180);
     }

     task Easy{
   alternative(arg[5])
    case(11){
  wait(60+30);
    CreateShot02(GetX,GetY,8,GetAngleToPlayer,-0.5,0.75,70,5);
    PlaySE(seshot1);
          }
   case(12){
   wait(rand_int(0,30));
   loop{
    CreateShot02(GetX,GetY,8,GetAngleToPlayer,-0.5,1,30,5);
    PlaySE(seshot1);
   wait(120);
       }
          }
  case(13){
  wait(rand_int(0,30));
   loop{
    CreateShot02(GetX,GetY,8,GetAngleToPlayer,-0.5,0.5,30,5);
    PlaySE(seshot1);
   wait(120);
         } 
         }
       }

     task Normal{
    alternative(arg[5])
    case(11){
   wait(60+30);
  ascent(a in 0..5){
    CreateShot02(GetX,GetY,8,GetAngleToPlayer+5*(a-2),-0.5,2,70,5);
     }
   PlaySE(seshot1);
          }
      case(12){
  wait(rand_int(0,30));
   loop{
     ascent(a in 0..3){
    CreateShot02(GetX,GetY,8,GetAngleToPlayer+5*(a-1),-0.5,1.5,30,5);
     }
    PlaySE(seshot1);
   wait(90);
       }
          }
    case(13){
  wait(rand_int(0,30));
   loop{
    CreateShot02(GetX,GetY,8,GetAngleToPlayer,-0.5,0.5,30,5);
    PlaySE(seshot1);
   wait(90);
         } 
         }
    }

     task Hard{
    alternative(arg[5])
    case(11){
   wait(60+30);
     ascent(b in 0..7){
   let angle = GetAngleToPlayer+7*(b-3);
    CreateShot02(GetX,GetY,8,angle,-0.5,3,70,5);
   }
   PlaySE(seshot1);
       }
   case(12){
  wait(rand_int(0,30));
   loop{
     ascent(b in 0..5){
    CreateShot02(GetX,GetY,8,GetAngleToPlayer+5*(b-2),-0.5,2,30,5);
     }
    PlaySE(seshot1);
   wait(60);
       }
          }
     case(13){
  wait(rand_int(0,30));
   loop{
    CreateShot02(GetX,GetY,8,GetAngleToPlayer,-0.5,0.5,30,5);
    PlaySE(seshot1);
   wait(60);
         } 
         }
   }

     task Lunatic{
     alternative(arg[5])
    case(11){
   wait(60+30);
     ascent(b in 0..13){
   let angle = GetAngleToPlayer+5*(b-6);
    CreateShot02(GetX,GetY,8,angle,-0.5,4,70,5);
   }
   PlaySE(seshot1);
     }
   case(12){
  wait(rand_int(0,30));
   loop{
      ascent(b in 0..7){
    CreateShot02(GetX,GetY,8,GetAngleToPlayer+5*(b-3),-0.5,3,30,5);
     }
    PlaySE(seshot1);
   wait(30);
       }
          }
     case(13){
  wait(rand_int(0,30));
   loop{
     CreateShot02(GetX,GetY,8,GetAngleToPlayer,-0.5,0.5,30,5);
    PlaySE(seshot1);
   wait(30);
         } 
         }
  }

     task Move{
     alternative(arg[6])
  case(0){wait(60);}
    case(1){ 
  let accel = GetSpeed/60;
  sgrnum = 2;
    loop(60){
   SetSpeed(GetSpeed-accel);
   wait(1);
            }
   sgrnum = 1;
    wait(150);
     SetAngle(-GetAngle);
   sgrnum = 2;
      loop(60){
   SetSpeed(GetSpeed+accel);
   wait(1);
            }
        }
   case(2){ 
    wait(60);
  sgrnum = 2;
     loop(80){
   SetAngle(GetAngle+1);
     wait(1);
        } 
      }
   case(3){ 
    wait(60);
  sgrnum = 2;
     loop(80){
   SetAngle(GetAngle-1);
     wait(1);
        } 
     }

    while(GetX >= minx-32 && GetX <= maxx+32 && GetY >= miny-32 && GetY <= maxy+32){wait(1);}
     VanishEnemy;
   }

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