#e
#Title[PueTւ̒ǕS-Lunatic-v]
#Text[G@ĹupXBv
dl̓sňxł~X{g肷ƃz[~OeȂ܂]
#ScriptVersion[2]
#PlayLevel[Lunatic]
#Player[FREE]

script_enemy_main {
 let img = "script\img\ExRumia.png";
 let name = "PueTւ̒ǕS-Lunatic-v";
 let obj = Obj_Create(OBJ_SHOT);
 let obj2 = Obj_Create(OBJ_SHOT);

 @Initialize {
  CutIn(KOUMA, name, "", 0, 0, 0, 0);
  SetX(GetCenterX);
  SetY(GetCenterY);
  SetLife(7000);
  SetTimer(50);
  SetScore(1000000);

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

  TMain;
  THoming;
  TDraw;
  TShot;
 }

 @MainLoop {
  SetCollisionA(GetX, GetY, 32);
  SetCollisionB(GetX, GetY, 2);

  yield;
 }

 @DrawLoop {
  DrawGraphic(GetX, GetY);
 }
	
 @Finalize {
  DeleteGraphic(img);
 }
	
 task TMain {
  yield;

  loop {
   CreateHomingShot(GetX, GetY, 1, GetAngleToPlayer, 2, 3000, WHITE03);
   loop(750) { yield; }
  }
 }

 task THoming {
  yield;

  loop {
   CreateHomingShot2(GetX, GetY, 0.5, atan2(Obj_GetY(obj) - Obj_GetY(obj2), Obj_GetX(obj) - Obj_GetX(obj2)), 2, 3000, RED03);
   loop(750) { yield; }
  }
 }

 task TDraw {
  let xm = 0;
  let ym = 0;
  yield;

  loop {
   loop(5) { yield; }
   CreateShot01(GetClipMinX + xm, GetCenterY, 0, 90, BLUE21, 0);
   xm += 40;
   if(xm == 440) {
    xm = 0;
   }

   loop(5) { yield; }
   CreateShot01(GetCenterX, GetClipMinY + ym, 0, 180, GREEN21, 0);
   ym += 40;
   if(ym > 460) {
    ym = 0;
   }
  }
 }

 task TShot {
  yield;

  loop {
   loop(60) { yield; }
   CreateShot01(GetX, GetY, rand(0.1, 0.5), rand(0, 360), BLUE11, 0);
   CreateShot01(GetX, GetY, rand(0.1, 0.5), rand(0, 360), BLUE11, 0);
   CreateShot01(GetX, GetY, rand(0.1, 0.5), rand(0, 360), BLUE11, 0);
   CreateShot01(GetX, GetY, rand(0.1, 0.5), rand(0, 360), BLUE11, 0);
   CreateShot01(GetX, GetY, rand(0.1, 0.5), rand(0, 360), BLUE11, 0);
   CreateShot01(GetX, GetY, rand(0.1, 0.5), rand(0, 360), BLUE11, 0);
   CreateShot01(GetX, GetY, rand(0.1, 0.5), rand(0, 360), BLUE11, 0);
   CreateShot01(GetX, GetY, rand(0.1, 0.5), rand(0, 360), PURPLE11, 0);
   CreateShot01(GetX, GetY, rand(0.1, 0.5), rand(0, 360), BLUE11, 0);
   CreateShot01(GetX, GetY, rand(0.1, 0.5), rand(0, 360), BLUE11, 0);
   CreateShot01(GetX, GetY, rand(0.1, 0.5), rand(0, 360), BLUE11, 0);
   CreateShot01(GetX, GetY, rand(0.1, 0.5), rand(0, 360), BLUE11, 0);
   CreateShot01(GetX, GetY, rand(0.1, 0.5), rand(0, 360), BLUE11, 0);
   CreateShot01(GetX, GetY, rand(0.1, 0.5), rand(0, 360), BLUE11, 0);
   CreateShot01(GetX, GetY, rand(0.1, 0.5), rand(0, 360), BLUE11, 0);
   CreateShot01(GetX, GetY, rand(0.1, 0.5), rand(0, 360), BLUE11, 0);
   CreateShot01(GetX, GetY, rand(0.1, 0.5), rand(0, 360), BLUE11, 0);
   CreateShot01(GetX, GetY, rand(0.1, 0.5), rand(0, 360), BLUE11, 0);
   CreateShot01(GetX, GetY, rand(0.1, 0.5), rand(0, 360), BLUE11, 0);
   CreateShot01(GetX, GetY, rand(0.1, 0.5), rand(0, 360), BLUE11, 0);
  }
 }

 task CreateHomingShot(x, y, speed, angle, mo, limit, graphic) {

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

 task CreateHomingShot2(x, y, speed, angle, mo, limit, graphic) {

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

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

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

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

}
