script_enemy_main {
    let time = 0;
    let phase = 1;
    let rate = 10;
    let kaku = 40;
    let score = 5000;
    let layer = 1;
    let bairitu = 1;
    let lv = 0;
    let angle = GetAngle();
    let rank = GetSpeed();
    let arg = GetArgument();
    let ex = GetCommonData("ex");
    let mapx = GetX();
    let mapy = GetY();
    let imgEnemy = GetCurrentScriptDirectory~"img\senkan1.png";
    let tama = GetCurrentScriptDirectory~"tama.txt";
    let se1 = GetCurrentScriptDirectory~"wav\se1.wav";
    let se2 = GetCurrentScriptDirectory~"wav\se2.wav";
    @Initialize(){
        SetLife( 450 );
        SetInvincibility( 60 );
        LoadGraphic( imgEnemy );
        LoadUserShotData( tama );
        SetX(mapx-GetCommonData("bgx"));
        SetY(GetCommonData("bgy")-mapy);
    }
    @MainLoop {
        if(time==1){
           CreateEnemyFromScript( "dodai", mapx, mapy, 0, 0, 0);
           CreateEnemyFromScript( "parts3", mapx, mapy-100, rank, 0, 0);
           CreateEnemyFromScript( "parts1", mapx+55, mapy-50, rank, 0, 0);
           CreateEnemyFromScript( "parts1", mapx-55, mapy-50, rank, 0, 0);
           CreateEnemyFromScript( "parts3", mapx, mapy+10, rank, 0, 0);
           CreateEnemyFromScript( "parts1", mapx+55, mapy+50, rank, 0, 0);
           CreateEnemyFromScript( "parts1", mapx-55, mapy+50, rank, 0, 0);
           //CreateEnemyFromScript( "parts3", mapx, mapy+60, rank, 0, 0);
           CreateEnemyFromScript( "parts1", mapx+95, mapy+125, rank, 0, 0);
           CreateEnemyFromScript( "parts1", mapx-95, mapy+125, rank, 0, 0);
        }
        if(phase==1&&GetLife<=100){
           phase-=1;
           VanishEnemy;
        }
        if(GetX<12||GetX>436||GetY<140){
           SetInvincibility( 5 );
        }
        if(time>1010){VanishEnemy;}
       if(phase>=1){SetCollisionA(GetX, GetY-120, 48);}
        SetX(mapx-GetCommonData("bgx"));
        SetY(GetCommonData("bgy")-mapy);
        if(GetCommonData("kakusei")>0){lv=1}
        else{lv=0}
        time++;
        yield;
    }
    @Finalize() {
    }
    @DrawLoop {
    }


   task setmove(a,t) {
      loop(t) {
         mapx+=cos(a)*0.6;mapy-=sin(a)*0.6;
         yield;
      }
   }

    #include_function".\efanction.txt"
}
script_enemy parts1 {
   let time = 0;
   let phase = 1;
   let rate = 2;
   let kaku = 10;
   let score = 180;
   let lv = 0;
   let angle = GetAngle();
   let rank = GetSpeed();
   let arg = GetArgument();
   let ex = GetCommonData("ex");
   let mapx = GetX();
   let mapy = GetY();
   let imgEnemy = GetCurrentScriptDirectory~"img\senkan1.png";
   let tama = GetCurrentScriptDirectory~"tama.txt";
   let se1 = GetCurrentScriptDirectory~"wav\se1.wav";
   let se3 = GetCurrentScriptDirectory~"wav\se3.wav";
   @Initialize(){
       SetLife( 115 );
       SetInvincibility( 10 );
       LoadGraphic( imgEnemy );
       LoadUserShotData( tama );
       SetX(mapx-GetCommonData("bgx"));
       SetY(GetCommonData("bgy")-mapy);
       Tshot;
   }
   @MainLoop {
   	if(BeParentVanished==true){
   		VanishEnemy();
   	}
       if(phase==1&&GetLife<=100){
          phase-=1;
          if(lv==0||GetPoint>0){DeleteEnemyShotImmediatelyInCircle(SHOT, GetX, GetY, 30);}
          PlaySE(se3);
          Tdeath(4,24,2,1);
       }
       if(GetX<12||GetX>436||GetY<40){
          SetInvincibility( 5 );
       }
       if(time>240&&GetY>500){VanishEnemy;}
       if(time>1000){VanishEnemy;}
       if(phase>=1){SetCollisionA(GetX, GetY, 24);}
       SetX(mapx-GetCommonData("bgx"));
       SetY(GetCommonData("bgy")-mapy);
       if(GetCommonData("kakusei")>0){lv=1}
       else{lv=0}
       time++;
       yield;
   }
   @Finalize() {
   }
   @DrawLoop {
	SetTexture( imgEnemy );
       SetGraphicRect( 256, 80, 336, 144 );
	DrawGraphic( GetX(), GetY() );
   }

   task Tshot{
      yield;
      wait(40+GetCommonData("ransu")%4*10);
      SetCommonData("ransu",GetCommonData("ransu")+1);
      loop{
         if(GetX>32&&GetX<416&&GetY>16&&GetY<(300+rank*20)){
            let p=genteikaku(GetAngleToPlayer(),40);
            let a=-0.5;
            loop(2+ex){
               if(phase<=0){return;}
               CreateShotFromScript( "shot1",GetX(), GetY(), 2.5, p+a*20, 0, 06);
               a++;
            }
         }
         wait(8-rank*4);
      }
   }


   #include_function".\efanction.txt"
}
script_enemy parts2 {
   let time = 0;
   let phase = 1;
   let rate = 4;
   let kaku = 10;
   let score = 180;
   let lv = 0;
   let angle = GetAngle();
   let rank = GetSpeed();
   let arg = GetArgument();
   let ex = GetCommonData("ex");
   let mapx = GetX();
   let mapy = GetY();
   let imgEnemy = GetCurrentScriptDirectory~"img\train.png";
   let tama = GetCurrentScriptDirectory~"tama.txt";
   let se1 = GetCurrentScriptDirectory~"wav\se1.wav";
   let se3 = GetCurrentScriptDirectory~"wav\se3.wav";
   @Initialize(){
       SetLife( 200 );
       SetInvincibility( 10 );
       LoadGraphic( imgEnemy );
       LoadUserShotData( tama );
       SetX(mapx-GetCommonData("bgx"));
       SetY(GetCommonData("bgy")-mapy);
       Tshot;
   }
   @MainLoop {
   	if(BeParentVanished==true){
   		VanishEnemy();
   	}
      if(phase==1&&GetLife<=100){
         phase-=1;
         if(lv==0||GetPoint>0){DeleteEnemyShotImmediatelyInCircle(SHOT, GetX, GetY, 40);}
         PlaySE(se3);
         Tdeath(6,24,2,1);
      }
      if(GetX<12||GetX>436||GetY<40){
         SetInvincibility( 5 );
      }
      if(time>240&&GetY>500){VanishEnemy;}
      if(time>1000){VanishEnemy;}
      if(phase>=1){SetCollisionA(GetX, GetY, 32);}
      SetX(mapx-GetCommonData("bgx"));
      SetY(GetCommonData("bgy")-mapy);
      if(GetCommonData("kakusei")>0){lv=1}
      else{lv=0}
      time++;
      yield;
   }
   @Finalize() {
   }
   @DrawLoop {
	SetTexture( imgEnemy );
      SetGraphicRect( 144, 64, 224, 96 );
      SetGraphicAngle(0,0,0);
	DrawGraphic( GetX(), GetY() );
   }

   task Tshot{
      yield;
      let a=0;
      loop{
         if(GetY>16&&GetY<(300+rank*20)){
         	loop(6){
            	let b=-1.5-ex;
            	loop(4+rank*2){
            	   if(phase<=0){return;}
            	   CreateShotFromScript( "shot1",GetX(), GetY(), 2.6+ex, 90+b*40, 0, 13);
         	      b++;
            	}
         		wait(3);
         	}
         }
         a++;
         wait(30-lv*15);
      }
   }


    #include_function".\efanction.txt"
}
script_enemy parts3 {
   let time = 0;
   let phase = 1;
   let rate = 7;
   let kaku = 10;
   let score = 180;
   let lv = 0;
   let angle = GetAngle();
   let rank = GetSpeed();
   let arg = GetArgument();
   let ex = GetCommonData("ex");
   let mapx = GetX();
   let mapy = GetY();
   let imgEnemy = GetCurrentScriptDirectory~"img\senkan1.png";
   let tama = GetCurrentScriptDirectory~"tama.txt";
   let se1 = GetCurrentScriptDirectory~"wav\se1.wav";
   let se2 = GetCurrentScriptDirectory~"wav\se2.wav";
   @Initialize(){
       SetLife( 180 );
       SetInvincibility( 10 );
       LoadGraphic( imgEnemy );
       LoadUserShotData( tama );
       SetX(mapx-GetCommonData("bgx"));
       SetY(GetCommonData("bgy")-mapy);
       Tshot;
   }
   @MainLoop {
   	if(BeParentVanished==true){
   		VanishEnemy();
   	}
      if(phase==1&&GetLife<=100){
         phase-=1;
         if(lv==0||GetPoint>0){DeleteEnemyShotImmediatelyInCircle(SHOT, GetX, GetY, 40);}
         PlaySE(se2);
         Tdeath(8,32,2,1);
      }
      if(GetX<12||GetX>436||GetY<40){
         SetInvincibility( 5 );
      }
      if(time>240&&GetY>500){VanishEnemy;}
      if(time>1000){VanishEnemy;}
      if(phase>=1){SetCollisionA(GetX, GetY, 40);}
      SetX(mapx-GetCommonData("bgx"));
      SetY(GetCommonData("bgy")-mapy);
      if(GetCommonData("kakusei")>0){lv=1}
      else{lv=0}
      time++;
      yield;
   }
   @Finalize() {
   }
   @DrawLoop {
	SetTexture( imgEnemy );
      SetGraphicRect( 256, 0, 352, 80 );
      SetGraphicAngle(0,0,0);
	DrawGraphic( GetX(), GetY() );
   }

   task Tshot{
      yield;
      SetCommonData("ransu",GetCommonData("ransu")+1);
      wait(40+GetCommonData("ransu")%4*10);
      loop{
         if(GetX>32&&GetX<416&&GetY>16&&GetY<(300+rank*20)){
            let a=0;
         	let p=genteikaku(GetAngleToPlayer,32);
            loop(8+rank){
               if(phase<=0){return;}
               let b=-1-ex;
               loop(3+ex*2){
                  CreateShotFromScript( "shot1",GetX()+3, GetY(), 3.5+ex, p+b*(30-ex*6), 0, 11);
                  CreateShotFromScript( "shot1",GetX(), GetY(), 3.5+ex, p+b*(30-ex*6), 0, 11);
                  CreateShotFromScript( "shot1",GetX()-3, GetY(), 3.5+ex, p+b*(30-ex*6), 0, 11);
                  b++;
               }
               a++;
               wait(4-lv*1);
            }
         }
         wait(40-lv*30);
      }
   }


   #include_function".\efanction.txt"
}

script_enemy dodai {
   let time = 0;
   let phase = 1;
   let rate = 10;
   let kaku = 40;
   let score = 5000;
   let layer = 1;
   let bairitu = 1;
   let lv = 0;
   let angle = GetAngle();
   let rank = GetSpeed();
   let arg = GetArgument();
   let ex = GetCommonData("ex");
   let mapx = GetX();
   let mapy = GetY();
   let imgEnemy = GetCurrentScriptDirectory~"img\senkan1.png";
   let tama = GetCurrentScriptDirectory~"tama.txt";
   let se3 = GetCurrentScriptDirectory~"wav\se3.wav";
   let se2 = GetCurrentScriptDirectory~"wav\se2.wav";
   @Initialize(){
       SetLife( 400 );
       SetInvincibility( 60 );
       LoadGraphic( imgEnemy );
       LoadUserShotData( tama );
       SetX(mapx-GetCommonData("bgx"));
       SetY(GetCommonData("bgy")-mapy);
       Tgazou(1,1,256,368);
   }
   @MainLoop {
      if(BeParentVanished==true&&phase==1){
         phase-=1;
         Tdeath(12,70,1,0);
         Tbaku;Toti;
      }
      if(time>1000){VanishEnemy;}
      SetX(mapx-GetCommonData("bgx"));
      SetY(GetCommonData("bgy")-mapy);
      if(GetCommonData("kakusei")>0){lv=1}
      else{lv=0}
      time++;
      yield;
    }
    @Finalize() {
    }
    @DrawLoop {
    }


   task setmove(a,t) {
      loop(t) {
         mapx+=cos(a)*0.6;mapy-=sin(a)*0.6;
         yield;
      }
   }
   task Tgazou(x1,y1,x2,y2)
   {
      let system = GetCurrentScriptDirectory~"img\system.png";
      let objenemy = Obj_Create(OBJ_EFFECT);//GtFNgIuWFNg쐬
      ObjEffect_SetTexture(objenemy, imgEnemy);//Ȃ炩̃eNX`ݒ
      ObjEffect_SetPrimitiveType(objenemy, PRIMITIVE_TRIANGLESTRIP);//v~eBu^Cvݒ
      ObjEffect_CreateVertex(objenemy, 4);//_4
      ObjEffect_SetLayer(objenemy,layer);
		
      //lp`Ɋe_̍Wݒ
      ObjEffect_SetVertexXY(objenemy, 0, -(x2-x1)*bairitu/2, -(y2-y1)*bairitu/2);
      ObjEffect_SetVertexXY(objenemy, 1, -(x2-x1)*bairitu/2,  (y2-y1)*bairitu/2);
      ObjEffect_SetVertexXY(objenemy, 2,  (x2-x1)*bairitu/2, -(y2-y1)*bairitu/2);
      ObjEffect_SetVertexXY(objenemy, 3,  (x2-x1)*bairitu/2,  (y2-y1)*bairitu/2);
		
      //lp`Ɋe_UVlݒB(0,0)-(10,10)̕B
      ObjEffect_SetVertexUV(objenemy, 0, x1, y1);
      ObjEffect_SetVertexUV(objenemy, 1, x1, y2);
      ObjEffect_SetVertexUV(objenemy, 2, x2, y1);
      ObjEffect_SetVertexUV(objenemy, 3, x2, y2);

      Obj_SetPosition(objenemy, GetX, GetY);
   
		
      loop{
         ObjEffect_SetVertexXY(objenemy, 0, -(x2-x1)*bairitu/2, -(y2-y1)*bairitu/2);
         ObjEffect_SetVertexXY(objenemy, 1, -(x2-x1)*bairitu/2,  (y2-y1)*bairitu/2);
         ObjEffect_SetVertexXY(objenemy, 2,  (x2-x1)*bairitu/2, -(y2-y1)*bairitu/2);
         ObjEffect_SetVertexXY(objenemy, 3,  (x2-x1)*bairitu/2,  (y2-y1)*bairitu/2);
         Obj_SetX(objenemy,GetX);
         Obj_SetY(objenemy,GetY);
         yield;
      }
      Obj_Delete(objenemy);
   }
   task Toti{
      layer=1;
      let a=0;
      loop(80){
         if(lv==0||GetPoint>0){DeleteEnemyShotImmediatelyInCircle(SHOT, 224, 240, 600);}
         if(a%10==0){
        		PlaySE(se3);
         }
         bairitu=1-a/80*0.3;
         a++;
         yield;
      }
      Explosion01(GetX,GetY,4,0.2,50);
      PlaySE(se2);
      VanishEnemy();
   }


    #include_function".\efanction.txt"
}

#include_script".\escript.txt"