
#Title[「悪魔　夢月」]
#Text[夢月・スペル10]
#Player[FREE]
#ScriptVersion[2]

script_enemy_main{
    #include_script".\Local.txt"
   let name        = " 「悪魔　夢月」";
   let imgBOSS = csd~"img\dot_mugetu.png";
   let shotData = csd ~ "data_usershot.txt";
  let effect = csd ~ "img\circle.png"; 

   @Initialize{
  SetShotAutoDeleteClip(64,64,64,64);
  /* CutIn(KOUMA, name, "", 0, 0, 0, 0);
     SetScore(3750000);  
   SetInvincibility(120);
    SetTimer(150); */
           SetLife(2000);
      SetDamageRate(100,0);
          
         sgr(0,0);
    SetX(cx);
   SetY(miny+80);
        SetAlpha(255);
           LoadGraphic(imgBOSS);
    LoadGraphic(effect);
          LoadUserShotData(shotData);
    Circle2(60);
           TMain;
   SetEffectForZeroLife(75,0,0); 
    }

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

         yield;
       }

   @DrawLoop{
   if(OnBomb){SetAlpha(0);}
   else if(!OnBomb){SetAlpha(255);}
         SetTexture(imgBOSS);  
        DrawGraphic(GetX,GetY);
     }

    @Finalize{
  SetCommonDataEx("","bg",3);
  PlaySE(sevanish);
        DeleteGraphic(imgBOSS);
        DeleteGraphic(effect);
 if(!IsTimeOut){
  loop(666){
     CreateItem(ITEM_SCORE,rand(minx,maxx),miny+rand(16,224)); 
       }   
     }
     }
 
     task TMain{
     wait(60);  
  SetCommonDataEx("","bg",4);
  SetDamageRate(20,0);
  CutIn(KOUMA, name, "", 0, 0, 0, 0);
     SetScore(3750000);  
   SetInvincibility(120);
    SetTimer(154);
  PlaySE("seUseSpellCard.wav");
  wait(90);
   con(60);
        Shot;
        Count;
    }

   task Shot{
 let v = 1.25;
  let way = 90;
  let color = 174;
  let delay = 10;
 let w = 300;
  let base = rand(-180,180);
    ascent(a in 0..way){
  let angle = base + 360/way*a;
  Ref(GetX,GetY,v,angle,color,delay);
       }
  PlaySE(seshot1);
  wait(w);
  loop{
  let base = rand(-180,180);
   let x = rand(minx+30,maxx-30);
  let y = miny+rand(16,160);
  ascent(a in 0..way){
  let angle = base + 360/way*a;
  Ref(x,y,v,angle,color,delay);
       }
   PlaySE(seshot1);
 let ss = 0;
 loop{
  if(GetLife >= 1500 && GetTimer > 30){v = 1.25; w = 300;}
  else if(GetLife >= 1000 && GetTimer > 30){v = 1.6; w = 225;} 
  else if(GetLife >= 500 && GetTimer > 30){v = 1.9; w = 150;} 
  else if(GetLife >= 0 || GetTimer <= 30){v = 2.25; w = 75;} 
   wait(1);
  ss++;
  if(ss >= w){break;}
       }
     }
    }

    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);
  let re = 0;  let ree = 0;
     while(!Obj_BeDeleted(p)){
    let basex = Obj_GetX(p);
   wait(1);
 if(Obj_GetX(p) < minx-20){Obj_SetX(p,maxx+20); re += 1;}
 else if(Obj_GetX(p) > maxx+20){Obj_SetX(p,minx-20); re += 1;}
 if(Obj_GetY(p) < miny){Obj_SetAngle(p,-Obj_GetAngle(p));}
  if(re >= 2 || ree >= 2){Obj_Delete(p);}
      }
   }

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

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