script_enemy_main {
    let time = 0;
    let phase = 1;
    let rate = 0;
    let life = 0;
    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( 350 );
        SetInvincibility( 60 );
        LoadGraphic( imgEnemy );
        LoadUserShotData( tama );
        SetX(mapx-GetCommonData("bgx"));
        SetY(GetCommonData("bgy")-mapy);
        if(arg==0){
        }
        else{setmove(angle,arg);}
        Tshot1;
        Tshot2;
    }
    @MainLoop {
        rate=life-GetLife;
        life=GetLife;
        if(phase==1&&GetLife<=100){
           phase-=1;
           PlaySE(se2);
           Tdeath(14,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(rate%1>0){Tkunsyon(10,2);}
        }
        if(time>240&&GetY>500){VanishEnemy;}
        if(time>1000){VanishEnemy;}
        if(phase>=1){SetCollisionA(GetX()+cos(angle)*40, GetY()+sin(angle)*40, 35);}
        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,angle);
	DrawGraphic( GetX()+cos(angle)*30, GetY()+sin(angle)*30 );
        SetGraphicRect( 128, 1, 256, 128 );
        SetGraphicAngle(0,0,GetAngleToPlayer()-GetAngleToPlayer()%12+6);
	DrawGraphic( GetX(), GetY() );
    }

    task Tshot1{
        yield;
        wait(80);
        loop{
           if(GetX>32&&GetX<416&&GetY>16&&GetY<300){
              if(phase==0){return;}
              let p=GetAngleToPlayer();
              SetShotDirectionType(ABSOLUTE);
              let a=0;
              let b=0;
              loop(20){
                 CreateShotFromScript( "shot1",GetX()+cos(a*100)*b, GetY()+sin(a*100)*b*0.7, 2.3+ex, p, 0, 04);
                 a++;
                 b+=1.4-a*0.06;
              }
           }
           wait(70-lv*12);
        }
    }
    task Tshot2{
        yield;
        wait(130);
        loop{
           if(GetX>32&&GetX<416&&GetY>16&&GetY<280){
              let p1=atan2( GetPlayerY()-(GetY()+35), GetPlayerX()-(GetX()+16));
              let p2=atan2( GetPlayerY()-(GetY()+35), GetPlayerX()-(GetX()-16));
              loop(5+rank){
                 if(phase==0){return;}
                 let a=-1-rank/4;
                 loop(3+rank/2+ex){
                    CreateShotFromScript( "shot1",GetX()+16, GetY()+35, 3.3+ex, p1-a*11, 0, 12);
                    CreateShotFromScript( "shot1",GetX()-16, GetY()+35, 3.3+ex, p2+a*11, 0, 12);
                    a++;
                 }
              wait(5);
              }
           }
           wait(90-lv*16);
        }
    }
   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"