
#Title[再戦クワガタ]
#Text[]
#ScriptVersion[2]


script_enemy_main {
  let imgBoss = "script\ザコ\zako3.PNG";
  let frame   = 0;
  let xIni    = GetCenterX;
  let yIni    = GetClipMaxY - 300;
 let Q=1;
 let scoa=0;
@Initialize {

    SetLife(300);
           
    SetDamageRate(0, 0);
           SetEffectForZeroLife(0,0,0);
    LoadGraphic(imgBoss);
   SetTexture(imgBoss);   SetGraphicRect(0, 0, 64, 64);

    TMain;

   }
@MainLoop {
 
    SetCollisionA(GetX, GetY, 24);
    SetCollisionB(GetX, GetY, 24);
   yield;

}
@DrawLoop{
    DrawGraphic(GetX, GetY);
   }

@Finalize {
if(scoa==0){
AddScore(500+500*GetPlayerLife);scoa=1;}
    DeleteGraphic(imgBoss);}

function moveToPlayer(xMove, yAdd, frame, left, top, right, bottom) {
     let x;
     let y;

     if(GetPlayerX < GetX) {
         x = GetX - xMove;
         if(x < left) {
             x = GetX + xMove;
     }
     } else {
         x = GetX + xMove;
         if(right < x) {
             x = GetX - xMove;
         }
     }
     y = GetY + yAdd;
     if(y < top) {
         y = top;
     } else if(bottom > y) {
         y = bottom;
     }

     SetMovePosition02(x, y, frame);



}

 task TMain {
        yield;
      standBy;

    loop{
                 Q=rand_int(1,3);

if(Q==1){NORMALSHOT; }
if(Q==2){BUME1;}
if(Q==3){BUME2;}
if(Q==7){NORMALSHOT; wait(60); }

}
      }


    sub standBy{
            let wIni =60;
        SetMovePosition02(xIni, yIni, 30);
    SetInvincibility(wIni);
   wait(wIni);  
 CutIn(KOUMA, "", "script\ロククロ\warn.png", 64, 0, 432, 462);
 PlaySE("\koukaonn\warp3.wav");
  wait(120); 
SetText("");
 SetDamageRate(10, 10);

             }

  sub move{
   

       
       moveToPlayer(rand(100, 180), rand(-30, 20), 10,
                     GetClipMinX + 60, GetClipMinY + 32,
                     GetClipMaxX - 60, GetClipMinY + 60);
   wait(20);
          
       }
    function wait(w) {
        loop(w) { yield; }
                    }
  task shot {
 let angle   = 90;
  let angle2   = 90;
loop(10){
loop(4){CreateShot02(GetX,GetY,4,angle,0,0,ORANGE01,30);
CreateShot02(GetX,GetY,0,angle+45,0.2,7,ORANGE02,30);
angle=angle+90;}   
wait(10);
loop(4){CreateShot02(GetX,GetY,4,angle+45,0,0,WHITE01,30);
CreateShot02(GetX,GetY,0,angle,0.2,7,WHITE02,30);
angle=angle+90;}   
wait(10);}
   }
  task shot2 {
 let angle   = 90;
  let angle2   = 90;

loop(10){
loop(4){CreateShot02(GetX,GetY,4,angle,0,0,BLUE02,30);
CreateShot02(GetX,GetY,0,angle+45,0.2,7,BLUE03,30);
angle=angle+90;}   
wait(10);
loop(4){CreateShot02(GetX,GetY,4,angle+45,0,0,GREEN02,30);
CreateShot02(GetX,GetY,0,angle,0.2,7,GREEN03,30);
angle=angle+90;}   
wait(10);}
   }
sub NORMALSHOT{
 if(GetLife>400){shot;}else{shot;}
loop(9){
if(GetX<GetCenterX){
SetMovePosition02(GetCenterX+rand(100,200),yIni+rand(-100,40),20);
wait(25);}
else{
SetMovePosition02(GetCenterX+rand(-100,-200),yIni+rand(-100,40),20);
wait(25);}}
wait(120);


}

sub BUME1{
    task setGraphicPose  {loop(10){ SetGraphicRect( 64,  0, 128,  128);yield;} 
                         loop(5){ SetGraphicRect( 128,  0, 192,  128);yield;}
                         loop(20){ SetGraphicRect( 192,  0, 256,  128);yield;}}

wait(15);
CreateEnemyFromFile(GetCurrentScriptDirectory~"カッター.txt",GetX,GetY,0,0,0);
if(GetLife>500){wait(70);

wait(15);
}
CreateEnemyFromFile(GetCurrentScriptDirectory~"カッター2.txt",GetX,GetY,0,0,0);
wait(180);
move;

}
sub BUME2{
    task setGraphicPose  {loop(10){ SetGraphicRect( 64,  0, 128,  128);yield;} 
                         loop(5){ SetGraphicRect( 128,  0, 192,  128);yield;}
                          
                         loop(20){ SetGraphicRect( 192,  0, 256,  128);yield;}}

wait(15);
CreateEnemyFromFile(GetCurrentScriptDirectory~"カッター2.txt",GetX,GetY,0,0,0);
if(GetLife>500){wait(70);
 
wait(15);
}
CreateEnemyFromFile(GetCurrentScriptDirectory~"カッター.txt",GetX,GetY,0,0,0);
wait(180);
move;

}
sub DEADLIFT{
let X=GetPlayerX;
    task setGraphicPose  {
loop(20){ SetGraphicRect( 192,  0, 256,  128);yield;}
loop(5){ SetGraphicRect( 128,  0, 192,  128);yield;}
loop(30){ SetGraphicRect( 64,  0, 128,  128);yield;} 
                         loop(5){ SetGraphicRect( 128,  0, 192,  128);yield;}
                         loop(20){ SetGraphicRect( 192,  0, 256,  128);yield;}}
if(GetPlayerY<GetCenterY){

wait(50);
SetMovePosition02(X,GetClipMinY+60,0);
wait(5);
CreateEnemyFromFile(GetCurrentScriptDirectory~"カッター3.txt",GetX,GetY,0,0,0);
wait(120);

}
else{

wait(50);
SetMovePosition02(X,GetClipMaxY-60,0);
wait(5);
CreateEnemyFromFile(GetCurrentScriptDirectory~"カッター4.txt",GetX,GetY,0,0,0);
wait(120);
SetMovePosition02(GetX,GetClipMinY+60,0);
wait(5);
}

}
sub DEADLIFT2{
let X=GetPlayerX;
    task setGraphicPose  {
loop(20){ SetGraphicRect( 192,  0, 256,  128);yield;}
loop(5){ SetGraphicRect( 128,  0, 192,  128);yield;}
loop(30){ SetGraphicRect( 64,  0, 128,  128);yield;} 
                         loop(5){ SetGraphicRect( 128,  0, 192,  128);yield;}
                         loop(20){ SetGraphicRect( 192,  0, 256,  128);yield;}}
    task setGraphicPose2  {
loop(10){ SetGraphicRect( 64,  0, 128,  128);yield;} 
    loop(5){ SetGraphicRect( 128,  0, 192,  128);yield;}
   loop(20){ SetGraphicRect( 192,  0, 256,  128);yield;}}

if(GetPlayerY<GetCenterY){

wait(50);
SetMovePosition02(X,GetClipMinY+60,0);
wait(5);
CreateEnemyFromFile(GetCurrentScriptDirectory~"カッター3.txt",GetX,GetY,0,0,0);
wait(60);
X=GetPlayerX;
SetMovePosition02(X,GetClipMaxY-60,0);

wait(15);
CreateEnemyFromFile(GetCurrentScriptDirectory~"カッター4.txt",GetX,GetY,0,0,0);
wait(120);
SetMovePosition02(GetX,GetClipMinY+60,0);
wait(5);

}
else{

wait(50);
SetMovePosition02(X,GetClipMaxY-60,0);
wait(5);
CreateEnemyFromFile(GetCurrentScriptDirectory~"カッター4.txt",GetX,GetY,0,0,0);
wait(60);
X=GetPlayerX;
SetMovePosition02(X,GetClipMinY+60,0);

wait(15);
CreateEnemyFromFile(GetCurrentScriptDirectory~"カッター3.txt",GetX,GetY,0,0,0);
wait(120);

}

}



    sub setGraphicStop  { SetGraphicRect(  0,   0,  64,  128); }

    sub setGraphicRight  { SetGraphicRect( 0,  128, 128,  256); }
    sub setGraphicLeft { SetGraphicRect( 128,  128, 256,  256); }

    task setGraphicMove {
     loop{yield;
        if(GetSpeedX < 0) {
            setGraphicLeft;
        } if(GetSpeedX > 0){
            setGraphicRight;
        } if(GetSpeed == 0){
          setGraphicStop;}
         }
    }

}}