#e
#Title[ӖuCW[Ag[rgv(sver)]
#Text[sł]
#ScriptVersion[2]

script_enemy_main {
 let img = "script\img\ExRumia.png";
 let name = "ӖuCW[Ag[rgv";
 let sWait = 60;
 let dWait = 1200;

 @Initialize {
  CutIn(KOUMA, name, "", 0, 0, 0, 0);
  SetX(GetCenterX);
  SetY(GetCenterY - 120);
  SetLife(5000);
  SetScore(1000000);
  SetTimer(99);

  LoadGraphic(img);
  SetTexture(img);
  SetGraphicRect(64, 0, 128, 64);

  TMain;
 }

 @MainLoop {
  SetCollisionA(GetX, GetY, 24);
  SetCollisionB(GetX, GetY, 24);

  yield;
 }

 @DrawLoop {
  DrawGraphic(GetX, GetY);
 }

 @Finalize {
  DeleteGraphic(img);
 }

 //ȉ^XN(}CNXbh)

 task TMain {
  yield;

  TMove;
  TShot;

  wait(220);
  TLaser;
  THorming; //Ă
 }

 task TMove {
  yield;

  loop {
   loop(120) { yield; }
   randomMove(rand(-80, 80), rand(-10, 10), 120, GetClipMinX + 60, GetClipMinY + 30, GetClipMaxX - 60, GetCenterY - 60);
  }
 }

 task TShot {
  yield;

  loop {
   wait(sWait);
   loop(180) {
    CreateShotA(1, rand(GetClipMinX, GetClipMaxX), rand(GetClipMinY, GetClipMaxY), 120);
    SetShotDataA(1, 0, 0.3, NULL, 0, 0, 0.1, RED02);
    FireShot(1);
    yield;
   }
   wait(dWait);
   DeleteEnemyShot(SHOT);
  }
 }

 task TLaser {
  yield;

  loop {
   loop(2) { yield; }
   CreateLaser01(GetX, GetY, rand(1, 2), rand(0, 360), 50, 6, WHITE11, 0);
  }
 }

 task THorming {
  yield;

  loop {
   wait(sWait + 180);
   loop(3) {
    CreateHomingShot(GetX, GetY, 0.5, rand(0, 360), 60, 1000, BLUE01);
    yield;
   }
   wait(dWait);
  }
 }
   

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

 function randomMove(xMove, yMove, frame, left, top, right, bottom) {
  let x;
  let y;

  x = GetX + xMove;

  if(x < left) {
   x = left;
  }
  if(right < x) {
   x = right;
  }

  y = GetY + yMove;
  if(y < top) {
   y = top;
  }
  else if(bottom < y) {
   y = bottom;
  }

  SetMovePosition02(x, y, frame);
 }

 task CreateHomingShot(x, y, speed, angle, mo, limit, graphic) {
  let obj = Obj_Create(OBJ_SHOT);

  Obj_SetPosition(obj, x, y);
  Obj_SetSpeed(obj, speed);
  Obj_SetAngle(obj, angle);
  ObjShot_SetGraphic(obj, graphic);

  loop(limit) {
   if(Obj_BeDeleted(obj)) {
    break;
   }

   let angleToPlayer = atan2(GetPlayerY - Obj_GetY(obj), GetPlayerX - Obj_GetX(obj));

   if(sin(angleToPlayer - Obj_GetAngle(obj)) > 0) {
    Obj_SetAngle(obj, Obj_GetAngle(obj) + mo);
   }
   else {
    Obj_SetAngle(obj, Obj_GetAngle(obj) - mo);
   }
   yield;
  }
 }

}