#e
#Title[tH[OiCt]
#Text[O̒ʂł]
#ScriptVersion[2]

script_enemy_main {
 let img = "script\img\ExRumia.png";
 let name = "tH[OiCt";
 let pet = 0;
 let bow = 0;
 let power = 0;

 @Initialize {
  CutIn(KOUMA, name, "", 0, 0, 0, 0);
  SetMovePosition02(GetCenterX, GetCenterY, 100);
  SetLife(5000);
  SetTimer(99);
  SetScore(1000000);

  LoadGraphic(img);
  SetTexture(img);
  SetGraphicRect(0, 0, 63, 63);

  TMove;
 }

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

  pet += 1;
  if(pet == 100) {
   CreateShot01(GetCenterX * rand(0, 6) / 3, GetClipMinY, 2, 90, GREEN32, 0);
   pet = 98;
  }
  bow += 1;
  if(bow == 120) {
   CreateShot01(GetCenterX * rand(0, 6) / 3, GetClipMinY, 1.9, 90, BLUE31, 0);
   bow = 117;
  }
  power += 1;
  if(power == 140) {
   CreateShot01(GetCenterX * rand(0, 6) / 3, GetClipMinY, 1.75, 90, RED32, 0);
   power = 137;
  }

  yield;
 }

 @DrawLoop {
  DrawGraphic(GetX, GetY);
 }

 @Finalize {
  DeleteGraphic(img);
 }

 function moveToPlayer(xMove, yMove, frame, left, top, right, bottom) {
  let x;
  x = GetX + xMove;
  if(x < left) {
   x = left;
  }
  else if(right < x) {
   x = right;
  }

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

  SetMovePosition02(x, y, frame);
 }

 task TMove {
  yield;

  loop {
   loop(100) { yield; }
   moveToPlayer(rand(-500, 500), rand(-500, 250), 90,
                GetClipMinX, GetClipMinY,
                GetClipMaxX, GetClipMaxY);
  }
 }

}