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 = 5;
               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{ 
   let x = GetX; 
     let y = GetY;
         if(!BeVanished){
             AddScore(arg[7]); 
    ascent(a in 0..arg[10]){CreateItem(ITEM_BOMB,x,y);}
       ascent(a in 0..arg[11]){CreateItem(ITEM_1UP,x,y);}
      ascent(a in 0..arg[8]){
       CreateItem(ITEM_SCORE,x,y);
       x = GetX+offsetX(rand(3,36),rand(-180,180));
       y = GetY+offsetY(rand(3,36),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));
                }  */
            }
	}

         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);
   loop{
  let base = rand(-180,180);
      ascent(a in 0..6){
   let angle = 60*a+base;
   CreateShot01(GetX,GetY,1,angle,8,5);
     }
   wait(90);
            }
         }
       }

     task Normal{
    alternative(arg[5])
    case(11){
    wait(60);
   loop{
  let base = rand(-180,180);
      ascent(a in 0..10){
   let angle = 36*a+base;
   CreateShot01(GetX,GetY,1,angle,8,5);
     }
   wait(60);
            }
          }
    }

     task Hard{
    alternative(arg[5])
    case(11){
     wait(60);
   loop{
  let base = rand(-180,180);
      ascent(a in 0..12){
   let angle = 30*a+base;
   CreateShot01(GetX,GetY,1,angle,8,5);
     }
   wait(50);
            }
        }
   }

     task Lunatic{
     alternative(arg[5])
    case(11){
     wait(60);
   loop{
  let base = rand(-180,180);
      ascent(a in 0..18){
   let angle = 20*a+base;
   CreateShot01(GetX,GetY,1,angle,8,5);
     }
   wait(30);
            }
        }
  }

     task Move{
     alternative(arg[6])
    case(1){
   sgrnum = 6;
    wait(60);
         }

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