script_enemy_main {
    let time = 0;
    let phase = 1;
    let rate = 6;
    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( 500 );
        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(12){
                    if(phase==0){return;}
                    CreateShotFromScript( "shot3",GetX()+20+a%3*6, GetY()+int(a/3)*8-12, 0.06+ex*0.03, p1, 0, 06);
                    CreateShotFromScript( "shot3",GetX()-20-a%3*6, GetY()+int(a/3)*8-12, 0.06+ex*0.03, p2, 0, 06);
                    if(ex==1){
                       CreateShotFromScript( "shot3",GetX()+20+a%3*6, GetY()+int(a/3)*8-12, 0.06+ex*0.03, p1-20, 0, 06);
                       CreateShotFromScript( "shot3",GetX()-20-a%3*6, GetY()+int(a/3)*8-12, 0.06+ex*0.03, p2+20, 0, 06);
                    }
                    a++;
                    wait(2);
                 }
              }
           }
           if(lv==0){wait(15-rank*3);}
           wait(1);
        }
    }
    task Tshot2{
        yield;
        wait(130);
        loop{
           if(GetX>32&&GetX<416&&GetY>16&&GetY<300){
              let p=GetAngleToPlayer();
              p+=-p%12+6;
              if(phase==0){return;}
              let a=-(6+rank)/2;
              loop(7+rank){
                 CreateShotFromScript( "shot1",GetX(), GetY(), 2.5+ex*0.5, p+a*(10-rank), 0, 12);
                 if(ex==1){CreateShotFromScript( "shot1",GetX(), GetY(), 4, p+a*(10-rank), 0, 12);}
                 a++;
              }
           }
           if(lv==0){wait(35-rank*7);}
           wait(35);
        }
    }
    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"