
#Title[Eʏe11]
#Text[Eʏe11]
#Player[FREE]
#ScriptVersion[2]

script_enemy_main{
    #include_script".\Local.txt"
   let imgBOSS = csd~"img\dot_mugetu.png";
   let shotData = csd ~ "data_usershot.txt";
  let effect = csd ~ "img\circle.png";

   @Initialize{
 SetCommonDataEx("","bg",8);
           SetLife(5000);
      SetDamageRate(100,0);
     /*      SetTimer(30);  */
           SetInvincibility(120);
         sgr(0,0);
/*SetMovePosition03(GetCenterX,GetClipMinY+120,20,10);*/
        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{
        DeleteGraphic(imgBOSS);
        DeleteGraphic(effect);
     }
 
     task TMain{
  yield;
  loop(3){Explosion01(cx,cy,0,10,10);}
  SetX(cx); SetY(miny+100);
 CreateEventFromScript("Talk");
  while(OnEvent){ wait(1);}
  SetTimer(75);
   SetInvincibility(120);
          wait(90);
        Shot;
    loop{
   if(OnBomb){SetAlpha(0); SetDamageRate(0,0);}
     else{SetAlpha(255); SetDamageRate(100,0);}
    wait(1);
      }
    }

   task Shot{
     Shot1;
  let prefer = 1;
  loop{
  let t = rand_int(1,4);
  while(t != 2 && t == prefer){t = rand_int(1,4);}
    alternative(t)
  case(1){Shot1;}
  case(2){Shot2;}
  case(3){Shot3;}
  case(4){Shot4;}
 prefer = t;
     }
    function Shot1{
 Concentration01(30);
  wait(30);
 sgr(5,1);
  let color = 8;
  let delay = 0;
    let way = 20;
    let base = rand(-180,180);
      ascent(a in 0..way){
   let v = 2.5+0.2*a;
    ascent(b in 0..8){
      let angle = base+45*b+5*a;
      let x = GetX;
      let y = GetY;
      CreateShot01(x,y,v,angle,color,delay);
      }
      PlaySE(seshot1);
       wait(4);
         }
   wait(30);
   Move;
       }
    function Shot2{
 Concentration01(30);
  wait(30);
 sgr(5,1);
  let color = 38;
  let delay = 30;
    let way = 36;
    let v = 3;
    let accel = -0.1;
    let base = GetAngleToPlayer;
      ascent(a in 0..way){
      let angle = base+10*a;
      let x = GetX;
      let y = GetY;
    let vmin = rand(0.65,0.75);
      CreateShot02(x,y,v,angle,accel,vmin,color,delay);
      }
      PlaySE(seshot3);
   wait(30);
   Move;
       }
    function Shot3{
  Concentration01(30);
  wait(30);
 ShotA;
  wait(10);
 sgr(5,1);
  let color = 174;
  let delay = 0;
    let way = 36;
    let accel = -0.1;
    let base = GetAngleToPlayer;
   ascent(c in 0..8){
      ascent(a in 0..8){
      ascent(b in 0..2){
    ascent(d in 0..2){
      let angle = base+(-70+10*c)*(-1)^b;
      let x = GetX+offsetX(4,angle-90+180*d)+7*(-1)^b;
      let y = GetY+offsetY(4,angle-90+180*d);
    let v = 2.3+0.7*a;
      CreateShot01(x,y,v,angle,color,delay);
      }
     }
    }
      PlaySE(seshot1);
   wait(8);
   }
   wait(30);
   Move;
       }
 function Shot4{
  Concentration01(30);
  wait(30);
 sgr(5,1);
  let color = YELLOW01;
  let delay = 20;
    let accel = -0.1;
    let base = GetAngleToPlayer;
  loop(60){
   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,angle,color,delay);
   PlaySE(seshot4);
   wait(1);
   }
   wait(30);
   Move;
       }
    }

  function ShotA{
    let way = 72;
   let delay = 20;
  let accel = -0.1;
  let color = 155;
    ascent(a in 0..way){
    let angle =  GetAngleToPlayer+360/way*a;
   let v = 4;
    let x = GetX;
      let y = GetY;
    CreateShotA(0,x,y,delay); 
    SetShotDataA(0,0,v,angle,0,accel,0,color);
    SetShotDataA(0,v*10+20,v,angle+90*(-1)^a,0,accel,0,color);
    SetShotDataA(0,v*20+30,4,angle+90*(-1)^a,0,0,0,color);
     FireShot(0);
          }
      PlaySE(seshot4);
       }

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

   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(20);
    Obj_SetSpeed(p,v);
   Obj_SetAngle(p,90);
   }

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

script_event Talk{
    @Initialize{
  }
    @MainLoop{
  if(GetPlayerType == REIMU_A || GetPlayerType == REIMU_B){
    TextOutA("\c[RED]炠AȂƂ܂łǂāEEE");
    TextOutA("\c[BLUE]񂽂̌ėɌ܂Ă邶Ȃ");
     TextOutA("\c[RED]E͂ǂ̂");
    TextOutA("\c[BLUE]Ȃ̌EȂČȂ");
  TextOutA("\c[RED]Ӂ`EEE\n\n
AǂȂɕH");
    TextOutA("\c[BLUE]mȂAȂ");
     TextOutA("\c[RED]Ă܂傤");
   TextOutA("\c[BLUE]Ƃ");
     TextOutA("\c[RED]EEEcO\n\n
y̓yYɂƎv񂾂");
   TextOutA("\c[BLUE]EEEςCȂ킯H");
         }

   else if(GetPlayerType == MARISA_A || GetPlayerType == MARISA_B){
  TextOutA("\c[RED]炠AȂƂ܂łǂāEEE");
    TextOutA("\c[BLUE]ǂė񂾂");
     TextOutA("\c[RED]Xg[J[śׂAƍ߂");
    TextOutA("\c[BLUE]NOuvH\n\n
́uǂāv񂾂\n\n
Xg[J[sׂł͂Ȃ");
  TextOutA("\c[RED]Ӂ`EEE\n\n
AǂȂɕH");
    TextOutA("\c[BLUE]");
     TextOutA("\c[RED]Ă܂傤");
   TextOutA("\c[BLUE]CÂ͖p");
     TextOutA("\c[RED]EEEcO\n\n
y̓yYɂƎv񂾂");
   TextOutA("\c[BLUE]ɖʔȂÂ");
         }  
       End;
      }
   @Finalize{
      }
    }