
#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){ loop(2){ shot; shot2;}wait(30); }
if(Q==2){SI;}
if(Q==3){SPIN;wait(30);}
if(Q==4){SPIN2;wait(30);}
if(Q==5){SI; }
         move;

}
      }


    sub standBy{
            let wIni =60;
        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);

             }

  sub move{
       moveToPlayer(rand(60, 90), rand(-30, 20), 30,
                     GetClipMinX + 60, GetClipMinY + 32,
                     GetClipMaxX - 60, GetClipMinY + 60);
   wait(30);
wait(60);
          
       }
    function wait(w) {
        loop(w) { yield; }
                    }
  sub shot { 
  let angle   = 90;
  loop(20){
     CreateShotA(359, GetX, GetY, 0);
     SetShotDataA(359, 0, 4, angle, 0, 0, 1, PURPLE03);
     angle = angle + 18;
     SetShotDataA(359, 30, 2, angle +130, 0 , 0, 1, PURPLE03);
    
   FireShot(359);
       }
   }
 sub shot2 {  
  let angle2   = 97;
 loop(25){
 CreateShotA(3594, GetX, GetY, 30);
     SetShotDataA(3594, 0, 4, angle2, 0, 0, 1, WHITE01);
     angle2 = angle2 - 54;
     SetShotDataA(3594, 30, 5, angle2 - 50, 0 , 0, 1, WHITE01);
        
   FireShot(3594);
      }wait(25);}

 sub SPIN{
  let angle   = 90;
  let C=rand_int(0,1);
 task shot{
loop(25){
loop(2){
  
        CreateShot02(GetX, GetY, 8, angle,-0.5,3, WHITE01, 50);
    angle = angle+180;     }
wait(2);    
loop(2){
            CreateShot02(GetX, GetY, 8, angle+90,-0.5,2, PURPLE01, 50);
       
    angle = angle+180;     }
angle=angle+45;
  wait(2);   
}
   }

    
 CreateEnemyFromScript("sild", GetX, GetY, 0, 0, 0);  
       setGraphicPose2;
  
       SetMovePosition02(GetCenterX,GetClipMinY,30);
          wait(30);
   shot;
if(C==0){
       SetMovePosition02(GetClipMinX,GetClipMinY,10);
          wait(10);
       SetMovePosition02(GetClipMinX,GetClipMaxY,30);
          wait(30);
       SetMovePosition02(GetClipMaxX,GetClipMaxY,20);
          wait(20);
       SetMovePosition02(GetClipMaxX,GetClipMinY,30);
          wait(30);
       SetMovePosition02(GetCenterX,GetClipMinY,10);
          wait(10);
}
if(C==1){
       SetMovePosition02(GetClipMaxX,GetClipMinY,10);
          wait(10);
       SetMovePosition02(GetClipMaxX,GetClipMaxY,30);
          wait(30);
          SetMovePosition02(GetClipMinX,GetClipMaxY,20);
          wait(20);
       SetMovePosition02(GetClipMinX,GetClipMinY,30);
          wait(30);
       SetMovePosition02(GetCenterX,GetClipMinY,10);
          wait(10);
}
       SetMovePosition02(GetCenterX,GetClipMinY+100,20);
          wait(20);
 
}
sub SPIN2{
  let angle   = 90;
  let C=rand_int(0,1);
 task shot{
loop(25){
loop(2){
  
        CreateShot02(GetX, GetY, 8, angle,-0.5,3, WHITE01, 50);
    angle = angle+180;     }
wait(2);    
loop(2){
            CreateShot02(GetX, GetY, 8, angle+90,-0.5,2, PURPLE01, 50);
       
    angle = angle+180;     }
angle=angle+45;
  wait(2);   
}
   }

    
 CreateEnemyFromScript("sild", GetX, GetY, 0, 0, 0);  
  
       SetMovePosition02(GetCenterX,GetClipMinY,5);
          wait(30);
   shot;
if(C==0){
       SetMovePosition02(GetClipMinX,GetClipMinY,10);
          wait(10);
       SetMovePosition02(GetClipMaxX,GetClipMaxY,30);
          wait(30);
       SetMovePosition02(GetClipMinX,GetClipMaxY,20);
          wait(20);
       SetMovePosition02(GetClipMaxX,GetClipMinY,30);
          wait(30);
       SetMovePosition02(GetCenterX,GetClipMinY,10);
          wait(10);
}
if(C==1){
       SetMovePosition02(GetClipMaxX,GetClipMinY,10);
          wait(10);
          SetMovePosition02(GetClipMinX,GetClipMaxY,30);
          wait(30);
       SetMovePosition02(GetClipMaxX,GetClipMaxY,20);
          wait(20);
       SetMovePosition02(GetClipMinX,GetClipMinY,30);
          wait(30);
       SetMovePosition02(GetCenterX,GetClipMinY,10);
          wait(10);
}
       SetMovePosition02(GetCenterX,GetClipMinY+100,20);
          wait(20);
 
}


sub SI{
      
CreateEnemyFromFile(GetCurrentScriptDirectory~"シールド.txt",GetX,GetY,0,0,0);
       wait(120);

}


    
    sub setGraphicStop  { SetGraphicRect(  0,   0,  64,  128); }
    sub setGraphicStop2  { loop(20){SetGraphicRect(  0,   128,  128,  256);yield;} }
    task setGraphicStop3  {loop(60){SetGraphicRect(  0,   128,  128,  256);yield;} 
   loop(30){SetGraphicRect(  128,   128,  256,  256);yield;}
    loop(30){SetGraphicRect(  0,   128,  128,  256);yield;} }
    task setGraphicPose1  {let aa=0;    loop(60){ yield; SetGraphicAngle(0,0,aa); aa=aa+39;}   SetGraphicAngle(0,0,0); }
       task setGraphicPose2  {let aa=0;    loop(150){yield; SetGraphicAngle(0,0,aa); aa=aa+21;}   SetGraphicAngle(0,0,0); }
 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;}
         }
    }


}}

	script_enemy sild
	{
        let img = "script\某アルマジロ\しーるど.png";
        let frame = 0;
        let aa=0;
        let aa2=90;
        let aa3=90;
        let X=GetX;
        let Y=GetY;
      LoadCommonData;
		@Initialize
		{ 
              SetLife(200);
              LoadGraphic(img);
SetAlpha(150);
SetGraphicAngle(0,0,aa);
              SetTexture(img);  SetGraphicRect(0, 0, 128, 128);


             TMain;
		
		}
			
		@MainLoop
		{
    SetCollisionA(GetX, GetY, 100);
    SetCollisionB(GetX, GetY, 60);
    aa=aa+21;
SetGraphicAngle(0,0,aa);
   yield;


		}
		
		@DrawLoop
		{
		   DrawGraphic(GetX, GetY);
		}
			
		@Finalize
		{
  
		}
         task TMain{
               
loop(130){
SetMovePosition02(GetEnemyX,GetEnemyY,1);
yield;
}
VanishEnemy;


                   }



	
task shot{
loop(90){

CreateShot02(GetX,GetY,2,aa2,0,0,ORANGE01,30);
CreateShot02(GetX,GetY,2,aa2+180,0,0,WHITE01,30);
aa2=aa2+180;
loop(5){yield;}
}




}
}