
#Title[魔理沙スペル5]
#Text[魔理沙スペル5]
#Player[FREE]
#ScriptVersion[2]

script_enemy_main{
     #include_script".\function_effect.txt"
    let name        = "天星　「ミルキーウェイ」";
     let csd = GetCurrentScriptDirectory;
        let gx = GetX;
        let gy = GetY;
        let gspeed = GetSpeed;
        let gangle = GetAngle;     
        let arg = GetArgument;
  let cx = GetCenterX;   let cy = GetCenterY;
   let imgBOSS = csd~"img\character\dot_marisa.png";
   let wIni  = 60;
   let csd = GetCurrentScriptDirectory;
   let shotData = csd ~ "data_usershot.txt";
   let se1 = csd~ "bgm\bell01.wav";
   let se2 = csd~ "bgm\eco00.wav";
   let se3 = csd~ "bgm\bomb1.wav";
   let se4 = csd~ "bgm\countdown.wav";
    let effect = csd ~ "img\magic_circle\powercircle.png";
    let star = csd ~ "shot_all.png";
   let arrayL = [];
 let dif = GetCommonData("Dif");
    if(dif == 2){name    = "新星　「スーパーノヴァ」";}
   @Initialize{
    /*   CutIn(KOUMA, name, "", 0, 0, 0, 0); */
           if(GetPlayerType == REIMU_A){SetLife(2000);}
            else{SetLife(2000);}
        /*   SetTimer(90);
     SetScore(2000000);   */
       SetDamageRate(100,0);
        if(GetPlayerType == MARISA_B){
           SetDamageRate(100,0);
         }
       /*    SetInvincibility(120); */
           SetGraphicRect(0*128,0,1*128,128);   
      /*     SetMovePosition03(GetCenterX,GetClipMinY+180,20,5); */
        SetAlpha(255);
      MagicCircle(false);
           LoadGraphic(imgBOSS);
          LoadGraphic(effect);
          LoadUserShotData(shotData);
         LoadSE(se1);LoadSE(se2);LoadSE(se3);LoadSE(se4);
       SetEffectForZeroLife(60,244,3);
           TMain;
    }

   @MainLoop{
           SetCollisionA(GetX, GetY, 24);
           SetCollisionB(GetX, GetY, 24);

         yield;
       }

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

    @Finalize{
        DeleteGraphic(imgBOSS);
        DeleteGraphic(effect);
        DeleteSE(se1);DeleteSE(se2);DeleteSE(se3);DeleteSE(se4);  
       if(!IsTimeOut){
                loop(500){
              CreateItem(ITEM_SCORE,GetCenterX+offsetX(rand(0,200),rand(-180,180)),GetY+offsetY(rand(0,64),rand(-180,180)));
              }
           }         
     }
 
     task TMain{
          yield;
      Circle(40);
     B;
       wait(90);
     CutIn(KOUMA, name, "", 0, 0, 0, 0);
    SetTimer(180); 
     SetScore(100000000);
   PlaySE("seUseSpellCard.wav");
  SetMovePosition03(GetCenterX,GetClipMinY+100,20,5);
     SetDamageRate(10,0);
   wait(120);
    SetGraphicRect(0*128,2*128,1*128,3*128); 
        if(dif == 1){Shot; }
     else if(dif == 2){Shot2;}
        Count;
      /*  Move; */
    }


      task Shot{
  let ln = 36;
 light(ln,180);
function light(way,n){
   let base = GetAngleToPlayer-180;
   let length = 450;  
   let width = 10; let kill = 240;
    let delay = 270;
   ascent(a in 0..way){
   let color = 9;
    let angle = base+360/way*a;
     CreateLaserB(0,length,width,color,delay);
     SetLaserDataB(0,0,0,200,-0.8,base,(angle-base)/240,base,(angle-base)/240);
     SetLaserDataB(0,240,0,NULL,0,NULL,0,NULL,0);
     SetShotKillTime(0,delay+kill);
     FireShot(0);
        }
    ascent(a in 0..way){
  let color = 14;
    let angle = base-360/way*a-180/way;
      CreateLaserB(0,length,width,color,delay);
     SetLaserDataB(0,0,0,200,-0.8,base,(angle-base)/240,base,(angle-base)/240);
     SetLaserDataB(0,240,0,NULL,0,NULL,0,NULL,0);
     SetShotKillTime(0,delay+kill);
     FireShot(0);
        }
   wait(270); PlaySE(se3);
   wait(230);
   loop(n){
     CreateShot02(cx+rand(-200,200),cy+rand(-200,200),
          0,rand(-180,180),1/60,1.5,rand_int(153,160),10);
          }
      DeleteEnemyShotInCircle(ALL,GetPlayerX,GetPlayerY,30);
     wait(120);
     }


  let way = 1; let span = 150;
  let la = 12; let w = 240; let num = 120;
  let mm = 12;
   loop{
  function crazy{
   if(GetLife <= 1750 || GetTimer <= 150){w = 210; mm = 16;}
      if(GetLife <= 1400|| GetTimer <= 120){mm = 20; num = 180; la = 16;}
      if(GetLife <= 1000|| GetTimer <= 90){w = 180; way = 3; mm = 24;}
      if(GetLife <= 750|| GetTimer <= 60){mm = 28; num = 240; la = 20;}
     if(GetLife <= 400 || GetTimer <= 35){w = 150; mm = 32; la = 24;}
     if(GetTimer <= 10){mm = 36; num = 300; la = 36;}
    }

  crazy;
     Move(1.5);
     wait(60);
     Spark(120,255,255,255,true);
     PlaySE(se2);
     wait(120);
  crazy;
 SetGraphicRect(5*128,2*128,6*128,3*128);   
     Shot1(way,span);
    Shot2(way,span);
    wait(180);
 crazy;
   Move(0.5);
    Shot3(mm); 
    wait(w);
  crazy;
    light(la,num);

    Move(1.5);
     wait(60);
     Spark(120,255,255,255,true);
     PlaySE(se2);
     wait(120);
  crazy;
 SetGraphicRect(5*128,2*128,6*128,3*128);
   Shot1(way,span/15);
    Shot2(way,span/15);
    wait(180);
 crazy;
   Move(0.5);
    Shot3(mm); 
    wait(w);
  crazy;
    light(la,num);
   }

     task Shot1(way,span){
   let x = GetX; let y = GetY;
  let delay = 30; let size = 30;
    ascent(b in 0..18){
     let v = 0.2+0.3*b;
     ascent(a in 0..way){
      let color = rand_int(161,168);
      let angle = GetAngleToPlayer+span/way*(a-(way-1)/2);
      Star(x,y,v,angle,color,delay,size);
         }
      PlaySE(se1);
       wait(4);
           }
       }
   task Shot2(way,span){
   let x = GetX; let y = GetY;
  let delay = 30; 
    loop(72){
     let v = rand(0.1,6);
     ascent(a in 0..way){
      let color = rand_int(161,168);
      let angle = GetAngleToPlayer+span/way*(a-(way-1)/2)+rand(-10,10);
      CreateShot01(x,y,v,angle,color,delay);
         }
       wait(1);
           }
       }
  task Shot3(way){
  let delay = 30; 
    loop(10){
    let x = GetX; let y = GetY;
     let v = 3;
      let color = rand_int(161,168);
      let angle = GetAngleToPlayer;
      CreateShot01(x,y,v,angle,color,delay);
       loop(way){
          CreateShot01(x,y,v,angle+rand(3,60)*(-1)^rand_int(0,1),color-8,delay);
            }
   PlaySE(se1);
       wait(30);
           }
       }
   }



task Shot2{
  let ln = 100;
 light(ln,300);
function light(way,n){
   let base = GetAngleToPlayer-180;
   let length = 450;  
   let width = 10; let kill = 240;
    let delay = 270;
   ascent(a in 0..way){
   let color = 11;
    let angle = base+360/way*a;
     CreateLaserB(0,length,width,color,delay);
     SetLaserDataB(0,0,0,200,-0.8,base,(angle-base)/240,base,(angle-base)/240);
     SetLaserDataB(0,240,0,NULL,0,NULL,0,NULL,0);
     SetShotKillTime(0,delay+kill);
     FireShot(0);
        }
    ascent(a in 0..way){
  let color = 10;
    let angle = base-360/way*a-180/way;
      CreateLaserB(0,length,width,color,delay);
     SetLaserDataB(0,0,0,200,-0.8,base,(angle-base)/240,base,(angle-base)/240);
     SetLaserDataB(0,240,0,NULL,0,NULL,0,NULL,0);
     SetShotKillTime(0,delay+kill);
     FireShot(0);
        }
   wait(270); PlaySE(se3);
   wait(230);
   loop(n){
     CreateShot02(cx+rand(-200,200),cy+rand(-200,200),
          0,rand(-180,180),1/60,rand(1,3),rand_int(153,160),10);
          }
      DeleteEnemyShotInCircle(ALL,GetPlayerX,GetPlayerY,30);
     wait(120);
     }


  let way = 3; let span = 150;
  let la = 36; let w = 240; let num = 200;
  let mm = 20;
   loop{
  function crazy{
   if(GetLife <= 1750 || GetTimer <= 150){w = 210; mm = 30;}
     if(GetLife <= 1400|| GetTimer <= 120){mm = 40; num = 250; la = 54; way = 4;}
      if(GetLife <= 1000|| GetTimer <= 90){w = 180;  mm = 45;}
      if(GetLife <= 750|| GetTimer <= 60){mm = 50; num = 300; la = 63; way = 5; span = 180;}
     if(GetLife <= 400 || GetTimer <= 35){w = 150; mm = 60; la = 72;}
     if(GetTimer <= 10){mm = 100; num = 400; la = 90;} 
    }

  crazy;
     Move(1.5);
     wait(60);
     Spark(120,255,255,255,true);
     PlaySE(se2);
     wait(120);
  crazy;
 SetGraphicRect(5*128,2*128,6*128,3*128);   
     Shot1(way,span);
    Shot2(way,span);
    wait(180);
 crazy;
   Move(0.5);
    Shot3(mm); 
    wait(w);
  crazy;
    light(la,num);

    Move(1.5);
     wait(60);
     Spark(120,255,255,255,true);
     PlaySE(se2);
     wait(120);
  crazy;
 SetGraphicRect(5*128,2*128,6*128,3*128);
   Shot1(way,span/15);
    Shot2(way,span/15);
    wait(180);
 crazy;
   Move(0.5);
    Shot3(mm); 
    wait(w);
  crazy;
    light(la,num);
   }

     task Shot1(way,span){
   let x = GetX; let y = GetY;
  let delay = 30; let size = 30;
    ascent(b in 0..18){
     let v = 0.2+0.3*b;
     ascent(a in 0..way){
      let color = rand_int(161,168);
      let angle = GetAngleToPlayer+span/way*(a-(way-1)/2);
      Star(x,y,v,angle,color,delay,size);
         }
      PlaySE(se1);
       wait(4);
           }
       }
   task Shot2(way,span){
   let x = GetX; let y = GetY;
  let delay = 30; 
    loop(72){
     let v = rand(0.1,6);
     ascent(a in 0..way){
      let color = rand_int(161,168);
      let angle = GetAngleToPlayer+span/way*(a-(way-1)/2)+rand(-15,15);
      CreateShot01(x,y,v,angle,color,delay);
         }
       wait(1);
           }
       }
  task Shot3(way){
  let delay = 30; 
    loop(10){
    let x = GetX; let y = GetY;
     let v = 3;
      let color = rand_int(161,168);
      let angle = GetAngleToPlayer;
      CreateShot01(x,y,v,angle,color,delay);
       loop(way){
          CreateShot01(x,y,v,angle+rand(3,60)*(-1)^rand_int(0,1),color-8,delay);
            }
   PlaySE(se1);
       wait(30);
           }
       }
   }


     task Move(v){
        let x = rand(64,96);
        let y = rand(0,32);
       /* let v = 1.5;*/
        let xmin = GetClipMinX+64;
        let ymin = GetClipMinY+60;
        let xmax = GetClipMaxX-64;
        let ymax = GetCenterY-60;
        if(x>=GetX){SetGraphicRect(2*128,3*128,3*128,4*128);}
       else if(x<=GetX){SetGraphicRect(2*128,1*128,3*128,2*128);}
         SetMovePositionRandom01(x,y,v,xmin,ymin,xmax,ymax);
         wait(90);
         SetGraphicRect(0*128,2*128,1*128,3*128); 
         wait(90);
    }
       
      task Count{
        loop{
          if(GetTimer <= 10){PlaySE(se4);}
         wait(60);
        }
    }

   task Star(x,y,v,angle,color,delay,size){
           let c= Obj_Create(OBJ_EFFECT);
             Obj_SetX(c,x);
             Obj_SetY(c,y);
             Obj_SetSpeed(c,v);
             Obj_SetAngle(c,angle);
             ObjEffect_SetAngle(c,0,0,0);
             ObjEffect_SetTexture(c,star);
             ObjEffect_SetRenderState(c,ALPHA);
             ObjEffect_SetPrimitiveType(c,PRIMITIVE_TRIANGLEFAN);
             ObjEffect_SetLayer(c,3);
             ObjEffect_CreateVertex(c,62);
             ObjEffect_SetVertexXY(c,0,0,0);
             ObjEffect_SetVertexUV(c,0,16+32*(color-161),354);
        /*     ObjEffect_SetVertexColor(c,0,255,255,255,255);  */
             ObjEffect_SetScale(c,size/10,size/10);
  if(color == 161){ObjEffect_SetVertexColor(c,0,255,255,0,0);}
  if(color == 162){ObjEffect_SetVertexColor(c,0,255,255,128,0);}
  if(color == 163){ObjEffect_SetVertexColor(c,0,255,255,255,0);}
  if(color == 164){ObjEffect_SetVertexColor(c,0,255,0,255,0);}
  if(color == 165){ObjEffect_SetVertexColor(c,0,255,128,128,255);}
  if(color == 166){ObjEffect_SetVertexColor(c,0,255,0,0,255);}
  if(color == 167){ObjEffect_SetVertexColor(c,0,255,255,0,255);}
  if(color == 168){ObjEffect_SetVertexColor(c,0,255,128,128,128);}
       ascent(let i in 0..61){
                ObjEffect_SetVertexXY(c,i+1,cos(i*6)*20,sin(i*6)*20);
                ObjEffect_SetVertexUV(c,i+1,cos(i*6)*16+16+32*(color-161),sin(i*6)*16+354);
            /*    ObjEffect_SetVertexColor(c,i+1,255,255,255,255); */
            }
      Spin;
       task Spin{
      let h = 0;
         while(!Obj_BeDeleted(c)){
          /*  Obj_SetX(c,GetX); Obj_SetY(c,GetY);*/
            ObjEffect_SetAngle(c,0,0,h);
            h += 4;
            wait(1);
           }
         }
      Damage;
       task Damage{
           while(!Obj_BeDeleted(c)){
                 Obj_SetY(c,Obj_GetY(c));
                 if((GetPlayerX-Obj_GetX(c))^2+(GetPlayerY-Obj_GetY(c))^2<(size+10)^2/2&&GetTimeOfPlayerInvincibility==0){
                 ShootDownPlayer();
                  }
                   wait(1);
                }
            }
       Delete;
        task Delete{
          while(!Obj_BeDeleted(c)){
             if(OnBomb){
            wait(30);
              CreateItem(ITEM_SCORE,Obj_GetX(c),Obj_GetY(c));
              Obj_Delete(c);
              }
           if(OnPlayerMissed){
            wait(30);
           Obj_Delete(c);
             }
         if(Obj_GetX(c)>GetClipMaxX+2*size || Obj_GetX(c)<GetClipMinX-2*size || Obj_GetY(c)>GetClipMaxY+2*size || Obj_GetY(c)<GetClipMinY-2*size){
           Obj_Delete(c);
             }
         wait(1);
           }
        }
      Graze;
      task Graze{
         while(!Obj_BeDeleted(c)){
                 if((GetPlayerX-Obj_GetX(c))^2+(GetPlayerY-Obj_GetY(c))^2<(size+50)^2/2&&GetTimeOfPlayerInvincibility==0){
                 AddGraze(1); PlaySE("seGraze.wav");
                 wait(3600);
                  }
                   wait(1);
                }
            }
    }

   task Circle(size){
           let c= Obj_Create(OBJ_EFFECT);
             Obj_SetX(c,GetX);
             Obj_SetY(c,GetY);
             Obj_SetAngle(c,0);
             ObjEffect_SetAngle(c,0,0,0);
             ObjEffect_SetTexture(c,effect);
             ObjEffect_SetRenderState(c,ADD);
             ObjEffect_SetPrimitiveType(c,PRIMITIVE_TRIANGLEFAN);
             ObjEffect_SetLayer(c,0);
             ObjEffect_CreateVertex(c,62);
             ObjEffect_SetVertexXY(c,0,0,0);
             ObjEffect_SetVertexUV(c,0,128,128);
             ObjEffect_SetVertexColor(c,0,255,255,255,255);
             ObjEffect_SetScale(c,size/10,size/10);

            ascent(let i in 0..61){
                ObjEffect_SetVertexXY(c,i+1,cos(i*6)*20,sin(i*6)*20);
                ObjEffect_SetVertexUV(c,i+1,cos(i*6)*130+130,sin(i*6)*130+130);
                ObjEffect_SetVertexColor(c,i+1,255,255,255,255);
            }
       Spin;
       Up;
     task Spin{
      let h = 0;
         loop{
            Obj_SetX(c,GetX); Obj_SetY(c,GetY);
            ObjEffect_SetAngle(c,0,0,h);
            h += 8;
            wait(1);
           }
         }
       task Up{
            loop{
             ascent(a in 0..30){
            Obj_SetX(c,GetX); Obj_SetY(c,GetY);
            ObjEffect_SetScale(c,(size+a/5)/10,(size+a/5)/10);
            wait(1);
             }
            wait(10);
             descent(a in 0..30){
            Obj_SetX(c,GetX); Obj_SetY(c,GetY);
            ObjEffect_SetScale(c,(size+a/5)/10,(size+a/5)/10);
            wait(1);
             }
            wait(10);
           }
        }
    }

  task B{
     let frame = 10;
     let pattern = 6;
     let radius = 64;
     let accAngle = 6;
     let blur = 6;
     let graphic = 14;
      loop{
     BombBarrier(frame,pattern,radius,accAngle,blur,graphic );
        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);
     }

       sub setGraphicStop  { SetGraphicRect( 1, 1, 64, 64); }

       function wait(w){
                loop(w){yield;}
       }

     function enemy(text,x,y,speed,angle,arg){
               CreateEnemyFromFile(text,x,y,speed,angle,arg);
            }
}