
#Title[再戦マンモス]
#Text[]
#ScriptVersion[2]


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

    SetLife(300);
           
    SetDamageRate(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;
   hinoko;
    loop{
                  Q=rand_int(1,1);
  if(GetLife<800){Q=rand_int(1,2);}
shot;   
move;
shot2;

loop(120) { yield; }
if(Q==1){wa;wait(90);} 
if(Q==2){SetMovePosition02(xIni, yIni-60, 30);wait(60);wall;loop(4){tama;wait(150);}wait(90);}
}
      }


    sub standBy{
            let wIni =60;
        SetMovePosition02(xIni, yIni-60, wIni);
    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{
    yield;

      
       moveToPlayer(rand(0, 60), rand(-30, 20), 60,
                     GetClipMinX + 60, GetClipMinY + 32,
                     GetClipMaxX - 60, GetClipMinY + 60);
   wait(90);
          
       }
    function wait(w) {
        loop(w) { yield; }
                    }
  task shot {

loop(30){
loop(4){CreateShot02(GetX,GetY,3,anglef,0,0,RED04,0);
anglef=anglef+10;}
    anglef=anglef+19;wait(5);}
   }
 sub shot2 {  
  let angle2   = 90;
loop(30){
loop(4){CreateShot02(GetX,GetY,2,angle2+6,0.1,4,ORANGE03,60);angle2=angle2+90;}
    angle2=angle2+18;wait(1);}
}

sub wa{
    task setGraphicPose2  {loop(10){ SetGraphicRect( 192,   0, 256,  128);yield;} }
       moveToPlayer(rand(60, 150), rand(-60, 40), 30,
                     GetClipMinX + 60, GetClipMinY + 32,
                     GetClipMaxX - 60, GetClipMinY + 60);
 loop(60) { yield; }
let Angle=GetAngleToPlayer; 
loop(60){
if(GetLife<600){
Angle=GetAngleToPlayer;} 

CreateShotA(45,GetX,GetY,40);
SetShotDataA(45,0,8,Angle,0,0,9,ORANGE03);
SetShotDataA(45,1,8,Angle,rand(-1.5,1.5),0,9,ORANGE03);
SetShotDataA(45,25,8,NULL,0,0,9,ORANGE03);
CreateShotA(46,GetX,GetY,40);
SetShotDataA(46,0,8,Angle,0,0,9,RED03);
SetShotDataA(46,1,8,Angle,rand(-1.5,1.5),0,9,RED03);
SetShotDataA(46,25,8,NULL,0,0,9,RED03);


FireShot(45);
FireShot(46);
yield;
yield;

}

}
task wall{
   task setGraphicPose2  {loop(660){ SetGraphicRect( 192,   0, 256,  128);yield;} }
 sub w{let X=GetClipMinX-100; 
loop(1){

CreateLaserA(45,X,GetClipMinY,0,60,ORANGE01,30);
SetLaserDataA(45,0,0,0,10,1,90);
SetLaserDataA(45,35,0,0,0,1,90);
SetLaserDataA(45,90,0,0,0,1,90);
FireShot(45);

yield;

}

}
 sub w2{let X=GetClipMaxX+100; 
loop(1){

CreateLaserA(45,X,GetClipMinY,0,60,ORANGE01,30);
SetLaserDataA(45,0,180,0,10,1,90);
SetLaserDataA(45,35,180,0,0,1,90);
SetLaserDataA(45,90,180,0,0,1,90);
FireShot(45);

yield;

}}

  loop(2){ 

      wait(150);

      wait(150);
        }
}
sub tama{
let a=1;
let b=rand_int(1,6);
CreateShotA(11,GetX,GetY,0);
SetShotDataA(11,0,1,GetAngleToPlayer,0,0.5,9,RED03);
loop(100){
b=rand_int(1,12);
CreateShotA(12,rand(-30,30),rand(-30,30),30);
SetShotDataA(12,0,2,30*b,0,-0.5,2,ORANGE11);
AddShot(a,11,12,0);
a=a+1;
}
    SetColor(240,100,20);
Concentration01(60);
SetColor(255,255,255);
  wait(30);
FireShot(11);
}

task hinoko{

   loop{   

    CreateShotA(3594, rand(-60, 500), GetClipMaxY-rand(0,60), 90);
    SetShotDataA(3594, 0, 1, 270, 0, 0, 1, ORANGE05);
     FireShot(3594);
     if(GetLife>800){wait(8);}if(GetLife>500){wait(8);}if(GetLife>200){wait(8);}
    CreateShotA(3595, rand(-60, 500), GetClipMaxY-rand(0,60), 60);
    SetShotDataA(3595, 0, 1, 270, 0, 0, 1, RED05);
   FireShot(3595);
     if(GetLife>650){wait(8);}if(GetLife>350){wait(8);}if(GetLife>0){wait(8);}
   } 

}



   sub setGraphicStop  { SetGraphicRect(  0,   0,  64,  128); }
    task setGraphicPose  {loop(90){ 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;}
         }
    }

}}