#東方弾幕風
#Title[戯言「サーファイスピエロ」]
#Text[仮]
#ScriptVersion[2]

script_enemy_main {
 let img = "script\img\ExRumia.png";
 let name = "戯言「サーファイスピエロ」";
 let pet = 0;
 let pet2 = 0;
 let pet3 = 0;
 let pet4 = 0;
 let angle = 0;
 let angle2 = 90;
 let angle3 = 180;
 let angle4 = 270;

 @Initialize {
  CutIn(KOUMA, name, "", 0, 0, 0, 0); //カットイン
  SetX(GetCenterX);
  SetY(GetCenterY);
  SetLife(5000);
  SetScore(1000000);
  SetTimer(50);

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

  TMain;
 }

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

  pet += 1;
  CreateShot01(GetX + offsetX(80, 90), GetY + offsetY(80, 90), 2, angle, WHITE31, 0);
  if(pet <= 120) {
   angle += 1;
  }
  if(pet > 120 && pet <= 360) {
   angle -= 1;
  }
  if(pet > 360) {
   angle += 1;
  }
  if(pet > 480) {
   pet = 0;
  }

  pet2 += 1;
  CreateShot01(GetX + offsetX(80, 0), GetY + offsetY(80, 0), 2, angle2, WHITE31, 0);
  if(pet2 <= 120) {
   angle2 += 1;
  }
  if(pet2 > 120 && pet2 <= 360) {
   angle2 -= 1;
  }
  if(pet2 > 360) {
   angle2 += 1;
  }
  if(pet2 > 480) {
   pet2 = 0;
  }

  pet3 += 1;
  CreateShot01(GetX + offsetX(80, -90), GetY + offsetY(80, -90), 2, angle3, WHITE31, 0);
  if(pet3 <= 120) {
   angle3 += 1;
  }
  if(pet3 > 120 && pet3 <= 360) {
   angle3 -= 1;
  }
  if(pet3 > 360) {
   angle3 += 1;
  }
  if(pet3 > 480) {
   pet3 = 0;
  }

  pet4 += 1;
  CreateShot01(GetX + offsetX(80, 180), GetY + offsetY(80, 180), 2, angle4, WHITE31, 0);
  if(pet4 <= 120) {
   angle4 += 1;
  }
  if(pet4 > 120 && pet4 <= 360) {
   angle4 -= 1;
  }
  if(pet4 > 360) {
   angle4 += 1;
  }
  if(pet4 > 480) {
   pet4 = 0;
  }

  yield;
 }

 @DrawLoop {
  DrawGraphic(GetX, GetY);
 }

 @Finalize {
  DeleteGraphic(img);
 }

 //以下タスク(マイクロスレッド)

 task TMain {
  yield;

  TMove;
  TShot; //何個足してもおｋ
 }

 task TMove {
  yield;

  loop {
   loop(120) { yield; }
   moveToPlayer(rand(-200, 200), rand(-200, 200), 120, GetClipMinX, GetClipMinY, GetClipMaxX, GetClipMaxY);
  }
 }

 task TShot {
  let S = 0;
  let C = 0;
  let angle9 = 90;
  yield;

  loop {
   loop(1) { yield; }
   loop(12) {
    CreateShotA(1, GetX + offsetX(80, S), GetY + offsetY(80, C), 0);
    SetShotDataA(1, 0, 2, angle9, 0, 0, 0, WHITE03);
    FireShot(1);
    S += 30;
    C += 30;
    angle9 -= 30;
    yield;
   }
  }
 }

 function offsetX(radius, mid) {
  return radius * sin(mid);
 }

 function offsetY(radius, mid) {
  return radius * cos(mid);
 }

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

 function moveToPlayer(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;
  }

  CreateShot01(x, y, 0, 0, RED01, 0);

  SetMovePosition02(x, y, frame);
 }

}