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 = 7;
               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);
  let t = 0;
        loop{
     if(t%45 == 0){
   let base = rand(-180,180);
      ascent(a in 0..8){
   let angle = base + 45*a;
   let x = GetX+offsetX(16,angle);
   let y = GetY+offsetY(16,angle);
   CreateShot01(x,y,1.2,angle,35,10);
    }
   }
       t++;
   wait(1);
              }
           }
  case(12){
   wait(90);
    loop{
  let base = GetAngleToPlayer+1;
  ascent(a in 1..11){
   ascent(b in 0..a){
  let angle = base + 2*(b-truncate(a/2))-a%2;
   CreateShot01(GetX,GetY,1.5,angle,65,5);
         }
   PlaySE(seshot1);
   wait(10);
      }
   wait(100);
        }
        }
       }

     task Normal{
    alternative(arg[5])
    case(11){
   wait(60);
  let t = 0;
        loop{
     if(t%30 == 0){
   let base = rand(-180,180);
      ascent(a in 0..12){
   let angle = base + 30*a;
   let x = GetX+offsetX(16,angle);
   let y = GetY+offsetY(16,angle);
   CreateShot01(x,y,1.6,angle,35,10);
    }
   }
       t++;
   wait(1);
              }
         }
  case(12){
   wait(90);
    loop{
  let base = GetAngleToPlayer+1.25;
  ascent(a in 1..11){
   ascent(b in 0..a){
  let angle = base + 2.5*(b-truncate(a/2))-(a%2)*1.25;
   CreateShot01(GetX,GetY,2.25,angle,65,5);
         }
   PlaySE(seshot1);
   wait(6);
      }
   wait(80);
        }
        }
    }

     task Hard{
    alternative(arg[5])
    case(11){
   wait(60);
  let t = 0;
        loop{
     if(t%20 == 0){
   let base = rand(-180,180);
      ascent(a in 0..15){
   let angle = base + 24*a;
   let x = GetX+offsetX(16,angle);
   let y = GetY+offsetY(16,angle);
   CreateShot01(x,y,2.4,angle,35,10);
    }
   }
       t++;
   wait(1);
              }
       }
   case(12){
   wait(90);
    loop{
  let base = GetAngleToPlayer+1.5;
  ascent(a in 1..11){
   ascent(b in 0..a){
    ascent(c in 0..3){
  let angle = base + 3*(b-truncate(a/2))-(a%2)*1.5 + 120*c;
   CreateShot01(GetX,GetY,3,angle,65,5);
         }
    }
   PlaySE(seshot1);
   wait(5);
      }
   wait(75);
        }
        }
   }

     task Lunatic{
     alternative(arg[5])
    case(11){
      wait(60);
  let t = 0;
        loop{
     if(t%15 == 0){
   let base = rand(-180,180);
      ascent(a in 0..20){
   let angle = base + 18*a;
   let x = GetX+offsetX(16,angle);
   let y = GetY+offsetY(16,angle);
   CreateShot01(x,y,3,angle,35,10);
    }
   }
       t++;
   wait(1);
              }
          }
  case(12){
   wait(90);
    loop{
  let base = GetAngleToPlayer+2;
  ascent(a in 1..11){
   ascent(b in 0..a){
    ascent(c in 0..6){
  let angle = base + 4*(b-truncate(a/2))-(a%2)*2 + 60*c;
   CreateShot01(GetX,GetY,4,angle,65,5);
         }
     }
   PlaySE(seshot1);
   wait(4);
      }
   wait(60);
        }
        }
  }

     task Move{
     alternative(arg[6])
    case(1){
  let accel = GetSpeed/30;
 if(absolute(GetAngle) != 90){
  sgrnum = 7;
     }
    loop(30){
     SetSpeed(GetSpeed-accel);
      wait(1);
            }
  sgrnum = 7;
    wait(570);
   if(absolute(GetAngle) != 90){
   sgrnum = 8;
       }
    loop(30){
     SetSpeed(GetSpeed-accel/5);
      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;}
       }
}