
#Title[AXʏe3]
#Text[AXʏe3]
#Player[FREE]
#ScriptVersion[2]

script_enemy_main{
     let csd = GetCurrentScriptDirectory;
        let gx = GetX;
        let gy = GetY;
        let gspeed = GetSpeed;
        let gangle = GetAngle;     
        let arg = GetArgument;
   let imgBOSS = csd~"img\character\dot_alice.png";
   let wIni  = 60;
   let csd = GetCurrentScriptDirectory;
   let shotData = csd ~ "data_usershot.txt";
   let se1 = csd~ "bgm\buble03.wav";
   let se2 = csd~ "bgm\eco02_a.wav";
   let se3 = csd~ "bgm\concentration.wav";
   let se4 = csd~ "bgm\countdown.wav";
    let effect = csd ~ "img\magic_circle\powercircle.png";
   let arrayL = [];
 let dif = GetCommonData("Dif");
   @Initialize{
           if(GetPlayerType == REIMU_A){SetLife(4000);}
            else{SetLife(4000);}
           SetTimer(60);
       SetDamageRate(100,20);
           SetInvincibility(120);
           SetGraphicRect(0*128,0,1*128,128);   
           SetMovePosition03(GetCenterX,GetClipMinY+100,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);
        Shot;
     /*  Move; */
        Count;
    }

      task Shot{
        if(dif == 1){Bullet;  Bullet2; Shot;}
     else if(dif == 2){Bullet4; Shot2;}
       task Bullet{
      let base = 0;
     loop{
        ascent(a in 0..12){
         let x = GetX+offsetX(64,base+30*a);
         let y = GetY+offsetY(64,base+30*a);
         let v = 5;let angle = GetAngleToPlayer;
         let color = rand_int(105,112);
         let delay = 10;
         CreateShot01(x,y,v,angle,color,delay);
        wait(6);
         }
         }
       }
   task Bullet3{
      let base = 0;
     loop{
        ascent(a in 0..20){
         let x = GetX+offsetX(64,base-18*a);
         let y = GetY+offsetY(64,base-18*a);
         let v = 5;let angle = GetAngleToPlayer;
         let color = rand_int(105,112);
         let delay = 10;
         CreateShot01(x,y,v,angle,color,delay);
        wait(6);
         }
         }
       }
       task Bullet2{
     loop{
   let base = GetAngleToPlayer;
        ascent(a in 0..2){
         let x = GetX+offsetX(48,base+180*a-90);
         let y = GetY+offsetY(48,base+180*a-90);
         let v = 5;let angle = GetAngleToPlayer;
         let color = rand_int(105,112);
         let delay = 10;
         CreateShot01(x,y,v,angle,color,delay);
        wait(1);
         }
         }
       }
    task Bullet4{
   let radius = 64;
  let base = 90;
     loop{
        ascent(a in 0..2){
         let x = GetX+offsetX(radius,base+180*a-90);
         let y = GetY;
         let v = 5;let angle = 90;
         let color = rand_int(105,112);
         let delay = 10;
         CreateShot01(x+100,y,v,angle,color,delay);  
         CreateShot01(x-100,y,v,angle,color,delay);
         }
      base += 3;
     wait(1);
         }
       }
        task Shot{
        wait(180);
         loop{
          let x = GetX; let y = GetY;
          let v = 2; let angle = GetAngleToPlayer;
          let color = rand_int(49,56); let delay = 10;
   /* if(dif == 2){v = 4;}*/
         CreateShot01(x,y,v,angle,color,delay);
         Move;
         PlaySE(se1);
         wait(60);
       if(GetLife >= 1000 && GetTimer >= 15){wait(60);}
       if(GetLife >= 2000 && GetTimer >= 30){wait(60);}
       if(GetLife >= 3000 && GetTimer >= 45){wait(60);}
           }
          }
      task Shot2{
        wait(90);
         loop{
          let x = GetX; let y = GetY;
          let color = rand_int(49,56); let delay = 10;
     ascent(a in 0..3){
   let v = 2*a+1;
        ascent(b in 0..3){
    let angle = GetAngleToPlayer+20*(b-1);
         CreateShot01(x,y,v,angle,color,delay);
        }
       }
         Move;
         PlaySE(se1);
         wait(60);
       if(GetLife >= 1000 && GetTimer >= 15){ Move; wait(60);}
       if(GetLife >= 2000 && GetTimer >= 30){Move; wait(60);}
       if(GetLife >= 3000 && GetTimer >= 45){Move; wait(60);}
           }
          }
    }

     task Move{
        let x = rand(32,32);
        let y = rand(16,32);
        let v = 2;
        let xmin = GetClipMinX+128;
        let ymin = GetClipMinY+60;
        let xmax = GetClipMaxX-128;
        let ymax = GetCenterY-60;
        if(x>=GetX){SetGraphicRect(1*128,1*128,2*128,2*128);}
       else if(x<=GetX){SetGraphicRect(1*128,1*128,2*128,2*128);}
         SetMovePositionRandom01(x,y,v,xmin,ymin,xmax,ymax);
         wait(90);
         SetGraphicRect(0*128,0,1*128,128); 
         wait(90);
    }
       
      task Count{
        loop{
          if(GetTimer <= 10){PlaySE(se4);}
         wait(60);
        }
    }
     
   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;}
       }
}