
#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,4);
 


if(Q==1){SHOTGANICE; wait(60); }
if(Q==2){NORMALSHOT;wait(210);}
if(Q==3){KOUTEI; wait(60); }
if(Q==4){KOUTEI; wait(60); }
if(Q==5){loop(3){SHOTGANICE; wait(50);}wait(10); }
if(Q==6){HUBUKI;snow;
loop(10){
       SetMovePosition02(GetPlayerX+rand(-90,90), GetClipMinY+30, 30);
        loop(30) { yield; }      } 
      SetMovePosition02(xIni, yIni, 30);
wait(30);
  }



         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{
    yield;

        
       moveToPlayer(rand(60, 120), rand(-30, 20), 60,
                     GetClipMinX + 60, GetClipMinY + 32,
                     GetClipMaxX - 60, GetClipMinY + 60);
   wait(80);
          
       }
    function wait(w) {
        loop(w) { yield; }
                    }

task NORMALSHOT{
  let angle   = 90;
  let angle2   = 97;

  sub shot {   loop(40){ 
     CreateShotA(359, GetX, GetY, 0);
     SetShotDataA(359, 0, 7, angle, 0, 0, 1, WHITE01);
     angle = angle + 54;
     SetShotDataA(359, 20, 0, NULL, 0 , 0, 1, BLUE23);
     SetShotDataA(359, 40, 2, rand(60, 120), 0, 0, 1, BLUE23);
     yield;
   FireShot(359);
   wait(1);    }}
   
 sub shot2 {   loop(40){
 CreateShotA(3594, GetX, GetY, 0);
     SetShotDataA(3594, 0, 7, angle2, 0, 0, 1, AQUA01);
     angle2 = angle2 - 54;
     SetShotDataA(3594, 20, 0, NULL, 0, 0, 1, WHITE02);
     SetShotDataA(3594, 40, 4, angle2 - 120, 0 , 0, 1, WHITE02);
          yield;
   FireShot(3594);
   wait(1);   }}

shot;
shot2;
}

task SHOTGANICE{
  let angle   = 90;
  
loop(6){

CreateShotA(11,0,0,0);
SetShotDataA(11,1,3,angle+135,0,0,9,BLUE23);
CreateShotA(22,0,0,0);
SetShotDataA(22,1,3,angle-135,0,0,9,BLUE23);
CreateShotA(33,0,0,0);
SetShotDataA(33,1,3,angle-90,0,0,9,BLUE23);
CreateShotA(44,0,0,0);
SetShotDataA(44,1,3,angle+90,0,0,9,BLUE23);
CreateShotA(3,0,0,0);
SetShotDataA(3,1,5,angle,0,0,9,WHITE01);
SetShotDataA(3,5,0,NULL,0,0,9,WHITE01);
CreateShotA(45,GetX,GetY,0);
SetShotDataA(45,1,7,GetAngleToPlayer,0,0,9,WHITE02);
angle=angle+60;

SetShotKillTime(3,61);
AddShot(60,3,11,0);
AddShot(60,3,22,0);
AddShot(60,3,33,0);
AddShot(60,3,44,0);
AddShot(20,45,3,0);

SetShotKillTime(45,21);
FireShot(45);

}
loop(12){

CreateShotA(11,0,0,0);
SetShotDataA(11,1,3,angle,0,0,9,AQUA23);
CreateShotA(22,0,0,0);
SetShotDataA(22,1,3,angle-180,0,0,9,AQUA23);
CreateShotA(33,0,0,0);
SetShotDataA(33,1,3,angle+90,0,0,9,AQUA23);
CreateShotA(44,0,0,0);
SetShotDataA(44,1,3,angle-90,0,0,9,AQUA23);
CreateShotA(5,0,0,0);
SetShotDataA(5,1,5,angle+15,0,0,9,WHITE01);
angle=angle+30;
SetShotDataA(5,10,0,NULL,0,0,9,WHITE01);
CreateShotA(46,GetX,GetY,0);
SetShotDataA(46,1,7,GetAngleToPlayer,0,0,9,WHITE02);

SetShotKillTime(5,61);
AddShot(60,5,11,0);
AddShot(60,5,22,0);
AddShot(60,5,33,0);
AddShot(60,5,44,0);
AddShot(20,46,5,0);

SetShotKillTime(46,21);
FireShot(46);
}
loop(6){

CreateShotA(11,0,0,0);
SetShotDataA(11,1,3,angle-210,0,0,9,WHITE23);
CreateShotA(22,0,0,0);
SetShotDataA(22,1,3,angle-190,0,0,9,WHITE23);
CreateShotA(33,0,0,0);
SetShotDataA(33,1,3,angle-160,0,0,9,WHITE23);
CreateShotA(44,0,0,0);
SetShotDataA(44,1,3,angle-170,0,0,9,WHITE23);
CreateShotA(9,0,0,0);
SetShotDataA(9,1,5,angle,0,0,9,WHITE01);
angle=angle+60;
SetShotDataA(9,15,0,NULL,0,0,9,WHITE01);
CreateShotA(47,GetX,GetY,0);
SetShotDataA(47,1,7,GetAngleToPlayer,0,0,9,WHITE02);
SetShotKillTime(9,61);
AddShot(60,9,11,0);
AddShot(60,9,22,0);
AddShot(60,9,33,0);
AddShot(60,9,44,0);
AddShot(20,47,9,0);


SetShotKillTime(47,21);
FireShot(47);
}
}

task KOUTEI{
 sub shot{
if(GetLife>500){
CreateEnemyFromFile(GetCurrentScriptDirectory~"kooli.txt",GetX,GetY+30,0,0,0);}
if(500>=GetLife){loop(2){CreateEnemyFromFile(GetCurrentScriptDirectory~"kooli.txt",GetX+rand(-100,100),GetY+rand(0,60),0,0,0);}}

}
 shot;

}
task HUBUKI{
let angle   = 90;
  let a=1;   loop(10){loop(3){ angle=rand(-45,45);
     CreateShotA(359, GetX, GetY, 0);
     SetShotDataA(359, 0, 5, GetAngleToPlayer+angle, 0, 0, 4, 01);
   loop(10){  CreateShotA(3592, 0, 0, 20);
     SetShotDataA(3592, 0, 1, GetAngleToPlayer+angle, 0, 0, 7, AQUA23);
        AddShot(a,359,3592,0);a=a+3;  }
   a=0;
       
       FireShot(359);
}
        wait(30);
      }

}
  task snow{  loop(1){   loop(75){   

    CreateShotA(3594, rand(-60, 500), GetClipMinY, 0);
    SetShotDataA(3594, 0, 4, 75, 0, 0, 3, WHITE05);
   

       yield;
     FireShot(3594);
     wait(1);
   } 
   loop(75){   

    CreateShotA(3594, rand(-60, 500), GetClipMinY, 0);
    SetShotDataA(3594, 0, 4, 105, 0, 0, 3, WHITE05);
   

       yield;
     FireShot(3594);
     wait(1);
   } }
   }






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


    }



}}