
#Title[쀬뼯믅륂뭙뼀4]
#Text[쀬뼯믅륂뭙뼀4]
#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_reimu.png";
   let wIni  = 60;
   let csd = GetCurrentScriptDirectory;
   let shotData = csd ~ "data_usershot.txt";
   let se1 = csd~ "bgm\tm2_shoot003.wav";
   let se2 = csd~ "bgm\tm2_coin000.wav";
   let se3 = csd~ "bgm\bell01.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(3000);}
            else{SetLife(3000);}
           SetTimer(60);
       SetDamageRate(100,1);
           SetInvincibility(120);
           SetGraphicRect(0*128,0,1*128,128);   
           SetMovePosition03(GetCenterX,GetClipMinY+120,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;
      L(GetClipMinX,GetClipMinY,0,600,1,WHITE01);
      L(GetClipMaxX,GetClipMinY,90,600,1,WHITE01);
      L(GetClipMinX,GetClipMinY,90,600,1,WHITE01);
      Circle(40);
     Collision(120);
       wait(120);
    SetGraphicRect(4*128,2*128,5*128,3*128); 
        if(dif == 1){Shot;}
     else if(dif == 2){Shot2;}
        Count;
    }

      task Shot{
   loop{
       Concentration01(120);
       Collision(150);
        pray(1,15);
    loop(30){
       let x = GetX; let y = GetY; let v = 5;
       let angle = GetAngleToPlayer+rand(-60,60);
       let color = 243;
        let delay = 0;
       CreateShot01(x,y,v,angle,color,delay);
        wait(1);
        }
     SetGraphicRect(0*128,0*128,0*128,0*128);
      loop(10){
        loop(18){
       let x = GetX; let y = GetY; let v = rand(0.5,2);
       let angle = rand(-180,180);
       let accel = rand(0.01,0.03);
       let grvAngle = 90;
       let color = 40;
        let delay = 0;
       GravityShot(x,y,v,angle,accel,grvAngle,color,delay);
       PlaySE(se3);
        wait(1);
           }
        Move;
        }
     Collision(210);
        SetGraphicRect(0*128,0*128,1*128,1*128);
        wait(60);
         Concentration01(120);
        pray(1,15);
    loop(30){
       let x = GetX; let y = GetY; let v = 5;
       let angle = GetAngleToPlayer+rand(-60,60);
       let color = 244;
        let delay = 0;
       CreateShot01(x,y,v,angle,color,delay);
        wait(1);
        }
     SetGraphicRect(0*128,0*128,0*128,0*128);
     let angle = GetAngleToPlayer;
     loop(180){
       ascent(a in 0..8){
       let v = 10-a;
       let accel = -v/40;
       let color = 33;
       let x = GetX+offsetX(24,angle);
       let y = GetY+offsetY(24,angle);
       let delay = 30;
       CreateShotA(0,x,y,delay); 
      SetShotDataA(0,0,v,angle,0,accel,0,color);
      SetShotDataA(0,120,NULL,NULL,0,1,10,color);
         FireShot(0);
          }
      PlaySE(se3);
         angle += rand(120,240);
        wait(1);
        }
     Collision(240);
       SetGraphicRect(0*128,0*128,1*128,1*128);
        wait(60);
         Concentration01(120);
        pray(1,15);
         loop(60){
       let x = GetX; let y = GetY; let v = 5;
       let angle = GetAngleToPlayer+rand(-60,60);
       let color = rand_int(243,244);
        let delay = 0;
       CreateShot01(x,y,v,angle,color,delay);
        wait(1);
        }
     SetGraphicRect(0*128,0*128,0*128,0*128);
       wait(60);
    loop(3){
     ascent(a in 0..6){
        let angle2 = GetAngleToPlayer + 60*a;
        let x = GetX; let y = GetY;
        let v = 5; let color = 245.5+0.5*(-1)^a;
        let delay = 0;
        P(x,y,v,angle2,color,delay);
          }
      ascent(a in 0..30){
        let angle2 = rand(-180,180);
        let x = GetX; let y = GetY;
        let v = rand(0.5,4); let color = 243.5+0.5*(-1)^a;
        let delay = 0;
        P(x,y,v,angle2,color,delay);
         }
   Move;
       PlaySE(se3);
        wait(60);
         }
   Collision(120);
     SetGraphicRect(0*128,0*128,1*128,1*128);
      wait(120);
        }
    }

   task Shot2{
   loop{
       Concentration01(120);
       Collision(150);
        pray(1,15);
    loop(30){
     loop(3){
       let x = GetX; let y = GetY; let v = 6;
       let angle = GetAngleToPlayer+rand(-90,90);
       let color = 243;
        let delay = 0;
       CreateShot01(x,y,v,angle,color,delay);
     }
        wait(1);
        }
     SetGraphicRect(0*128,0*128,0*128,0*128);
      loop(10){
        loop(18){
      loop(2){
       let x = GetX; let y = GetY; let v = rand(0.5,4);
       let angle = rand(-180,180);
       let accel = rand(0.01,0.06);
       let grvAngle = 90;
       let color = 40;
        let delay = 0;
       GravityShot(x,y,v,angle,accel,grvAngle,color,delay);
     }
       PlaySE(se3);
        wait(1);
           }
        Move;
        }
     Collision(210);
        SetGraphicRect(0*128,0*128,1*128,1*128);
        wait(60);
         Concentration01(120);
        pray(1,15);
    loop(30){
    loop(3){
       let x = GetX; let y = GetY; let v = 6;
       let angle = GetAngleToPlayer+rand(-90,90);
       let color = 244;
        let delay = 0;
       CreateShot01(x,y,v,angle,color,delay);
    }
        wait(1);
        }
     SetGraphicRect(0*128,0*128,0*128,0*128);
     let angle = GetAngleToPlayer;
     loop(180){
    loop(2){
       ascent(a in 0..8){
       let v = 10-a;
       let accel = -v/40;
       let color = 33;
       let x = GetX+offsetX(24,angle);
       let y = GetY+offsetY(24,angle);
       let delay = 30;
       CreateShotA(0,x,y,delay); 
      SetShotDataA(0,0,v,angle,0,accel,0,color);
      SetShotDataA(0,120,NULL,NULL,0,1,10,color);
         FireShot(0);
          }
   angle += rand(120,240);
     }
      PlaySE(se3);
        wait(1);
        }
     Collision(240);
       SetGraphicRect(0*128,0*128,1*128,1*128);
        wait(60);
         Concentration01(120);
        pray(1,15);
         loop(60){
      loop(3){
       let x = GetX; let y = GetY; let v = 6;
       let angle = GetAngleToPlayer+rand(-90,90);
       let color = rand_int(243,244);
        let delay = 0;
       CreateShot01(x,y,v,angle,color,delay);
     }
        wait(1);
        }
     SetGraphicRect(0*128,0*128,0*128,0*128);
       wait(60);
    loop(3){
     ascent(a in 0..8){
        let angle2 = GetAngleToPlayer + 45*a;
        let x = GetX; let y = GetY;
        let v = 7; let color = 245.5+0.5*(-1)^a;
        let delay = 0;
        P(x,y,v,angle2,color,delay);
          }
      ascent(a in 0..60){
        let angle2 = rand(-180,180);
        let x = GetX; let y = GetY;
        let v = rand(0.5,5); let color = 243.5+0.5*(-1)^a;
        let delay = 0;
        P(x,y,v,angle2,color,delay);
         }
    Move;
       PlaySE(se3);
        wait(60);
         }
   Collision(120);
     SetGraphicRect(0*128,0*128,1*128,1*128);
      wait(120);
        }
    }

     task Move{
        let x = rand(64,128);
        let y = rand(0,16);
        let v = 100;
        let xmin = GetClipMinX+64;
        let ymin = GetClipMinY+60;
        let xmax = GetClipMaxX-64;
        let ymax = GetCenterY-60;
         SetMovePositionRandom01(x,y,v,xmin,ymin,xmax,ymax);
    }
       
     task P(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);
         ObjShot_SetBombResist(p,false);
         Obj_SetCollisionToObject(p,true);
         Obj_SetCollisionToPlayer(p,true);
         Obj_SetAutoDelete(p,true);

         while(!Obj_BeDeleted(p)){
           let i = 0;
             loop(length(arrayL)){
             if(Collision_Obj_Obj(p,arrayL[i])){
        CreateShot01(Obj_GetX(p),Obj_GetY(p),Obj_GetSpeed(p),2*Obj_GetAngle(arrayL[i])-Obj_GetAngle(p),color,0);    
             Obj_Delete(p); 
        wait(1);  
             break;
             }
         i++;
         if(i == 3){i = 0;}
         }
        wait(1);
        }
      }

   task L(x,y,angle,length,width,color){
              let l = Obj_Create(OBJ_LASER);
              arrayL = arrayL ~ [l];
              Obj_SetX(l,x);
              Obj_SetY(l,y);
              Obj_SetAngle(l,angle);
              Obj_SetAutoDelete(l,false);
              ObjShot_SetGraphic(l,color);
              Obj_SetCollisionToObject(l,true);
              Obj_SetCollisionToPlayer(l,false);
              ObjLaser_SetLength(l,length);
              ObjLaser_SetWidth(l,width);
              ObjLaser_SetSource(l,false);
     }

      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 pray(m ,n){
    loop(m){
       SetGraphicRect(6*128,0*128,7*128,1*128); 
       wait(n);
       SetGraphicRect(7*128,0*128,8*128,1*128); 
       wait(n);
       SetGraphicRect(6*128,1*128,7*128,2*128); 
       wait(n);
       SetGraphicRect(7*128,1*128,8*128,2*128); 
       wait(n);
       SetGraphicRect(6*128,2*128,7*128,3*128); 
       wait(n);
       SetGraphicRect(7*128,2*128,8*128,3*128); 
        wait(n);
       SetGraphicRect(6*128,3*128,7*128,4*128); 
       wait(n);
       SetGraphicRect(7*128,3*128,8*128,4*128); 
       wait(n);
       }
     }

    task Collision(w){
     loop(w){
       SetCollisionA(GetX, GetY, 24);
        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);
            }
}