
#Title[u̎􂢂̍v]
#Text[EXy12]
#Player[FREE]
#ScriptVersion[2]

script_enemy_main{
    #include_script".\Local.txt"
   let name        = "u̎􂢂̍v";
   let imgBOSS = csd~"img\dot_mugetu.png";
   let shotData = csd ~ "data_usershot.txt";
  let effect = csd ~ "img\circle.png"; 

   @Initialize{
 SetCommonDataEx("","bg",9);
     CutIn(KOUMA, name, "", 0, 0, 0, 0);
     SetScore(5000000);
           SetLife(10000);
      SetDamageRate(100,0);
           SetTimer(150);
           SetInvincibility(120);
         sgr(0,0);
      /*   SetMovePosition03(GetCenterX,GetClipMinY+100,20,5);*/
        SetAlpha(255);
           LoadGraphic(imgBOSS);
    LoadGraphic(effect);
          LoadUserShotData(shotData);
   Circle2(60);
  SetEffectForZeroLife(60,128,1);
           TMain;
    }

   @MainLoop{
    if(OnEvent){break;}
    if(!OnBomb){
      SetCollisionA(GetX, GetY, 24);
      SetCollisionB(GetX, GetY, 18);
     }

         yield;
       }

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

    @Finalize{
   PlaySE(sevanish);
 SetCommonDataEx("","bg",8);
        DeleteGraphic(imgBOSS);
        DeleteGraphic(effect);
  loop(64){
     CreateItem(ITEM_SCORE,rand(minx,maxx),miny+rand(16,150)); 
       }   
  CreateItem(ITEM_1UP,GetX,GetY); 
     }
 
     task TMain{
    yield;
  SetX(cx); SetY(miny+100);
        Shot;
        Count;
    loop{
   if(OnBomb){
   SetAlpha(0);
   SetDamageRate(0,0);}
     else{
    SetAlpha(255);
   SetDamageRate(100,0);}
    wait(1);
      }
    }

   task Shot{
  Shot1;
  Shot2;
  task Shot1{
  let t = 5; 
  let base = 0;
  let g = 0;
 let way = 2;
  loop{
  if(GetLife < 9000 && GetTimer >= 30){way = 4;}
  if(GetLife < 8000 && GetTimer >= 30){way = 6;}
  if(GetLife < 7000 && GetTimer >= 30){way = 8;}
  if(GetLife < 6000 && GetTimer >= 30){way = 10;}
  if(GetLife < 5000 && GetTimer >= 30){way = 12;}
  if(GetLife < 4000 && GetTimer >= 30){way = 15;}
  if(GetLife < 3000 && GetTimer >= 30){way = 18;}
  if(GetLife < 2000 && GetTimer >= 30){way = 20;}
  if(GetLife < 1000 || GetTimer < 30){way = 24;}
   ascent(a in 0..way){
  let angle = GetAngleToPlayer + 360/way*a+base;
  CreateShot02(GetX,GetY,6,angle,-0.2,3,8,0);
    }
 base += t;  
 g++;
 if(g >= 60){t = -t; g = 0;}
  wait(5);
      }
     }
    task Shot2{
  let t = 9; 
  let base = 0;
 let g = 0;
  loop{
   ascent(d in 0..2){
   ascent(a in 0..4){
 let angle = GetAngleToPlayer + 90*a+base;
  let x = GetX+offsetX(4,angle-90+180*d);
   let y = GetY+offsetY(4,angle-90+180*d);
  CreateShot01(x,y,5,angle,174,0);
    }
   }
 base -= t;  
  g++;
 if(g >= 60){t = -t; g = 0;}
  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);
      wait(delay);
    while(!Obj_BeDeleted(p) && Obj_GetSpeed(p) > 0){
      Obj_SetSpeed(p,Obj_GetSpeed(p)-0.1);
      wait(1);
      }
    Obj_SetSpeed(p,0);
    wait(60);
    Obj_SetSpeed(p,v);
   Obj_SetAngle(p,90);
  /* while(!Obj_BeDeleted(p) && Obj_GetY(p) < maxy){wait(1);}
   Obj_SetAngle(p,-90);*/
   }


     function Move{
  sgr(0,0);
  ascent(a in 0..16){
   SetGraphicRect(0,0,128,128-(a+1)*8);
 SetY(miny+100-(a+1)*4);
   wait(1);
      }
  let basex = GetX;
   SetX(rand(minx+64,maxx-64));
 while(GetX >= basex-64 && GetX <= basex+64){
  SetX(rand(minx+64,maxx-64));
  }
   let basey = GetY;
     ascent(a in 0..16){
   SetGraphicRect(0,0,128,(a+1)*8);
 SetY(basey+(a+1)*4);
   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);}

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