
#Title[HEʏe2]
#Text[HEʏe2]
#Player[FREE]
#ScriptVersion[2]

script_enemy_main{
    #include_script".\Local.txt"
 #include_function".\function_bullet.txt"
   let imgBOSS = csd~"img\dot_yuka.png";
   let shotData = csd ~ "data_usershot.txt";
  let effect = csd ~ "img\circle.png";
  let vanish = false;

   @Initialize{
 SetCommonDataEx("","bg",7);
           SetLife(1);
      SetDamageRate(0,0);
     /*      SetTimer(30);  */
           SetInvincibility(120);
         sgr(0,0);
   SetX(cx);
   SetY(miny+120);
 /*SetMovePosition03(GetCenterX,GetClipMinY+120,20,10);*/
        SetAlpha(255);
           LoadGraphic(imgBOSS);
    LoadGraphic(effect);
          LoadUserShotData(shotData);
           TMain;
    }

   @MainLoop{
    if(OnEvent){break;}
         yield;
       }

   @DrawLoop{
         SetTexture(imgBOSS);  
        DrawGraphic(GetX,GetY);
     }

    @Finalize{
        DeleteGraphic(imgBOSS);
        DeleteGraphic(effect);
     }
 
     task TMain{
  wait(120);
  SpinMotion(35);
  SetX(cx);
   SetY(miny+120);
  ascent(a in 0..18){
      SetAlpha(255-15*a);
   if(a >= 15){vanish = false;}
   wait(2);
      }
  sgr(3,2);
  imgBOSS = csd~"img\UFG.png";
  LoadGraphic(imgBOSS);
  Angle;
      ascent(a in 0..18){
      SetAlpha(15*a);
   if(a >= 15){vanish = false;}
   wait(2);
      }
        Shot;
    }

   task Shot{
    ShotA;   Move(210,20,90);
  wait(195+120);
    ShotA;   Move(210,75,-60);
    wait(195+120);
    ShotB;   Move(210,20,180);
  wait(195+120);
   ShotC; SetSpeed(6); SetAngle(30); Move2(360); 
   wait(360+210);  
  ShotD;  Move3(300+420);
   wait(300+120);
  ShotE;
   wait(300);
  VanishEnemy;

   task ShotA{
  loop(13){
  let angle = rand(-180,180);
  ascent(a in 0..36){
  CreateShot01(GetX,GetY,4.5,angle+10*a,16,0);
           }
       wait(15);
         }
       }
   task ShotB{
  let v = 4;
  loop(13){
  let angle = rand(-180,180);
  ascent(a in 0..36){
  CreateShot01(GetX,GetY,v,angle+10*a,38,30);
           }
   PlaySE(seshot3);
    v += 0.2;
       wait(15);
         }
       }
   task ShotC{
  let v = 2.5; let color = 155;
  let delay = 0;
  loop(36){
  let angle = rand(-180,180);
  ascent(a in 0..5){
  let angle = -90+20*(a-2);
 Ref(GetX,GetY,v,angle,color,delay)
     }
   PlaySE(seshot4);
       wait(10);
         }
       }
    task ShotD{
  loop(20){
  let angle = GetAngleToPlayer;
  ascent(a in 0..36){
  CreateShot01(GetX,GetY,3,angle+10*a,16,0);
           }
    ascent(a in 0..18){
  CreateShot01(GetX,GetY,4.5,angle+20*a,16,0);
           }
       wait(15);
         }
       }


    task ShotE{
  let v = 8;
  loop(2){
  loop(4){
     CreateItem(ITEM_SCORE,GetX,GetY);
   PlaySE(seshot4);
    wait(5); 
       } 
  wait(30);
  loop(4){
   ascent(a in 0..5){
  CreateShot01(GetX,GetY,v,GetAngleToPlayer+5*(a-2),16,0);
           }
   PlaySE(seshot3);
       wait(5);
         }
   wait(30);
        }
     CreateItem(ITEM_1UP,GetX,GetY);
   PlaySE(seshot4);  
  wait(30);
  loop(4){
   ascent(a in 0..5){
  CreateShot01(GetX,GetY,v,GetAngleToPlayer+5*(a-2),16,0);
           }
   PlaySE(seshot3);
       wait(5);
         }
       }
  }

  task Ref(x,y,v,angle,color,delay){
        let p = Obj_Create(OBJ_SHOT);
         Obj_SetX(p,x);
         Obj_SetY(p,y);
         Obj_SetSpeed(p,v);
         Obj_SetAngle(p,angle);
         ObjShot_SetGraphic(p,color); 
         ObjShot_SetDelay(p,delay);
         Obj_SetAutoDelete(p,true);
         ObjShot_SetBombResist(p,false);
         Obj_SetCollisionToObject(p,true);
         Obj_SetCollisionToPlayer(p,true);

     while(!Obj_BeDeleted(p)){
 if(Obj_GetX(p) < minx || Obj_GetX(p) > maxx){Obj_SetAngle(p,180-Obj_GetAngle(p));}
 if(Obj_GetY(p) < miny){Obj_SetAngle(p,-Obj_GetAngle(p));}
   wait(1);
      }
   }

  task Angle{
   loop{
    let t = rand(-180,180);
    SetGraphicAngle(0,0,t);
       wait(3);
        }
     }

    task Move(f,r,base){
    let radius = 0; 
     loop(f){
      SetX(cx+offsetX(radius,base));
      SetY(miny+120+offsetY(radius,base));
      radius += r/30;
    if(radius > r){radius = r;}
      base -= 2.5;
      wait(1);
        }
     SetMovePosition02(cx,miny+120,30);
    }

   task Move2(f){
     loop(f){
   if(GetX < minx || GetX > maxx){SetAngle(180-GetAngle+rand(-5,5));}
   if(GetY < miny || GetY > miny+160){SetAngle(-GetAngle+rand(-5,5));}
     wait(1);
        }
  SetMovePosition02(cx,miny+120,30);
    }

   task Move3(f){
  let base = 0; let t = 1.5;
   ascent(a in 0..f){
   SetX(GetX+t);
   SetY(miny+120+offsetY(80,base));
  base += 3;
   if(GetX > maxx && a <= 600){t = -1.5;}
    if(GetX < minx && a <= 600){t = 1.5;}
    wait(1);
       }
      }

    function offsetX(radius,angle){
           return radius * cos(angle);
     }

        function offsetY(radius,angle){
            return radius * sin(angle);
     }           

       function move(f){
          SetMovePosition02(rand(GetClipMinX+60,GetClipMaxX-60),GetY+rand(-20,20),f);
     }
            
        function sc(r,g,b){
             SetShotColor(r,g,b);
     }

  function sgr(a,b){SetGraphicRect(a*128,b*128,(a+1)*128,(b+1)*128);}

  task SpinMotion(f){
      ascent(a in 0..4){
         sgr(7,a);
       wait(f/4);
            }
          sgr(0,0);
      }

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