
#Title[再戦タコ]
#Text[]
#ScriptVersion[2]

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

    SetLife(300);
           
    SetDamageRate(0, 0);
           SetEffectForZeroLife(0,0,0);
    LoadGraphic(imgBoss);
SetShotAutoDeleteClip(128,128,128,128);
   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(3,5);




if(Q==1){           setGraphicPose2;  wait(30); setGraphicPose3;nshot1;wait(210); move; }
if(Q==2){           setGraphicPose2;  wait(10); setGraphicPose3;nshot2;wait(210); move; }
if(Q==3){  T=300;       SetMovePosition02(GetCenterX, GetClipMaxY - 400,30); wait(60);   
     wait(30);       HOR; wait(390); }
if(Q==5){SetMovePosition02(GetCenterX, GetClipMinY ,30); wait(30);move2;loop(10){ Ns;wait(60);}
        SetMovePosition02(GetCenterX, GetClipMaxY - 350,30); wait(90); } 
if(Q==4){        SetMovePosition02(GetCenterX+rand(-200,200), GetClipMinY+60,30); wait(30);
  wait(15);Ns3; wait(60); }
if(Q==6){SetMovePosition02(GetCenterX, GetClipMinY ,30); wait(30);move2;loop(20){ Ns;wait(30);}
      move3;loop(10){ Ns3;wait(60);} } 
if(Q==7){ T=600; HOR; SetMovePosition02(GetCenterX, GetClipMinY ,30); wait(30);lase;move2;wait(700);
     HOR; move3;wait(700);} 


       }
    }


    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), 30,
                     GetClipMinX + 60, GetClipMinY + 32,
                     GetClipMaxX - 60, GetClipMinY + 60);
       loop(40) { yield; }
       if(GetLife>550){wait(20);}
       }
    function wait(w) {
        loop(w) { yield; }
                    }
task move2{
  SetMovePositionHermite(GetClipMaxX,GetY+100,2000,180,200,45,120);
        loop(120){yield;}
    SetMovePositionHermite(GetClipMinX,GetY+100,200,90,-200,45,120);
        loop(120){yield;}
    SetMovePositionHermite(GetClipMaxX,GetY+100,200,90,200,45,120);
        loop(120){yield;}
    SetMovePositionHermite(GetClipMinX,GetY+100,200,90,-200,45,120);
        loop(120){yield;}
    SetMovePositionHermite(GetClipMaxX,GetY+100,200,90,200,45,120);
        loop(120){yield;}
}
task move3{

    SetMovePositionHermite(GetClipMinX,GetY-100,200,-90,-200,45,120);
        loop(120){yield;}
  SetMovePositionHermite(GetClipMaxX,GetY-100,200,-90,200,45,120);
        loop(120){yield;}
    SetMovePositionHermite(GetClipMinX,GetY-100,200,-90,-200,45,120);
        loop(120){yield;}
    SetMovePositionHermite(GetClipMaxX,GetY-100,200,-90,200,45,120);
        loop(120){yield;}
    SetMovePositionHermite(GetCenterX, GetClipMaxY - 350,200,-90,200,45,120);
        loop(120){yield;}
}
task lase{
  let angle   = 90;
  let objShot = NULL;
  let objShot2 = NULL;
  let objShot3 = NULL;
  let objShot4 = NULL;
  let an =NULL;
  let an2 =NULL;
  let an3 =NULL;
  let an4 =NULL;
  let count=0;
     let aa=90;
  let an= 45;
Obj_SetSpeed(objShot,1);
   objShot=Obj_Create(OBJ_LASER);
   Obj_SetPosition(objShot,GetX,GetY);
   ObjShot_SetDelay(objShot,60);
   Obj_SetAngle(objShot,an);
   ObjLaser_SetLength(objShot,200);
   ObjLaser_SetWidth(objShot,30);
   ObjShot_SetGraphic(objShot,RED01);
   ObjLaser_SetSource(objShot,false);
  let an2= 225;
Obj_SetSpeed(objShot2,1);
   objShot2=Obj_Create(OBJ_LASER);
   Obj_SetPosition(objShot2,GetX,GetY);
   ObjShot_SetDelay(objShot2,60);
   Obj_SetAngle(objShot2,an2);
   ObjLaser_SetLength(objShot2,200);
   ObjLaser_SetWidth(objShot2,30);
   ObjShot_SetGraphic(objShot2,BLUE01);
   ObjLaser_SetSource(objShot2,false);
  let an3= 135;
  let an4= 315;
Obj_SetSpeed(objShot3,1);
   objShot3=Obj_Create(OBJ_LASER);
   Obj_SetPosition(objShot3,GetX,GetY);
   ObjShot_SetDelay(objShot3,60);
   Obj_SetAngle(objShot3,an3);
   ObjLaser_SetLength(objShot3,200);
   ObjLaser_SetWidth(objShot3,30);
   ObjShot_SetGraphic(objShot3,GREEN01);
   ObjLaser_SetSource(objShot3,false);

Obj_SetSpeed(objShot4,1);
   objShot4=Obj_Create(OBJ_LASER);
   Obj_SetPosition(objShot4,GetX,GetY);
   ObjShot_SetDelay(objShot4,60);
   Obj_SetAngle(objShot4,an4);
   ObjLaser_SetLength(objShot4,200);
   ObjLaser_SetWidth(objShot4,30);
   ObjShot_SetGraphic(objShot4,YELLOW01);
   ObjLaser_SetSource(objShot4,false);

loop(1300){
   Obj_SetAngle(objShot,an);
an=an+2;
   Obj_SetAngle(objShot2,an2);
an2=an2+2;

   Obj_SetAngle(objShot3,an3);
an3=an3+2;
   Obj_SetAngle(objShot4,an4);
an4=an4+2;
   Obj_SetPosition(objShot,GetX,GetY);
   Obj_SetPosition(objShot2,GetX,GetY);
   Obj_SetPosition(objShot3,GetX,GetY);
   Obj_SetPosition(objShot4,GetX,GetY);
yield;
}
ObjShot_FadeDelete(objShot);
ObjShot_FadeDelete(objShot2);
ObjShot_FadeDelete(objShot3);
ObjShot_FadeDelete(objShot4);


}

sub Ns{
let ang=rand_int(1,4)*90;
let a=1;

   SetShotDirectionType(ABSOLUTE);
CreateShotA(3,GetX,GetY,0);
SetShotDataA(3,0,7,ang,0,0,2,RED02);
CreateShotA(5,GetX,GetY,0);
SetShotDataA(5,0,7,ang+180,0,0,2,BLUE02);
CreateShotA(9,GetX,GetY,0);
SetShotDataA(9,0,7,ang+90,0,0,2,GREEN02);
CreateShotA(4,GetX,GetY,0);
SetShotDataA(4,0,7,ang-90,0,0,2,YELLOW02);
 
loop(100){


CreateShotA(32,0,0,0);
  SetShotDirectionType(PLAYER);
SetShotDataA(32,0,0,0,0,0,2,RED12);
SetShotDataA(32,70-a,3,NULL,0,0,2,RED12);
AddShot(a,3,32,0);
CreateShotA(52,0,0,0);
SetShotDataA(52,0,0,0,0,0,2,BLUE12);
SetShotDataA(52,70-a,3,NULL,0,0,2,BLUE12);
AddShot(a,5,52,0);
CreateShotA(92,0,0,0);
SetShotDataA(92,0,0,0,0,0,2,GREEN12);
SetShotDataA(92,70-a,3,NULL,0,0,2,GREEN12);
AddShot(a,9,92,0);
CreateShotA(42,0,0,0);
SetShotDataA(42,0,0,0,0,0,2,YELLOW12);
SetShotDataA(42,70-a,3,NULL,0,0,2,YELLOW12);
AddShot(a,4,42,0);

a=a+10;}

   SetShotDirectionType(PLAYER);
   SetShotDirectionType(ABSOLUTE);
FireShot(3);
FireShot(5);
FireShot(9);
FireShot(4);
}
sub Ns2{
let a=1;
let b=0;
   SetShotDirectionType(ABSOLUTE);
CreateShotA(3,GetX,GetY,0);
SetShotDataA(3,0,7,20+GetAngleToPlayer,0,0,2,RED02);
CreateShotA(5,GetX,GetY,0);
SetShotDataA(5,0,7,-20+GetAngleToPlayer,0,0,2,BLUE02);
CreateShotA(9,GetX,GetY,0);
SetShotDataA(9,0,7,60+GetAngleToPlayer,0,0,2,GREEN02);
CreateShotA(4,GetX,GetY,0);
SetShotDataA(4,0,7,-60+GetAngleToPlayer,0,0,2,YELLOW02);
 
loop(100){
 b=-30;
loop(3){

CreateShotA(32,0,0,0);
  SetShotDirectionType(PLAYER);
SetShotDataA(32,0,3,b,0,0,2,RED12);
AddShot(a,3,32,0);
CreateShotA(52,0,0,0);
SetShotDataA(52,0,3,b,0,0,2,BLUE12);
AddShot(a,5,52,0);
CreateShotA(92,0,0,0);
SetShotDataA(92,0,3,b,0,0,2,GREEN12);
AddShot(a,9,92,0);
CreateShotA(42,0,0,0);
SetShotDataA(42,0,3,b,0,0,2,YELLOW12);
AddShot(a,4,42,0);
   b=b+30; }
a=a+5;}

   SetShotDirectionType(PLAYER);
   SetShotDirectionType(ABSOLUTE);
FireShot(3);
FireShot(5);
FireShot(9);
FireShot(4);
}
sub Ns3{
let a=1;
let b=-20;
let A=GetAngleToPlayer;
CreateShotA(3,GetX,GetY,0);
SetShotDataA(3,0,9,10+A,0,0,2,RED02);
CreateShotA(5,GetX,GetY,0);
SetShotDataA(5,0,9,-10+A,0,0,2,BLUE02);
CreateShotA(9,GetX,GetY,0);
SetShotDataA(9,0,9,30+A,0,0,2,GREEN02);
CreateShotA(4,GetX,GetY,0);
SetShotDataA(4,0,9,-30+A,0,0,2,YELLOW02);
 
loop(100){

b=-30;
loop(3){
CreateShotA(32,0,0,20);

SetShotDataA(32,0,3,10+A+b,0,0,2,RED12);
AddShot(a,3,32,0);
CreateShotA(52,0,0,20);
SetShotDataA(52,0,3,-10+A+b,0,0,2,BLUE12);
AddShot(a,5,52,0);
CreateShotA(92,0,0,20);
SetShotDataA(92,0,3,30+A+b,0,0,2,GREEN12);
AddShot(a,9,92,0);
CreateShotA(42,0,0,20);
SetShotDataA(42,0,3,-30+A+b,0,0,2,YELLOW12);
AddShot(a,4,42,0);
b=b+30;}
a=a+8;}


FireShot(3);
FireShot(5);
FireShot(9);
FireShot(4);
}

sub nshot1{  let ang=GetAngleToPlayer-60;
let ang2=GetAngleToPlayer+60;

loop(4){
let a=1;
CreateShotA(359,GetX,GetY,0);
SetShotDataA(359,0,7,ang,0,0,2,GREEN02);
ang=ang+34;
CreateShotA(358,GetX,GetY,0);
SetShotDataA(358,0,7,ang2,0,0,2,YELLOW02);
ang2=ang2-34;
loop(100){

CreateShotA(31,0,0,20);
SetShotDataA(31,0,0.7,ang+180,0,0,2,GREEN12);
SetShotDataA(31,a*6,2,ang,0,0,2,GREEN12);
AddShot(a,359,31,0);
CreateShotA(32,0,0,20);
SetShotDataA(32,0,0.7,ang2+180,0,0,2,YELLOW12);
SetShotDataA(32,a*6,2,ang2,0,0,2,YELLOW12);
AddShot(a,358,32,0);
a=a+4;}

FireShot(359);
FireShot(358);
}


}

sub nshot2{   let ang=GetAngleToPlayer-60;
let ang2=GetAngleToPlayer+60;

loop(4){
let a=1;
CreateShotA(359,GetX,GetY,0);
SetShotDataA(359,0,7,ang,0,0,2,BLUE02);
ang=ang+34;
CreateShotA(358,GetX,GetY,0);
SetShotDataA(358,0,7,ang2,0,0,2,RED02);
ang2=ang2-34;
loop(100){

CreateShotA(31,0,0,20);
SetShotDataA(31,0,0.7,ang+180,0,0,2,BLUE12);
SetShotDataA(31,a*6,1,ang,0,0,2,BLUE12);
AddShot(a,359,31,0);
CreateShotA(32,0,0,20);
SetShotDataA(32,0,0.7,ang2+180,0,0,2,RED12);
SetShotDataA(32,a*6,1,ang2,0,0,2,RED12);
AddShot(a,358,32,0);
a=a+4;}

FireShot(359);
FireShot(358);
}



}
task HOR{
 let angle   = 90;
  let objShot = NULL;
  let objShot2 = NULL;
  let objShot3 = NULL;
  let objShot4 = NULL;
  let a =180;


sub henka{
shot4;
		
			
               loop(T){let a1=atan2(GetPlayerY()-Obj_GetY(objShot), GetPlayerX()-Obj_GetX(objShot));
                        let a2=atan2(GetPlayerY()-Obj_GetY(objShot2), GetPlayerX()-Obj_GetX(objShot2));
                        let a3=atan2(GetPlayerY()-Obj_GetY(objShot3), GetPlayerX()-Obj_GetX(objShot3));
                        let a4=atan2(GetPlayerY()-Obj_GetY(objShot4), GetPlayerX()-Obj_GetX(objShot4));		
			Obj_SetAngle(objShot, a1);
                        Obj_SetAngle(objShot2, a2);
			Obj_SetAngle(objShot3, a3);
                        Obj_SetAngle(objShot4,a4); 
                        Obj_SetSpeed(objShot, 1.2);  
                        Obj_SetSpeed(objShot2, 1.2);  
                        Obj_SetSpeed(objShot3, 1.2);  
                        Obj_SetSpeed(objShot4, 1.2);                       
                  yield;}


                       }
          
sub shot2{ 
        Obj_BeDeleted(objShot); 
       let aaa=90;
 if(Obj_BeDeleted(objShot)==false){       Obj_SetSpeed(objShot, 0);     
  loop(1){loop(3){     loop(10){
      CreateShot02(Obj_GetX(objShot),Obj_GetY(objShot),5,aaa,-0.1,2,RED21,0);
      aaa=aaa+36;}wait(1);aaa=aaa+7; }wait(10);}
       Obj_Delete(objShot); }

  if(Obj_BeDeleted(objShot2)==false){      Obj_SetSpeed(objShot2, 0);     
  loop(1){loop(3){     loop(10){
      CreateShot02(Obj_GetX(objShot2),Obj_GetY(objShot2),5,aaa,-0.1,2,YELLOW21,0);
      aaa=aaa+36;}wait(1);aaa=aaa+7; }wait(10);}
       Obj_Delete(objShot2);    }

 if(Obj_BeDeleted(objShot3)==false){       Obj_SetSpeed(objShot3, 0);     
  loop(1){loop(3){     loop(10){
      CreateShot02(Obj_GetX(objShot3),Obj_GetY(objShot3),5,aaa,-0.1,2,GREEN21,0);
      aaa=aaa+36;}wait(1);aaa=aaa+7; }wait(10);}
       Obj_Delete(objShot3);    } 

 if(Obj_BeDeleted(objShot4)==false){       Obj_SetSpeed(objShot4, 0);     
  loop(1){loop(3){     loop(10){
      CreateShot02(Obj_GetX(objShot4),Obj_GetY(objShot4),5,aaa,-0.1,2,AQUA21,0);
      aaa=aaa+36;}wait(1);aaa=aaa+7; }wait(10);}
       Obj_Delete(objShot4); }
          
             
}
			
          

  
 sub shot{  
                objShot = Obj_Create(OBJ_SHOT);
		Obj_SetX(objShot, GetCenterX+150);
		Obj_SetY(objShot, GetClipMinY);
		Obj_SetSpeed(objShot, 10);
		ObjShot_SetGraphic(objShot, RED02);                
                Obj_SetAngle(objShot,90);

Obj_SetSpeed(objShot, 0);

    a=a+rand(30,90);
                objShot2 = Obj_Create(OBJ_SHOT);
		Obj_SetX(objShot2, GetCenterX-150);
		Obj_SetY(objShot2, GetClipMinY);
		Obj_SetSpeed(objShot2, 10);
		ObjShot_SetGraphic(objShot2, YELLOW02);                
                Obj_SetAngle(objShot2, 90); 

Obj_SetSpeed(objShot2, 0);

   a=a+rand(30,90);
                objShot3 = Obj_Create(OBJ_SHOT);
		Obj_SetX(objShot3, GetCenterX+150);
		Obj_SetY(objShot3, GetClipMaxY);
		Obj_SetSpeed(objShot3, 10);
		ObjShot_SetGraphic(objShot3, GREEN02);                
                Obj_SetAngle(objShot3, 90 );

Obj_SetSpeed(objShot3, 0); 

            a=a+rand(30,90);
                objShot4 = Obj_Create(OBJ_SHOT);
		Obj_SetX(objShot4, GetCenterX-150);
		Obj_SetY(objShot4, GetClipMaxY);
		Obj_SetSpeed(objShot4, 10);
		ObjShot_SetGraphic(objShot4, AQUA02);                
                Obj_SetAngle(objShot4, 90); 

Obj_SetSpeed(objShot4, 0);

            a=a+rand(30,90);


   }
task shot4{
yield; 
let aaaa=135;
let aaaa2=45;
let aaaa3=225;
let aaaa4=315;

loop{
yield;
 loop(T/5) { 
 if(Obj_BeDeleted(objShot)==false){       
      CreateShot02(Obj_GetX(objShot),Obj_GetY(objShot),4,aaaa,-0.1,2,RED12,0);
      aaaa=aaaa+5; }
 if(Obj_BeDeleted(objShot2)==false){            
      CreateShot02(Obj_GetX(objShot2),Obj_GetY(objShot2),4,aaaa2,-0.1,2,YELLOW12,0);
      aaaa2=aaaa2-5; }
 if(Obj_BeDeleted(objShot3)==false){          
      CreateShot02(Obj_GetX(objShot3),Obj_GetY(objShot3),4,aaaa3,-0.1,2,GREEN12,0);
      aaaa3=aaaa3-5; }
 if(Obj_BeDeleted(objShot4)==false){           
      CreateShot02(Obj_GetX(objShot4),Obj_GetY(objShot4),4,aaaa4,-0.1,2,AQUA12,0);
      aaaa4=aaaa4+5; }        

        
 wait(5);}
return;
}
}
     shot;
     henka;
     shot2;
      wait(30);

}


   sub setGraphicStop  { SetGraphicRect(  0,   0,  64,  128); }
    task setGraphicPose  {loop(50){ SetGraphicRect( 192,   0, 256,  128);yield;} }
    task setGraphicPose2  {loop(50){ SetGraphicRect( 0,   128, 64,  256);yield;} }
    task setGraphicPose3  {loop(30){ SetGraphicRect( 64,   128, 128,  256);yield;} }
    task setGraphicPose4  {loop(300){ SetGraphicRect( 64,   128, 128,  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;}
         }
    }






}}