
#Title[魔理沙通常弾幕3]
#Text[魔理沙通常弾幕3]
#Player[FREE]
#ScriptVersion[2]

script_enemy_main{
    #include_script".\function_bullet.txt"
     let csd = GetCurrentScriptDirectory;
        let gx = GetX;
        let gy = GetY;
        let gspeed = GetSpeed;
        let gangle = GetAngle;     
        let arg = GetArgument;
   let imgBOSS = csd~"img\character\dot_marisa.png";
   let wIni  = 60;
   let csd = GetCurrentScriptDirectory;
   let shotData = csd ~ "data_usershot.txt";
   let se1 = csd~ "bgm\goro03.wav";
   let se2 = csd~ "bgm\tm2_gun002.wav";
   let se3 = csd~ "bgm\bell01.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");
   @Initialize{
           if(GetPlayerType == REIMU_A){SetLife(2000);}
            else{SetLife(2000);}
           SetTimer(60);
       SetDamageRate(100,20);
           SetInvincibility(120);
           SetGraphicRect(0*128,0,1*128,128);   
           SetMovePosition03(GetCenterX,GetClipMinY+130,20,20);
        SetAlpha(255);
           LoadGraphic(imgBOSS);
          LoadGraphic(effect);
          LoadUserShotData(shotData);
         LoadSE(se1);LoadSE(se2);LoadSE(se3);LoadSE(se4);
           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);           
     }
 
     task TMain{
          yield;
      Circle(40);
       wait(120);
    SetGraphicRect(4*128,2*128,5*128,3*128); 
        if(dif == 1){Shot;}
     else if(dif == 2){ShotD;}
        Count;
    /*    Move; */
    }

      task Shot{
    /*   Shot1; */
       task Shot1{
        loop{
      let v = rand(1,3);
        let x = rand(GetClipMinX+32,GetClipMaxX-32);
        let y = rand(GetCenterY-64,GetClipMinY+32);
        let color = rand_int(161,168); let angle = rand(60,120);
       let size = rand(70,70);
        Star(x,y,v,angle,color,size);
      PlaySE(se1);
       wait(15);
       }
     }

      Shot2;
     task Shot2{
     loop{
       Concentration01(90);
       wait(90);
     loop(2){
       ascent(a in 0..5){
       let x = GetX; let y = GetY;
       let v = 6; let size = 30;
      let color = rand_int(161,161);
        let angle = GetAngleToPlayer+45*(a-2);
        Star(x,y,v,angle,color,size);
      loop(30){
          CreateShot01(x,y,rand(0.1,5),angle+rand(-10,10),color-8,0);
            }
         }
       PlaySE(se2);
       wait(60);
        }
     wait(30);
      Move(3);
      Concentration01(90);
       wait(90);
       ascent(a in 0..5){
       let x = GetX; let y = GetY;
       let v = 6; let size = 30;
      let color = rand_int(161,161);
        let angle = GetAngleToPlayer+5*(a-2);
        Star(x,y,v,angle,color,size);
      loop(30){
          CreateShot01(x,y,rand(0.1,5),angle+rand(-10,10),color-8,0);
            }
         }
       PlaySE(se2);
     wait(30);
      Move(3);
      Concentration01(90);
       wait(90);
      loop(2){
       ascent(a in 0..5){
       let x = GetX; let y = GetY;
       let v = 6; let size = 30;
      let color = rand_int(161,161);
        let angle = GetAngleToPlayer+45*(a-2);
        Star(x,y,v,angle,color,size);
      loop(30){
          CreateShot01(x,y,rand(0.1,5),angle+rand(-10,10),color-8,0);
            }
         }
       PlaySE(se2);
       wait(30);
        }
      wait(30);
      Move(3);
      wait(60);
         }
      }
    }

  task ShotD{
   let n = 20;
     loop{
      Concentration01(90);
       wait(90);
 let base = GetAngleToPlayer;
   loop(7){
    let x = GetX; let y = GetY;
     let v = 6; let angle = base;
     let color = 161;  let size = 30;
      Star(x,y,v,angle,color,size);
        loop(n){
         CreateShot01(x,y,rand(1,5),angle+rand(-10,10),color-8*rand_int(0,1),28);
         }
    PlaySE(se2);
       wait(4);
        }
   Move(1.5);
     ascent(a in 0..16){
     let x = GetX; let y = GetY;
     let v = 6; let angle = base+24*a;
     let color = 161;  let size = 30;
      Star(x,y,v,angle,color,size);
        loop(n){
         CreateShot01(x,y,rand(1,5),angle+rand(-30,30),color-8*rand_int(0,1),0);
         }
   if(a > 7 && a < 13){base = GetAngleToPlayer;}
    PlaySE(se2);
       wait(4);
        }
     wait(60);
   base = GetAngleToPlayer;
  loop(3){
    let x = GetX; let y = GetY;
     let v = 6; let angle = base;
     let color = 161;  let size = 30;
      Star(x,y,v,angle,color,size);
        loop(n){
         CreateShot01(x,y,rand(1,5),angle+rand(-10,10),color-8*rand_int(0,1),28);
         }
    PlaySE(se2);
       wait(4);
        }
    Move(1.5);
     ascent(a in 0..16){
     let x = GetX; let y = GetY;
     let v = 6; let angle = base-24*a;
     let color = 161;  let size = 30;
      Star(x,y,v,angle,color,size);
        loop(n){
         CreateShot01(x,y,rand(1,5),angle+rand(-30,30),color-8*rand_int(0,1),0);
         }
   if(a > 7 && a < 13){base = GetAngleToPlayer;}
    PlaySE(se2);
       wait(4);
        }
   wait(60);
      }
     }

     task Move(v){
        let x = rand(96,96);
        let y = rand(0,32);
      /*  let v = 3;*/
        let xmin = GetClipMinX+64;
        let ymin = GetClipMinY+100;
        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(30);
    }
       
      task Count{
        loop{
          if(GetTimer <= 10){PlaySE(se4);}
         wait(60);
        }
    }
     
   task Star(x,y,v,angle,color,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);
            }
 /*    let base = rand(-180,180);
    ascent(a in 0..24){
      CreateShot01(x,y,v,base+15*a,color-8,0);
        } */
      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){
           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);
           }
        } 
  /*  Small; */
     task Small{
      while(!Obj_BeDeleted(c)){
                       if(size > 10){
                             size = size - 0.25*v;
                             ObjEffect_SetScale(c,size/10,size/10);
                           }
                  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);
           }
        }
    }

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