
#Title[魔理沙スペル1]
#Text[魔理沙スペル1]
#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 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 arrayL = [];
 let dif = GetCommonData("Dif");
  if(dif == 2){name    = "魔砲　「恋色マスタースパーク」";
       shotData = csd ~ "heart_bullet.txt";}
   @Initialize{
       CutIn(KOUMA, name, "", 0, 0, 0, 0);
           if(GetPlayerType == REIMU_A){SetLife(1000);}
            else{SetLife(1000);}
           SetTimer(90);
     SetScore(15000000);
       SetDamageRate(30,5);
           SetInvincibility(120);
           SetGraphicRect(0*128,0,1*128,128);   
           SetMovePosition03(GetCenterX,GetClipMinY+60,20,5);
        SetAlpha(255);
      MagicCircle(false);
           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);  
       if(!IsTimeOut){
                loop(125){
              CreateItem(ITEM_SCORE,GetX+offsetX(rand(0,64),rand(-180,180)),GetY+offsetY(rand(0,64),rand(-180,180)));
              }
           }         
     }
 
     task TMain{
          yield;
      Circle(40);
       wait(120);
    SetGraphicRect(0*128,2*128,1*128,3*128); 
        if(dif == 1){Shot; }
     else if(dif == 2){Shot2;}
        Count;
    }

      task Shot{
        Sparkb;
      task Sparkb{
         let length = 480;
         let width = 10;
         let color = 247;
          let delay = 90;
      loop{
       let x = GetX; let y = GetY;
       let angle = GetAngleToPlayer;
      L(x,y,angle,length,width,color,delay);
       PlaySE(se2);
      Spark(60,255,255,255,true);
         wait(delay);
        loop(12){
        let x = GetX; let y = GetY;
        let v = 3; let color = rand_int(153,156);
        let delay = 20;
           ascent(a in 0..13){
            let angle = GetAngleToPlayer+10*(a-6);
            CreateShot01(x,y,v,angle,color,delay);
             }
         PlaySE(se1);
           wait(10);
           ascent(a in 0..14){
            let angle = GetAngleToPlayer+10*(a-6)-5;
            CreateShot01(x,y,v,angle,color+4,delay);
             }
         PlaySE(se1);
            wait(10);
          } 
       Move;
      wait(180);
        
        let x = GetX; let y = GetY;
       let angle = GetAngleToPlayer;
      L(x,y,angle,length,width,color,delay);
       PlaySE(se2);
      Spark(60,255,255,255,true);
         wait(delay);
        loop(12){
        let x = GetX; let y = GetY;
        let v = 6; let color = rand_int(153,156);
        let delay = 20;
           ascent(a in 0..13){
            let angle = GetAngleToPlayer+10*(a-6);
            CreateShot01(x,y,v,angle,color,delay);
             }
         PlaySE(se1);
           wait(10);
           ascent(a in 0..19){
            let angle = GetAngleToPlayer+7*(a-9);
            CreateShot01(x,y,v,angle,color+4,delay);
             }
         PlaySE(se1);
            wait(10);
          } 
       Move;
      wait(180);
         }
       } 
    }

  task Shot2{
        Sparkb;
      task Sparkb{
         let length = 800;
         let width = 10;
         let color = PURPLE11;
          let delay = 90;
    let way = 12;
   let n = 5;
      loop{
       let x = GetX; let y = GetY;
       let angle = GetAngleToPlayer;
      L2(x,y,angle,length,width,color,delay);
       PlaySE(se2);
      Spark(60,255,255,255,true);
         wait(delay);
   let base1 = GetAngleToPlayer;
   let base2 = GetAngleToPlayer;
        loop(120){
       ascent(a in 0..way*2){
           let radius = 8;
          let angle = 90+360/way/2*a;
          let v = 4*2.5;
          let x = GetX+offsetX(radius,angle);
          let y = GetY+offsetY(radius,angle);
         let color = 6;
          let delay = 30;
         let accel = 0;
         CreateShotA(0,x,y,delay); 
         SetShotDataA(0,0,v,angle,0.8*2.5,accel,v,color);
         FireShot(0);
          }
    ascent(a in 0..way*2){
           let radius = 0;
          let angle = base2+360/way/2*a;
          let v = 4*2.5;
          let x = GetX+offsetX(radius,angle);
          let y = GetY+offsetY(radius,angle);
         let color = 6;
          let delay = 30;
         let accel = 0;
         CreateShotA(0,x,y,delay); 
         SetShotDataA(0,0,v,angle,-0.8*2.5,accel,v,color);
         FireShot(0);
          }
         PlaySE(se1);
            wait(1);
          } 
   loop(24){
       ascent(a in 0..way){
           let radius = 8;
          let angle = base1+360/way*a;
          let v = 4;
          let x = GetX+offsetX(radius,angle);
          let y = GetY+offsetY(radius,angle);
         let color = 6;
          let delay = 10;
         let accel = 0;
         CreateShotA(0,x,y,delay); 
         SetShotDataA(0,0,v,angle,0.8,accel,v,color);
         FireShot(0);
          }
    ascent(a in 0..way){
           let radius = 0;
          let angle = base2+360/way*a;
          let v = 4;
          let x = GetX+offsetX(radius,angle);
          let y = GetY+offsetY(radius,angle);
         let color = 6;
          let delay = 10;
         let accel = 0;
         CreateShotA(0,x,y,delay); 
         SetShotDataA(0,0,v,angle,-0.8,accel,v,color);
         FireShot(0);
          }
         PlaySE(se1);
       base1 -= n;
       base2 += n;
            wait(10);
          } 
       Move;
      wait(180);
         }
       } 
    }

    task L(x,y,angle,length,width,color,delay){
              let l = Obj_Create(OBJ_LASER);
              arrayL = arrayL ~ [l];
              Obj_SetX(l,x);
              Obj_SetY(l,y);
              Obj_SetAngle(l,angle);
              ObjShot_SetGraphic(l,color);
              ObjShot_SetDelay(l,delay);
              Obj_SetCollisionToObject(l,true);
              Obj_SetCollisionToPlayer(l,true);
              ObjLaser_SetLength(l,0); 
              ObjLaser_SetWidth(l,width);
              ObjLaser_SetSource(l,true);
       /* wait(delay);*/
      while(ObjLaser_GetLength(l) < length){
          ObjLaser_SetLength(l,ObjLaser_GetLength(l)+length/delay);
          wait(1);
         }
       Star;
      PlaySE(se3);
        while(ObjLaser_GetWidth(l) <= 610){
              ObjLaser_SetWidth(l,ObjLaser_GetWidth(l)+3);
        /*  PlaySE(se3);  */
              wait(1);
              }
       wait(60);
          ObjShot_FadeDelete(l);
          task Star{
       while(!Obj_BeDeleted(l)){
        loop(12){
            let x = Obj_GetX(l);
            let y = Obj_GetY(l);
            let v = rand(0.1,4);
            let angle = Obj_GetAngle(l)+rand(-270,-90);
            let color = rand_int(153,168);
             let delay = 10;
         CreateShotA(0,x,y,delay); 
         SetShotDataA(0,0,v,angle,0,0,v,color);
         SetShotDataA(0,rand(30,180),v,NULL,rand(-1,1),0,v*2,color);
         SetShotDataA(0,240,1,NULL,0,0,v*2,color);
         FireShot(0);
         }
         wait(5);
           }
          }
        }

    task L2(x,y,angle,length,width,color,delay){
              let l = Obj_Create(OBJ_LASER);
              arrayL = arrayL ~ [l];
              Obj_SetX(l,x);
              Obj_SetY(l,y);
              Obj_SetAngle(l,angle);
              ObjShot_SetGraphic(l,color);
              ObjShot_SetDelay(l,delay);
              Obj_SetCollisionToObject(l,true);
              Obj_SetCollisionToPlayer(l,true);
              ObjLaser_SetLength(l,0); 
              ObjLaser_SetWidth(l,width);
              ObjLaser_SetSource(l,true);
       /* wait(delay);*/
      while(ObjLaser_GetLength(l) < length){
          ObjLaser_SetLength(l,ObjLaser_GetLength(l)+length/delay);
          wait(1);
         }
       Heart;
      PlaySE(se3);
   ObjLaser_SetWidth(l,610);
        while(ObjLaser_GetWidth(l) <= 610){
              ObjLaser_SetWidth(l,ObjLaser_GetWidth(l)+3);
        /*  PlaySE(se3);  */
              wait(1);
              }
       wait(360);
          ObjShot_FadeDelete(l);
          task Heart{
       while(!Obj_BeDeleted(l)){
        loop(12){
            let x = Obj_GetX(l);
            let y = Obj_GetY(l);
            let v = rand(0.1,10);
            let angle = Obj_GetAngle(l)+rand(60,300);
            let color = rand_int(5,8);
             let delay = 10;
         CreateShotA(0,x,y,delay); 
         SetShotDataA(0,0,v,angle,0,0,v,color);
         FireShot(0);
         }
         wait(5);
           }
          }
        }

     task Move{
        let x = rand(92,128);
        let y = rand(0,32);
        let v = 2;
        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 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;}
       }

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