
#Title[アリススペル3]
#Text[アリススペル3]
#Player[FREE]
#ScriptVersion[2]

script_enemy_main{
    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_alice.png";
   let wIni  = 60;
   let csd = GetCurrentScriptDirectory;
   let shotData = csd ~ "data_usershot.txt";
   let se1 = csd~ "bgm\gun10.wav";
   let se2 = csd~ "bgm\eco02_a.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");
  if(dif == 2){name   = "試作品　「ゴリアテ人形 -Lunatic-」";}
   @Initialize{
    /*   CutIn(KOUMA, name, "", 0, 0, 0, 0);  */
           if(GetPlayerType == REIMU_A){SetLife(1);}
            else{SetLife(1);}
  /*         SetTimer(65);
     SetScore(12000000);   */
       SetDamageRate(0,0);
      SetDurableSpellCard;
           SetInvincibility(120);
           SetGraphicRect(0*128,0,1*128,128);   
     /*      SetMovePosition03(GetCenterX,GetClipMinY+120,20,5);
        SetAlpha(128); */
      MagicCircle(false);
           LoadGraphic(imgBOSS);
          LoadGraphic(effect);
          LoadUserShotData(shotData);
         LoadSE(se1);LoadSE(se2);LoadSE(se3);LoadSE(se4);
     SetEffectForZeroLife(60,64,1);
           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);  
                loop(250){
              CreateItem(ITEM_SCORE,GetX+2*offsetX(rand(0,64),rand(-180,180)),GetY+offsetY(rand(0,64),rand(-180,180)));     
         } 
    if(GetMissCountInThisSpell == 0){
       loop(3){
              CreateItem(ITEM_BOMB,GetX+offsetX(rand(0,64),rand(-180,180)),GetY+offsetY(rand(0,64),rand(-180,180)));
              }
         }  
      else if(GetMissCountInThisSpell != 0){
        CreateItem(ITEM_1UP,GetX,GetY);  
         } 
     }
 
     task TMain{
          yield;
      Circle(40);
       wait(120);
 CutIn(KOUMA, name, "", 0, 0, 0, 0);
  SetTimer(65);
     SetScore(12000000);
   PlaySE("seUseSpellCard.wav");
  SetMovePosition03(GetCenterX,GetClipMinY+120,20,5);
        SetAlpha(128);
     SetDamageRate(0,0);
  wait(120);
    SetGraphicRect(0*128,2*128,1*128,3*128);  
     Enemy;
        Count;
      wait(180);
   SetAlpha(0);
    Move;
      if(dif == 1){Shot; }
   else if(dif == 2){Shot2;}
    }

      task Shot{ 
      let way = 17;
   loop{
     if(GetTimer>41){
       let xy = rand(-16,16);
       let color = 14; let delay = 20;
     ascent(b in 0..4){
       ascent(a in 0..way){
        let v = 1.5;
       let x =xy+(GetClipMaxX-GetClipMinX)/8*a-10*b; 
       let y = GetClipMinY;
        let angle = 90;
        CreateShot01(x,y,v,angle,color,delay);
         }
       PlaySE(se1);
        wait(10);
         }
      }
    else if(GetTimer<=41 && GetTimer>=39){DeleteEnemyShot(SHOT);}
      else if(GetTimer>21 && GetTimer<39){
       let xy = rand(-16,16);
       let color = 12; let delay = 20;
     ascent(b in 0..4){
       ascent(a in 0..way){
        let v = 1;
       let x =xy+(GetClipMaxX-GetClipMinX)/8*a-5*b+50; 
       let y = GetClipMaxY;
        let angle = -90;
        CreateShot01(x,y,v,angle,color,delay);
       let x2 = GetClipMaxX;
       let y2 = xy+(GetClipMaxY-GetClipMinY)/8*a+5*b+50; 
       CreateShot01(x2,y2,v,angle-90,color,delay);
         }
       PlaySE(se1);
        wait(10);
         }
      }
   else if(GetTimer<=21 && GetTimer>=19){DeleteEnemyShot(SHOT);}
     else if(GetTimer < 19){
    loop{
      let v = 1; let delay = 20;
        let x = GetClipMinX;
        let y = rand(GetClipMinY,GetClipMaxY);
        let color = 10; let angle = 0;
     /*   CreateShot01(x,y,v,angle,color,delay); */
       x = GetClipMaxX;
       color = 11; let angle = 180;
   /*     CreateShot01(x,y,v,angle,color,delay); */
       x = rand(GetClipMinX,GetClipMaxX);
       y = GetClipMinY;
        color = 13;  angle = 90;
       P(x,y,v,angle,color,delay);
       y = GetClipMaxY;
         color = 15; angle = -90;
       P(x,y,v,angle,color,delay); 
       wait(1*(GetTimer+1));
       PlaySE(se1);
       }
       }
        wait(30);
     }
  }

  task Shot2{ 
      let way = 8;
   loop{
     if(GetTimer>=40.5){
       let xy = rand(-24,24);
       let color = 14; let delay = 20;
     ascent(b in 0..4){
       ascent(a in 0..way){
        let v = 1;
       let x =xy+(GetClipMaxX-GetClipMinX)/5*a-10*b; 
       let y = GetClipMinY;
        let angle = 90;
        CreateShot01(x,y,v,angle,color,delay);
      angle = -90;
     y = GetClipMaxY;
      CreateShot01(x,y,v,angle,color,delay);
         }
       PlaySE(se1);
        wait(0);
         }
    wait(30);
      }
    else if(GetTimer<=40.5 && GetTimer>=39.5){DeleteEnemyShot(SHOT);}
      else if(GetTimer>=20.5 && GetTimer<=39.5){
       let xy = rand(-24,24);
       let color = 12; let delay = 20;
     ascent(b in 0..6){
       ascent(a in 0..way){
        let v = 1;
       let x = GetClipMinX;
       let y = xy+(GetClipMaxY-GetClipMinY)/5*a-10*b+50; 
        let angle = 0;
        CreateShot01(x,y,v,angle,color,delay);
       let x2 = GetClipMaxX;
       let y2 = xy+(GetClipMaxY-GetClipMinY)/5*a+10*b+50; 
       CreateShot01(x2,y2,v,angle+180,color,delay);
         }
         }
   PlaySE(se1);
     wait(30);
      }
   else if(GetTimer<=20.5 && GetTimer>=19.5){DeleteEnemyShot(SHOT);}
     else if(GetTimer <= 19.5){
    loop{
      let v = 1; let delay = 20;
        let x = GetClipMinX;
        let y = rand(GetClipMinY,GetClipMaxY);
        let color = 10; let angle = 0;
        P(x,y,v,angle,color,delay);
       x = GetClipMaxX;
       color = 11; let angle = 180;
       P(x,y,v,angle,color,delay);
       x = rand(GetClipMinX,GetClipMaxX);
       y = GetClipMinY;
        color = 13;  angle = 90;
       P(x,y,v,angle,color,delay);
       y = GetClipMaxY;
         color = 15; angle = -90;
       P(x,y,v,angle,color,delay); 
       wait(GetTimer+1);
       PlaySE(se1);
       }
       }
        wait(30);
     }
  }

    task Enemy{
      let x = GetX; let y = GetY;
      let v = 0; 
         enemy(csd~"Alice_doll03.txt",x,y,v,GetAngleToPlayer,194);
      /* PlaySE(se3);*/
        }

     task Move{
     /*   let x = rand(92,92);
        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(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,2*128,1*128,3*128); 
         wait(90); */
     loop{
       SetX(GetPlayerX); SetY(GetPlayerY);
        wait(1);
      }
    }
       
      task Count{
        loop{
          if(GetTimer <= 10){PlaySE(se4);}
         wait(60);
        }
    }
     
  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);
         Obj_SetAutoDelete(p,true);
         ObjShot_SetBombResist(p,true);
         Obj_SetCollisionToObject(p,true);
         Obj_SetCollisionToPlayer(p,true);
   }

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