script_enemy_main {
    let time = 0;
    let phase = 1;
    let rate = 7;
    let kaku = 40;
    let score = 1600;
    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\tank1.png";
    let tama = GetCurrentScriptDirectory~"tama.txt";
    let se1 = GetCurrentScriptDirectory~"wav\se1.wav";
    let se2 = GetCurrentScriptDirectory~"wav\se2.wav";
    @Initialize(){
        SetLife( 340 );
        SetInvincibility( 60 );
        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 {
        if(phase==1&&GetLife<=100){
           phase-=1;
           if(lv==0||GetPoint>0){DeleteEnemyShotImmediatelyInCircle(SHOT, GetX, GetY+30, 64);}
           PlaySE(se2);
           Tdeath(14,64,2,1);
        }
        if(time>240&&GetY>500){VanishEnemy;}
        if(time>1000){VanishEnemy;}
        if(phase>=1){SetCollisionA(GetX(), GetY(), 60);}
        SetX(mapx-GetCommonData("bgx"));
        SetY(GetCommonData("bgy")-mapy);
        if(GetCommonData("kakusei")>0){lv=1}
        else{lv=0}
        time++;
        yield;
    }
    @Finalize() {
    }
    @DrawLoop {
	SetTexture( imgEnemy );
        SetGraphicRect( 1, 1, 156, 120 );
        SetGraphicAngle(0,0,0);
	DrawGraphic( GetX(), GetY()+10 );
        SetGraphicRect( 192, 0, 272, 80 );
        SetGraphicAngle(0,30,genteikaku(GetAngleToPlayer,16));
	DrawGraphic( GetX(), GetY() );
    }

    task Tshot1{
        yield;
        wait(30);
        loop{
           if(GetX>32&&GetX<416&&GetY>25&&GetY<300){
              SetShotDirectionType(ABSOLUTE);
              let a=0;
              loop(5+rank/2){
                 if(phase==0){return;}
                 CreateShotFromScript( "shot1",GetX()+cos(angle)*38, GetY()+sin(angle)*30, 2.3+ex, 90, 0, 12);
                 CreateShotFromScript( "shot1",GetX()+cos(angle+180)*38, GetY()+sin(angle+180)*30, 2.3+ex, 90, 0, 12);
                 a++;
                 wait(4);
              }
           }
           if(lv==0){wait(20-rank*3);}
           wait(15);
        }
    }
    task Tshot2{
        yield;
        wait(30);
        loop{
           if(GetX>32&&GetX<416&&GetY>16&&GetY<280){
              loop(10+rank*3){
                 if(phase==0){return;}
                 let a=0;
                 let p=genteikaku(GetAngleToPlayer,16);
                 loop(1+ex){
                    CreateShotFromScript( "shot1",GetX()+cos(p+10)*30, GetY()+sin(p+10)*22, 3+a, p, 0, 04);
                    CreateShotFromScript( "shot1",GetX()+cos(p-0)*30, GetY()+sin(p-0)*22, 3+a, p, 0, 04);
                    CreateShotFromScript( "shot1",GetX()+cos(p-10)*30, GetY()+sin(p-10)*22, 3+a, p, 0, 04);
                    a++;
                 }
              wait(3);
              }
           }
           if(lv==0){wait(40-rank*6);}
           wait(10);
        }
    }
    task Tmove1{
        let a=angle;
        angle=90;
        yield;
        SetMovePosition02( GetX(), GetY()+500, 800);
        wait(800);
        VanishEnemy;
    }
    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"