
#Title[@u̗v]
#Text[EXy11]
#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(3000000);
           SetLife(800);
      SetDamageRate(20,0);
           SetTimer(80);
           SetInvincibility(120);
         sgr(0,0);
      /*   SetMovePosition03(GetCenterX,GetClipMinY+100,20,5);*/
        SetAlpha(255);
           LoadGraphic(imgBOSS);
    LoadGraphic(effect);
          LoadUserShotData(shotData);
   Circle2(60);
           TMain;
    }

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

         yield;
       }

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

    @Finalize{
 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);
          wait(90);
        Shot;
        Count;
    loop{
   if(OnBomb){
   SetAlpha(0);
   SetDamageRate(0,0);}
     else{
    SetAlpha(255);
   SetDamageRate(20,0);}
    wait(1);
      }
    }

   task Shot{
/* Shot2;*/
  loop{Shot4;}
  function Shot4{
 sgr(5,1);
  let color = YELLOW01;
  let delay = 20;
    let accel = -0.1;
    let base = GetAngleToPlayer;
  loop(120){
   loop(1){
   let r = rand(0,32);
   let ra = rand(-180,180);
      let angle = 180*rand_int(0,1);
      let x = GetX+offsetX(r,ra);
      let y = GetY+offsetY(r,ra);
    let v = rand(1,8);
      Ref(x,y,v,base,color,delay);
   }
   PlaySE(seshot4);
   wait(1);
   }
  ascent(a in 0..18){
 CreateShot02(GetX,GetY,20,GetAngleToPlayer+20*(a-2),-1,0.5,GREEN03,30);
   }
   wait(30);
   Move;
   wait(30);
       }
  task Shot2{
  loop{
  CreateShot02(rand(minx-16,maxx+16),maxy+16,0.5,-90,0.001,10,3,30);
  CreateShot02(rand(minx-16,maxx+16),GetY,0.5,-90,0.001,10,3,0);
   wait(10);
    }
      }
    }

   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+180*rand_int(0,1)-90);
         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(20);
    Obj_SetSpeed(p,v);
   Obj_SetAngle(p,angle);
  /* 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;}
       }
}