
#Title[镄@ǔЁv]
#Text[EXy6]
#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"; 
  let slow = 0;

   @Initialize{
  SetCommonDataEx("","bg",4);
     CutIn(KOUMA, name, "", 0, 0, 0, 0);
     SetScore(3000000);
           SetLife(750);
      SetDamageRate(20,0);
           SetTimer(70);
           SetInvincibility(180);
         sgr(0,0);
         SetMovePosition03(GetCenterX,GetClipMinY+140,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",3);
        DeleteGraphic(imgBOSS);
        DeleteGraphic(effect);
  loop(64){
     CreateItem(ITEM_SCORE,rand(minx,maxx),miny+rand(16,150)); 
       }   
     }
 
     task TMain{
     wait(60);
  SetShotAutoDeleteClip(64,64,64,64);
        Shot; 
        Count;
    loop{
   if(OnBomb){
   SetAlpha(0);
   SetDamageRate(0,0);}
     else{
    SetAlpha(255);
   SetDamageRate(20,0);}
    wait(1);
      }
    }

   task Shot{
  loop{
  con(120/(slow+1));
  let n = rand_int(0,2);
 /*  SlowEffect(n); */
    Shot1;
  wait(120/(slow+1));
  Move;
 con(90/(slow+1));
  let n = rand_int(0,2);
 /* SlowEffect(n); */
   Shot2;
   wait(120/(slow+1));
  Move;
  con(90/(slow+1));
  let n = rand_int(0,2);
 /* SlowEffect(n); */
   Shot3;
  wait(120/(slow+1));
 SetMovePosition03(GetCenterX,GetClipMinY+140,20,5*(slow+1));
     wait(120/(slow+1));
 con(90/(slow+1));
  let n = rand_int(0,2);
/*  SlowEffect(n); */
   Shot4;
   wait(180/(slow+1));
  n = 0;
   }

  task Shot1{
 let d = 0;
 let basecolor = [RED01,ORANGE01,YELLOW01,
       GREEN01,AQUA01,BLUE01,PURPLE01];
 let delay = 10;
 let way = 20;
  ascent(b in 0..way){
   ascent(c in 0..2){
  ascent(a in 0..3){
 let angle = 180*c+30*(a-1)+d;
 let color = basecolor[truncate(b/3)];
 let radius = b*10;
 let x = cx+offsetX(radius,angle);
 let y = miny+140+offsetY(radius,angle);
 let v = -1-1.5*(slow+1); let accel = 0.05*(slow+1);
  let vmax = rand(0.2,5);
  Light(x,y,v,90,accel,vmax,color,delay);
  d += rand(-3,3);
       }
      }
   wait(3-slow);
      }
     }
   task Shot2{
 let d = 0;
 let basecolor = [RED01,ORANGE01,YELLOW01,
       GREEN01,AQUA01,BLUE01,PURPLE01];
 let delay = 10;
 let way = 45;
  ascent(b in 0..way){
  ascent(a in 0..7){
 let color = basecolor[6-a];
 let x = minx+12*b-20-12*a;
 let y = cy+180-10*b-40*a;
 let v = rand(-2,-0.5)-1.5*(slow+1); let accel = 0.05*(slow+1);
  let vmax = rand(0.2,5);
  Light(x,y,v,90,accel,vmax,color,delay);
      }
   wait(3-slow);
      }
     }
  task Shot3{
 let d = 0;
 let basecolor = [RED01,ORANGE01,YELLOW01,
       GREEN01,AQUA01,BLUE01,PURPLE01];
 let delay = 10;
 let way = 45;
  ascent(b in 0..way){
  ascent(a in 0..7){
 let color = basecolor[6-a];
 let x = maxx-12*b+20+12*a;
 let y = cy+180-10*b-40*a;
 let v = rand(-2,-0.5)-1.5*(slow+1); let accel = 0.05*(slow+1);
  let vmax = rand(0.2,5);
  Light(x,y,v,90,accel,vmax,color,delay);
      }
   wait(3-slow);
      }
     }
  task Shot4{
 let d = 0;
 let basecolor = [RED01,ORANGE01,YELLOW01,
       GREEN01,AQUA01,BLUE01,PURPLE01];
 let delay = 10;
 let way = 34;
  ascent(b in 0..way){
   ascent(c in 0..2){
  ascent(a in 0..3){
 let color = basecolor[truncate(b/5)];
 let x = cx+200*(-1)^c-12*(-1)^c*b;
 let y = cy+50-100*a+50*c;
 let v = rand(-2,-0.5)-1.5*(slow+1); let accel = 0.05*(slow+1);
  let vmax = rand(0.2,5);
  Light(x,y,v,90,accel,vmax,color,delay);
      }
    }
   wait(3-slow);
      }
     }
  }

   task Light(x,y,v,angle,accel,vmax,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);
  let accel2 = accel;
     while(!Obj_BeDeleted(p)){
  let nowslow = slow;
  if(Obj_GetSpeed(p) >= -0.1 && Obj_GetSpeed(p) <= 0.1){Obj_SetAngle(p,rand(85,95));}
   if(Obj_GetSpeed(p) >= 0 && Obj_GetSpeed(p) <= 1){accel = rand(0.001,0.02)*(slow+1);}
   else if(Obj_GetSpeed(p) >= 0.98 &&Obj_GetSpeed(p) <= 1.02){accel = rand(0.05,0.1)*(slow+1);}
      Obj_SetSpeed(p,Obj_GetSpeed(p)+accel);
   wait(1);
 if(nowslow == 0){Obj_SetSpeed(p,Obj_GetSpeed(p)*(slow+1)); accel = accel*(slow+1);}
 else if(nowslow == 1){Obj_SetSpeed(p,Obj_GetSpeed(p)*(slow+1)/2); accel = accel*(slow+1)/2;}
 else if(nowslow == 2){Obj_SetSpeed(p,Obj_GetSpeed(p)*(slow+1)/3); accel = accel*(slow+1)/3;}
  if(Obj_GetSpeed(p) > vmax*(slow+1)){Obj_SetSpeed(p,vmax*(slow+1));}
     }
   }

    task Move{
   let f = 2*(slow+1);
  let r = rand_int(0,1);
 if(GetX < minx+64){r = 0;}
    else if(GetX > maxx-64){r = 1;}
    let x = GetX + rand(64,96)*(-1)^r;
    let y = GetY + rand(-48,48);
    if(y < miny+48){y = miny+48;}
    else if(y > miny+160){y = miny+180;}
  /* if(GetX > x){sgr(2,1);}
   else if(GetX < x){sgr(2,3);}  */
    SetMovePosition03(x,y,15,f);
     wait(180);
    }

  function con(frame){
    Concentration01(frame);
     PlaySE(secon);
    wait(frame);
    }

   function SlowEffect(dd){
     Slow(dd);
   slow = dd;
  }

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