
#Title[ʏe1]
#Text[]
#Player[FREE]
#ScriptVersion[2]

script_enemy_main{
    #include_script".\Local.txt"
   #include_function".\function_bullet.txt"
   let imgBOSS = csd~"img\dot_itirin.png";
   let shotData = csd ~ "data_usershot.txt";

   @Initialize{
   SetCommonDataEx("","dif",difficult);
           SetLife(2700);
      SetDamageRate(100,60);
           SetTimer(34);  
           SetInvincibility(120);
         sgr(0,0);
        SetAlpha(255);
           LoadGraphic(imgBOSS);
          LoadUserShotData(shotData);
           TMain;
    }

   @MainLoop{
    if(OnEvent){break;}
   if(GetCommonDataDefaultEx("","gof",false)){
       SetDamageRate(0,0);
       SetTimer(100);
       break;
       }
           SetCollisionA(GetX, GetY, 24);
           SetCollisionB(GetX, GetY, 20);

         yield;
       }

   @DrawLoop{
         SetTexture(imgBOSS); 
   if(GetHitCount >= rand_int(1,damage) && GetTimeOfInvincibility == 0){
   SetColor(0,0,255);
        }
        DrawGraphic(GetX,GetY);
        SetColor(255,255,255);
  SetFontColor(255,255,0,255,255,0);
  DrawText("Itirin Kumoi",minx+15,miny+15,10,255);
  SetFontColor(255,255,255,255,255,255);
     }

    @Finalize{
  if(difficult == 2 || difficult == 3){
 SetCommonDataEx("","timeout",IsTimeOut);
   }
        DeleteGraphic(imgBOSS);
   if(difficult >= 2 || IsTimeOut){}
   else{PlaySE(sevanish);}
   if(difficult <= 1 && !IsTimeOut){
  loop(10){
     CreateItem(ITEM_SCORE,GetX+offsetX(rand(16,48),rand(0,360)),GetY+offsetY(rand(16,48),rand(0,360))); 
       }   
       }
     }
 
     task TMain{
  yield;
    Count;
 SetMovePosition03(cx,miny+100,10,3);
   wait(120);
  alternative(difficult)
   case(0){Easy;}
   case(1){Normal;}
   case(2){Hard;}
   case(3){Lunatic;}
    }

 task Easy{
  let delay = 5;
  let color = 68;
  loop{
  let base = GetAngleToPlayer;
 sgrnum = 3;
     ascent(d in 0..2){
 let r = 16;
  ascent(b in 0..20){
   ascent(a in 0..1){
     ascent(c in 0..5){
  let v = 2-0.05*c;
 let angle = base+(240-18*b)*(-1)^d;
   let x = GetX+offsetX(r,angle);
   let y = GetY+offsetY(r,angle);
  CreateShotA(0,x,y,delay);
  SetShotDataA(0,0,v,angle,-1.5*(-1)^(d),0,v,color+2*d);
  SetShotDataA(0,90,NULL,NULL,-0.2*(-1)^(d),0,v,color+2*d);
  SetShotDataA(0,300,NULL,NULL,0,0,v,color+2*d);
  FireShot(0);
      }
  wait(1);
   }
  PlaySE(seshot1);
   wait(0);
       }
   wait(10);
   if(d == 0){wait(90); Move; wait(60);}
         }
   wait(0);
      }
    }

 task Normal{
   let delay = 5;
  let color = 68;
  loop{
  let base = GetAngleToPlayer;
 sgrnum = 3;
     ascent(d in 0..2){
 let r = 16;
  ascent(b in 0..30){
   ascent(a in 0..1){
     ascent(c in 0..10){
  let v = 2.3-0.05*c;
 let angle = base+(240-12*b)*(-1)^d;
   let x = GetX+offsetX(r,angle);
   let y = GetY+offsetY(r,angle);
  CreateShotA(0,x,y,delay);
  SetShotDataA(0,0,v,angle,-1.5*(-1)^(d),0,v,color+2*d);
  SetShotDataA(0,90,NULL,NULL,-0.2*(-1)^(d),0,v,color+2*d);
  SetShotDataA(0,300,NULL,NULL,0,0,v,color+2*d);
  FireShot(0);
      }
  wait(1);
   }
  PlaySE(seshot1);
   wait(0);
       }
   if(d == 0){wait(90); Move; wait(60);}
         }
   wait(0);
      }
    }

   task Hard{
 let delay = 5;
  let color = 68;
  loop{
  let base = GetAngleToPlayer;
 sgrnum = 3;
     ascent(d in 0..2){
 let r = 16;
  ascent(b in 0..24){
   ascent(a in 0..2){
     ascent(c in 0..10){
  let v = 2.5-0.05*c-0.5*a;
 let angle = base+(240-15*b-7.5*a)*(-1)^d;
   let x = GetX+offsetX(r,angle);
   let y = GetY+offsetY(r,angle);
  CreateShotA(0,x,y,delay);
  SetShotDataA(0,0,v,angle,(-1.5-0.25*a)*(-1)^(d),0,v,color+2*d);
  SetShotDataA(0,90,NULL,NULL,(-0.2-0.1*a)*(-1)^(d),0,v,color+2*d);
  SetShotDataA(0,300,NULL,NULL,0,0,v,color+2*d);
  FireShot(0);
      }
   }
 wait(1);
  PlaySE(seshot1);
   wait(0);
       }
   if(d == 0){wait(90); Move; wait(60);}
         }
   wait(0);
      }
    }

  task Lunatic{
 let delay = 5;
  let color = 68;
  loop{
  let base = GetAngleToPlayer;
 sgrnum = 3;
     ascent(d in 0..2){
 let r = 16;
  ascent(b in 0..30){
   ascent(a in 0..3){
     ascent(c in 0..10){
  let v = 2.7-0.05*c-0.5*a;
 let angle = base+(240-12*b-6*a)*(-1)^d;
   let x = GetX+offsetX(r,angle);
   let y = GetY+offsetY(r,angle);
    if(a <= 1){
  CreateShotA(0,x,y,delay);
  SetShotDataA(0,0,v,angle,(-1.5-0.25*a)*(-1)^(d),0,v,color+2*d);
  SetShotDataA(0,90,NULL,NULL,(-0.2-0.1*a)*(-1)^(d),0,v,color+2*d);
  SetShotDataA(0,300,NULL,NULL,0,0,v,color+2*d);
  FireShot(0);
         }
   else if(a == 2){
    SetShotColor(255,200,224);
   CreateShot01(x,y,4-0.075*c,base+(240-12*b)*(-1)^d,color+3,delay);
  SetShotColor(255,255,255);
          }
      }
   }
 wait(1);
  PlaySE(seshot1);
       }
   if(d == 0){wait(90); Move; wait(60);}
         }
      }
    }

    task Move{
   let f = 1.5;
  let r = rand_int(0,1);
 if(GetX < minx+100){r = 0;}
 else if(GetX > maxx-100){r = 1;}
 else if(GetX < GetPlayerX){r = 0;}
 else if(GetX > GetPlayerX){r = 1;}
    let x = GetX + rand(30,90)*(-1)^r;
    let y = GetY + rand(-32,32);
    if(y < miny+48){y = miny+48;}
    else if(y > miny+130){y = miny+130;}
   if(GetX > x){sgrnum = 1;}
   else if(GetX < x){sgrnum = 2;}  
    SetMovePosition03(x,y,15,f);
     wait(90);
    sgrnum = 0;
    }

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