
#Title[再戦マンドリル]
#Text[]
#ScriptVersion[2]

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

@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{  
loop(5){
                 Q=rand_int(1,4);


if(Q==2){NORMALSHOT; wait(20); if(GetLife>500){wait(40);}}
if(Q==1){DASH; wait(20); if(GetLife>500){wait(40);}}
if(Q==3){Shot1;Shot2; wait(30); if(GetLife>500){wait(30);}}
if(Q==4){Shot3;Shot4; wait(30); if(GetLife>500){wait(30);}}
if(Q==5){fist;}
if(Q==6){Shot1;Shot2;Shot3;Shot4; wait(30);}
move;}
       SetMovePosition02(xIni, 150, 20);
wait(20);
        }
    }


    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, 120), rand(-30, 20), 30,
                     GetClipMinX + 60, GetClipMinY + 32,
                     GetClipMaxX - 60, GetClipMinY + 60);
       wait(60);
       }
    function wait(w) {
        loop(w) { yield; }
                    }
sub NORMALSHOT{
task setGraphicPose  {loop(30){ SetGraphicRect( 192,  0, 256,  128);yield;} }
let AA2   = 0;
sub Shot{
loop(5){
let AA   = AA2;
let aa=5;
CreateShotA(11,GetX,GetY,30);
SetShotDataA(11,0,10,AA,0,0,9,YELLOW04);

CreateShotA(13,GetX,GetY,30);
SetShotDataA(13,0,10,AA+90,0,0,9,PURPLE04);

CreateShotA(12,GetX,GetY,30);
SetShotDataA(12,0,10,AA+180,0,0,9,YELLOW04);

CreateShotA(14,GetX,GetY,30);
SetShotDataA(14,0,10,AA-90,0,0,9,PURPLE04);
loop(10){
CreateShotA(110,0,0,10);
SetShotDataA(110,0,3,AA+90,0,0,9,YELLOW12);
CreateShotA(130,0,0,10);
SetShotDataA(130,0,3,AA+90+90,0,0,9,PURPLE12);
CreateShotA(120,0,0,10);
SetShotDataA(120,0,3,AA+180+90,0,0,9,YELLOW12);
CreateShotA(140,0,0,10);
SetShotDataA(140,0,3,AA-90+90,0,0,9,PURPLE12);
AddShot(aa,11,110,0);
AddShot(aa,12,120,0);
AddShot(aa,13,130,0);
AddShot(aa,14,140,0);
aa=aa+5;
}
FireShot(11);
FireShot(12);
FireShot(13);
FireShot(14);
wait(2);
}

wait(5);
}
loop(5){
Shot;
wait(2);
AA2=AA2+48;}
}
  sub DASH{
let A=20;
let Y=GetY-rand(-120,120);
if(Y>GetClipMaxY){Y=GetClipMaxY-120;}
if(Y<GetClipMinY){Y=GetClipMinY+120;}
    loop(3){
if(GetX<=GetCenterX){

       SetMovePosition02(GetClipMaxX-20,Y,15);
A=20;
}
if(GetX>=GetCenterX){

       SetMovePosition02(GetClipMinX+20,Y,15);
A=-20;
}
          wait(15);
shot;
}
sub shot{
let AA=0;
let AA2=0;
 let AAA=90;
let AAA2=0;
loop(12){
AA=0;
AA2=0;
CreateShotA(45,GetX+A,GetY,10);
SetShotDataA(45,0,7,AAA,0,0,9,YELLOW04);
CreateShotA(46,GetX+A,GetY,10);
SetShotDataA(46,0,7,AAA+180,0,0,9,PURPLE04);
task ad{
loop(110){
AA=AA+rand(3,16);
AA2=AA2+rand(3,16);
CreateShotA(33,0,0,20);
SetShotDataA(33,0,9,AAA2,0,-0.8,4,YELLOW12);
AddShot(AA,45,33,0);
CreateShotA(34,0,0,20);
SetShotDataA(34,0,9,AAA2,0,-0.8,2,PURPLE12);
AddShot(AA2,46,34,0);
AAA2=AAA2+180;
}}
ad;
FireShot(45);
FireShot(46);
AAA=AAA+180;
wait(5);
}
}
      

       }


 task Shot1{
loop(10){
CreateShot02(GetX,GetY-12,10,0,0,0,PURPLE04,10);
CreateShot02(GetX,GetY-12,10,180,0,0,PURPLE04,10);
wait(2);
}
wait(10);
let obj1=Obj_Create(OBJ_SHOT);
Obj_SetX(obj1, GetClipMaxX);
Obj_SetY(obj1, GetY-12);
ObjShot_SetGraphic(obj1, PURPLE04);
ObjShot_SetDelay(obj1,60);
Obj_SetAngle(obj1,270);
Obj_SetSpeed(obj1, 2);
let obj2=Obj_Create(OBJ_SHOT);
Obj_SetX(obj2, GetClipMinX);
Obj_SetY(obj2, GetY-12);
ObjShot_SetGraphic(obj2, PURPLE04);
ObjShot_SetDelay(obj2,60);
Obj_SetAngle(obj2,270);
Obj_SetSpeed(obj2, 2);
yield;
Obj_SetAutoDelete(obj1,true);
Obj_SetAutoDelete(obj2,true);
loop(30){wait(12);
let obj3=Obj_Create(OBJ_SHOT);
Obj_SetX(obj3, Obj_GetX(obj1));
Obj_SetY(obj3, Obj_GetY(obj1));
ObjShot_SetGraphic(obj3, PURPLE12);
ObjShot_SetDelay(obj3,10);
Obj_SetAngle(obj3,180);
Obj_SetSpeed(obj3, 4);

task el{
loop{
yield;
if(!Obj_BeDeleted(obj1)){
Obj_SetY(obj3, Obj_GetY(obj1));
if(Collision_Obj_Obj(obj3,obj2)==true){Obj_Delete(obj3);}
}
}
}
el;

} 
Obj_Delete(obj1);
Obj_Delete(obj2); 
}

 task Shot2{
loop(10){
CreateShot02(GetX,GetY-12,10,0,0,0,YELLOW04,10);
CreateShot02(GetX,GetY-12,10,180,0,0,YELLOW04,10);
wait(2);
}
wait(10);
let obj1=Obj_Create(OBJ_SHOT);
Obj_SetX(obj1, GetClipMinX);
Obj_SetY(obj1, GetY-12);
ObjShot_SetGraphic(obj1, YELLOW04);
ObjShot_SetDelay(obj1,60);
Obj_SetAngle(obj1,90);
Obj_SetSpeed(obj1, 2);
let obj2=Obj_Create(OBJ_SHOT);
Obj_SetX(obj2, GetClipMaxX);
Obj_SetY(obj2, GetY-12);
ObjShot_SetGraphic(obj2, YELLOW04);
ObjShot_SetDelay(obj2,60);
Obj_SetAngle(obj2,90);
Obj_SetSpeed(obj2, 2);
yield;
Obj_SetAutoDelete(obj1,true);
Obj_SetAutoDelete(obj2,true);
loop(30){wait(12);
let obj3=Obj_Create(OBJ_SHOT);
Obj_SetX(obj3, Obj_GetX(obj1));
Obj_SetY(obj3, Obj_GetY(obj1));
ObjShot_SetGraphic(obj3, YELLOW12);
ObjShot_SetDelay(obj3,10);
Obj_SetAngle(obj3,0);
Obj_SetSpeed(obj3, 4);

task el{
loop{yield;
if(!Obj_BeDeleted(obj1)){
Obj_SetY(obj3, Obj_GetY(obj1));
if(Collision_Obj_Obj(obj3,obj2)==true){Obj_Delete(obj3);}
}
}
}
el;

}  
Obj_Delete(obj1);
Obj_Delete(obj2);
}

 task Shot3{
loop(10){
CreateShot02(GetX,GetY-12,10,90,0,0,PURPLE04,10);
CreateShot02(GetX,GetY-12,10,270,0,0,PURPLE04,10);
wait(2);
}
wait(10);
let obj1=Obj_Create(OBJ_SHOT);
Obj_SetX(obj1, GetX);
Obj_SetY(obj1, GetClipMaxY);
ObjShot_SetGraphic(obj1, PURPLE04);
ObjShot_SetDelay(obj1,60);
Obj_SetAngle(obj1,0);
Obj_SetSpeed(obj1, 2);
let obj2=Obj_Create(OBJ_SHOT);
Obj_SetX(obj2, GetX);
Obj_SetY(obj2, GetClipMinY);
ObjShot_SetGraphic(obj2, PURPLE04);
ObjShot_SetDelay(obj2,60);
Obj_SetAngle(obj2,0);
Obj_SetSpeed(obj2, 2);
yield;
Obj_SetAutoDelete(obj1,true);
Obj_SetAutoDelete(obj2,true);
loop(30){wait(12);
let obj3=Obj_Create(OBJ_SHOT);
Obj_SetX(obj3, Obj_GetX(obj1));
Obj_SetY(obj3, Obj_GetY(obj1));
ObjShot_SetGraphic(obj3, PURPLE12);
ObjShot_SetDelay(obj3,10);
Obj_SetAngle(obj3,270);
Obj_SetSpeed(obj3, 4);

task el{
loop{yield;
if(!Obj_BeDeleted(obj1)){
Obj_SetX(obj3, Obj_GetX(obj1));
if(Collision_Obj_Obj(obj3,obj2)==true){Obj_Delete(obj3);}
}
}
}
el;
}  
Obj_Delete(obj1);
Obj_Delete(obj2);
}

 task Shot4{
loop(10){
CreateShot02(GetX,GetY-12,10,90,0,0,YELLOW04,10);
CreateShot02(GetX,GetY-12,10,270,0,0,YELLOW04,10);
wait(2);
}
wait(10);
let obj1=Obj_Create(OBJ_SHOT);
Obj_SetX(obj1, GetX);
Obj_SetY(obj1, GetClipMinY);
ObjShot_SetGraphic(obj1, YELLOW04);
ObjShot_SetDelay(obj1,60);
Obj_SetAngle(obj1,180);
Obj_SetSpeed(obj1, 2);
let obj2=Obj_Create(OBJ_SHOT);
Obj_SetX(obj2, GetX);
Obj_SetY(obj2, GetClipMaxY);
ObjShot_SetGraphic(obj2, YELLOW04);
ObjShot_SetDelay(obj2,60);
Obj_SetAngle(obj2,180);
Obj_SetSpeed(obj2, 2);
yield;
Obj_SetAutoDelete(obj1,true);
Obj_SetAutoDelete(obj2,true);
loop(30){wait(12);
let obj3=Obj_Create(OBJ_SHOT);
Obj_SetX(obj3, Obj_GetX(obj1));
Obj_SetY(obj3, Obj_GetY(obj1));
ObjShot_SetGraphic(obj3, YELLOW12);
ObjShot_SetDelay(obj3,10);
Obj_SetAngle(obj3,90);
Obj_SetSpeed(obj3, 4);

task el{
loop{yield;
if(!Obj_BeDeleted(obj1)){
Obj_SetX(obj3, Obj_GetX(obj1));
if(Collision_Obj_Obj(obj3,obj2)==true){Obj_Delete(obj3);}
}
}
}
el;
}  
Obj_Delete(obj1);
Obj_Delete(obj2);
}

sub fist{
let an=0;

wait(40);
    SetColor(150,200,0);
Concentration01(40);
SetColor(255,255,255);

yield;
MotionBlur(ALL,50,220);
        SetMovePosition02(GetPlayerX, GetPlayerY, 25);
   wait(25);

loop(12){
CreateShot02(GetX,GetY,8,an,0,0,YELLOW04,0);
CreateShot02(GetX,GetY,5,an+15,0,0,PURPLE04,0);
an=an+30;
}
   wait(40);
        SetMovePosition02(GetPlayerX, yIni+60, 20);
   wait(30);


}



    sub setGraphicStop  { SetGraphicRect(  0,   0,  64,  128); }
  task setGraphicPoseA  {loop(20){ SetGraphicRect( 192,  0, 256,  128);yield;} }
  task setGraphicPoseB  {loop(30){ SetGraphicRect( 192,  0, 256,  128);yield;} }
  task setGraphicPoseC  {loop(10){ SetGraphicRect( 192,  0, 256,  128);yield;} }
    task setGraphicPose1  {loop(90){ SetGraphicRect( 0,  128, 128,  256);yield;} }
    task setGraphicPose2  {loop(90){ SetGraphicRect( 128,  128, 256,  256);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;}
         }
    }

}}