script_enemy_main {
    let time = 0;
    let phase = 1;
    let rate = 6;
    let kaku = 40;
    let score = 1800;
    let lv = 0;
    let ex = GetCommonData("ex");
    let angle = GetAngle();
    let rank = GetSpeed();
    let arg = GetArgument();
    let mapx = GetX();
    let mapy = GetY();
    let imgEnemy = GetCurrentScriptDirectory~"img\tank4.png";
    let tama = GetCurrentScriptDirectory~"tama.txt";
    let se1 = GetCurrentScriptDirectory~"wav\se1.wav";
    let se2 = GetCurrentScriptDirectory~"wav\se2.wav";
    @Initialize(){
        SetLife( 450 );
        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 {
        if(phase==1&&GetLife<=100){
           phase-=1;
           if(lv==0||GetPoint>0){DeleteEnemyShotImmediatelyInCircle(SHOT, GetX, GetY, 64);}
           PlaySE(se2);
           Tdeath(12,64,2,1);
        }
        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);
        if(GetCommonData("kakusei")>0){lv=1}
        else{lv=0}
        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(4+rank/2+ex*1){
                    if(phase==0){return;}
                    CreateShotFromScript( "shot1",GetX()+20, GetY(), 1+a/4, p1+sin((a+time)*113)*30, 0, 03);
                    CreateShotFromScript( "shot1",GetX()-20, GetY(), 1+a/4, p2-sin((a+time)*113)*30, 0, 03);
                    a++;
                 }
              }
           }
           if(lv==0){wait(32-rank*5);}
           wait(10);
        }
    }
    task Tshot2{
        yield;
        wait(130);
        loop{
           if(GetX>32&&GetX<416&&GetY>16&&GetY<300){
              let p=GetAngleToPlayer();
              p+=-p%12+6;
              let a=0;
              loop(3+rank/2){
                 if(phase==0){return;}
                 CreateShotFromScript( "shot1",GetX(), GetY(), 2.8+ex, p+6, 0, 13);
                 CreateShotFromScript( "shot1",GetX(), GetY(), 2.8+ex, p, 0, 13);
                 CreateShotFromScript( "shot1",GetX(), GetY(), 2.8+ex, p-6, 0, 13);
                 a++;
                 wait(4);
              }
           }
           if(lv==0){wait(45-rank*5);}
           wait(6);
        }
    }
    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"