script_enemy_main {
    let time = 0;
    let phase = 1;
    let rate = 0;
    let life = 0;
    let kaku = 40;
    let score = 1200;
    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\tank2.png";
    let tama = GetCurrentScriptDirectory~"tama.txt";
    let se1 = GetCurrentScriptDirectory~"wav\se1.wav";
    let se2 = GetCurrentScriptDirectory~"wav\se2.wav";
    @Initialize(){
        SetLife( 400 );
        SetInvincibility( 130 );
        LoadGraphic( imgEnemy );
        LoadUserShotData( tama );
        SetX(mapx-GetCommonData("bgx"));
        SetY(GetCommonData("bgy")-mapy);
        if(arg==0){
           if( (|angle|) ==1){Tmove1;}
           if( (|angle|) ==2){Tmove2;}
           if( (|angle|) ==3){Tmove3;}
        }
        else{setmove(angle,arg);}
        Tshot1;Tshot2;
    }
    @MainLoop {
        rate=life-GetLife;
        life=GetLife;
        if(phase==1&&GetLife<=100){
           phase-=1;
           PlaySE(se2);
           Tdeath(12,64,2,1);
           DeleteEnemyShotImmediatelyInCircle(SHOT, 224, 240, 600);
           CreateEnemyFromFile(GetCurrentScriptDirectory~"landitem.txt",mapx+20,mapy-10, 0, 0, 2);
           CreateEnemyFromFile(GetCurrentScriptDirectory~"landitem.txt",mapx+20,mapy-40, 0, 0, 2);
           CreateEnemyFromFile(GetCurrentScriptDirectory~"landitem.txt",mapx-20,mapy-10, 0, 0, 2);
           CreateEnemyFromFile(GetCurrentScriptDirectory~"landitem.txt",mapx-20,mapy-40, 0, 0, 2);
        }
        if(time>240&&GetY>500){VanishEnemy;}
        if(time>1000){VanishEnemy;}
        if(phase>=1){SetCollisionA(GetX(), GetY(), 45);}
        SetX(mapx-GetCommonData("bgx"));
        SetY(GetCommonData("bgy")-mapy);
        lv=GetCommonData("rank");
        time++;
        yield;
    }
    @Finalize() {
    }
    @DrawLoop {
	SetTexture( imgEnemy );
        SetGraphicRect( 1, 1, 128, 128 );
        SetGraphicAngle(0,0,0);
	DrawGraphic( GetX(), GetY());
    }

    task Tshot1{
        yield;
        wait(120);
        loop{
           if(GetX>32&&GetX<416&&GetY>16&&GetY<320){
              loop(1){
                 let p1=atan2( GetPlayerY()-(GetY()), GetPlayerX()-(GetX()+25));
                 let p2=atan2( GetPlayerY()-(GetY()), GetPlayerX()-(GetX()-25));
                 SetShotDirectionType(ABSOLUTE);
                 let a=0;
                 loop(12){
                    if(phase==0){return;}
                    CreateShotFromScript( "shot3",GetX()+20+a%3*6, GetY()+int(a/3)*8-12, 0.04+ex*0.02, p1, 0, 06);
                    CreateShotFromScript( "shot3",GetX()-20-a%3*6, GetY()+int(a/3)*8-12, 0.04+ex*0.02, p2, 0, 06);
                    if(ex==1){
                       CreateShotFromScript( "shot3",GetX()+20+a%3*6, GetY()+int(a/3)*8-12, 0.04+ex*0.02, p1-20, 0, 06);
                       CreateShotFromScript( "shot3",GetX()-20-a%3*6, GetY()+int(a/3)*8-12, 0.04+ex*0.02, p2+20, 0, 06);
                    }
                    a++;
                    wait(2);
                 }
              }
           }
           wait(32-lv*6);
        }
    }
    task Tshot2{
        yield;
        wait(130);
        loop{
           if(GetX>32&&GetX<416&&GetY>16&&GetY<300){
              let p=GetAngleToPlayer();
              p+=-p%6+3;
              if(phase==0){return;}
              let a=-3;
              loop(7){
                 CreateShotFromScript( "shot1",GetX(), GetY(), 2.5+ex*0.5, p+a*16-ex, 0, 12);
                 if(ex==1){CreateShotFromScript( "shot1",GetX(), GetY(), 3, p+a*16+1, 0, 12);}
                 a++;
              }
           }
           wait(65-lv*10);
        }
    }
    task Tmove1{
        setmove(90,90);
        wait(90);
        setmove(-90,90);
        wait(90);
    }
    task Tmove2{
        let a=angle;
        a/=2;
        angle=90;
        yield;
        SetMovePosition02( GetX(), GetY()+120, 80);
        wait(80);
        SetMovePosition02( GetX()-24*a, GetY()+35, 30);
        angle=90+45*a;
        wait(30);
        SetMovePosition02( GetX()-1000*a, GetY+500, 1000);
        angle=90+90*a;
    }
    task Tmove3{
        let a=angle;
        a/=3;
        angle=90*a;
        yield;
        SetMovePosition02( GetX()-100, GetY()+200*a, 200);
        wait(200);
        SetMovePosition02( GetX()-35, GetY()+24*a, 30);
        angle=180-45*a;
        wait(30);
        SetMovePosition02( GetX()-600, GetY(), 400);
        angle=180;
    }

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



    #include_function".\efanction.txt"
}

#include_script".\escript.txt"