
#Title[メットールエース２]
#Text[]
#ScriptVersion[2]


script_enemy_main {
  let imgBoss = "script\ザコ\zako4.PNG";
  let frame   = 0;
  let xIni    = GetCenterX;
  let yIni    = GetCenterY-100;
  let Q=1;
let a=1;
let scoa=0;
@Initialize {

    SetLife(500);

    SetDamageRate(0, 0);
    LoadGraphic(imgBoss);
   SetTexture(imgBoss);   SetGraphicRect(0, 0, 64, 128);
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){a=1;ken;move;}
if(Q==2){a=-1;ken;move;}
if(Q==3){ken2;move2;}
wait(90);
      }


      }


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




             }

  sub move{
loop(390){
 if(GetX<GetPlayerX) {    SetMovePosition02(GetX+2, GetY, 1);
}

 if(GetX>GetPlayerX) {   SetMovePosition02(GetX-2, GetY, 1);
}
yield;
}
       }
sub move2{
loop(270){
 if(GetX<GetPlayerX) {    SetMovePosition02(GetX+2, GetY, 1);
}

 if(GetX>GetPlayerX) {   SetMovePosition02(GetX-2, GetY, 1);
}
yield;
}
 SetMovePosition02(GetCenterX, GetClipMinY, 60);
wait(90);
 SetMovePosition02(GetX, GetClipMaxY, 180);
wait(210);
 SetMovePosition02(GetX, GetClipMinY, 180);
wait(210);
 SetMovePosition02(GetX, GetClipMaxY, 180);
wait(210);
 SetMovePosition02(GetX, GetClipMinY, 180);
wait(210);
DeleteEnemyShot(ALL);
 SetMovePosition02(xIni, yIni, 30);
wait(30);
       }
    function wait(w) {
        loop(w) { yield; }
                    }

task ken{
let b=1;
CreateLaserB(359,150,20,BLUE32,30);
SetLaserDataB(359,0,0,60,0,0,1,0,3);
SetLaserDataB(359,90,0,60,0,NULL,-2,NULL,-5);
SetLaserDataB(359,180,0,60,0,NULL,4,NULL,6);
SetLaserDataB(359,270,0,0,5,90,0,90,6*a);


CreateLaserB(358,150,20,RED32,30);
SetLaserDataB(358,0,0,60,0,120,1,0,-5);
SetLaserDataB(358,90,0,60,0,NULL,-2,NULL,4);
SetLaserDataB(358,180,0,60,0,NULL,4,NULL,-5);
SetLaserDataB(358,330,0,0,5,90,0,90,-6*a);

CreateLaserB(357,150,20,GREEN32,30);
SetLaserDataB(357,0,0,60,0,240,1,0,5);
SetLaserDataB(357,90,0,60,0,NULL,-2,NULL,-5);
SetLaserDataB(357,180,0,60,0,NULL,4,NULL,5);
SetLaserDataB(357,390,0,0,5,90,0,90,6*a);

loop(90){

CreateShotA(31,0,0,0);
SetShotDataA(31,0,3,0,0,0,3,BLUE12);
AddShot(b,359,31,0);
CreateShotA(32,0,0,0);
SetShotDataA(32,0,3,0,0,0,3,RED12);
AddShot(b,358,32,0);
CreateShotA(33,0,0,0);
SetShotDataA(33,0,3,0,0,0,3,GREEN12);
AddShot(b,357,33,0);
b=b+3;
}
FireShot(359);
FireShot(358);
FireShot(357);
}
task ken2{
let b=1;
CreateLaserB(359,150,20,BLUE32,30);
SetLaserDataB(359,0,0,60,0,0,1,0,3);
SetLaserDataB(359,90,0,60,0,NULL,-2,NULL,-5);
SetLaserDataB(359,180,0,60,0,NULL,4,NULL,6);
SetLaserDataB(359,270,0,60,0,NULL,15,30,10);

CreateLaserB(358,150,20,RED32,30);
SetLaserDataB(358,0,0,60,0,120,1,0,-5);
SetLaserDataB(358,90,0,60,0,NULL,-2,NULL,4);
SetLaserDataB(358,180,0,60,0,NULL,4,NULL,-5);
SetLaserDataB(358,270,0,60,0,NULL,15,150,10);

CreateLaserB(357,150,20,GREEN32,30);
SetLaserDataB(357,0,0,60,0,240,1,0,5);
SetLaserDataB(357,90,0,60,0,NULL,-2,NULL,-5);
SetLaserDataB(357,180,0,60,0,NULL,4,NULL,5);
SetLaserDataB(357,270,0,60,0,NULL,15,270,10);

loop(360){

CreateShotA(31,0,0,0);
SetShotDataA(31,0,3,0,0,0,3,BLUE12);
AddShot(b,359,31,0);
CreateShotA(32,0,0,0);
SetShotDataA(32,0,3,0,0,0,3,RED12);
AddShot(b,358,32,0);
CreateShotA(33,0,0,0);
SetShotDataA(33,0,3,0,0,0,3,GREEN12);
AddShot(b,357,33,0);
b=b+3;
}
FireShot(359);
FireShot(358);
FireShot(357);
}

task shot{
loop{  CreateShot02(GetX, GetY, 1, GetAngleToPlayer,0.1,3, PURPLE03, 0);
CreateShot02(GetX, GetY, 1, GetAngleToPlayer+20,0.1,3, PURPLE03, 0);
CreateShot02(GetX, GetY, 1, GetAngleToPlayer-20,0.1,3, PURPLE03, 0);
wait(60);}
}

    sub setGraphicStop  { SetGraphicRect(  0,   0,  64,  128); }
    task setGraphicPose  {loop(50){ SetGraphicRect( 192,   0, 256,  128);yield;} }
    sub setGraphicRight  { SetGraphicRect(128,   0, 192,  128); }
    sub setGraphicLeft { SetGraphicRect(64,   0, 128,  128); }

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


    }



}}
