script_enemy_main {
    let time = 0;
    let phase = 1;
    let rate = 7;
    let kaku = 40;
    let score = 1000;
    let lv = 0;
    let angle = GetAngle();
    let ex = GetCommonData("ex");
    let rank = GetSpeed()+ex*2;
    let arg = GetArgument();
    let mapx = GetX();
    let mapy = GetY();
    let imgEnemy = GetCurrentScriptDirectory~"img\tank3.png";
    let tama = GetCurrentScriptDirectory~"tama.txt";
    let se1 = GetCurrentScriptDirectory~"wav\se1.wav";
    let se2 = GetCurrentScriptDirectory~"wav\se2.wav";
    @Initialize(){
        SetLife( 400 );
        SetInvincibility( 90 );
        LoadGraphic( imgEnemy );
        LoadUserShotData( tama );
        SetX(mapx-GetCommonData("bgx"));
        SetY(GetCommonData("bgy")-mapy);
        Tshot1;
    }
    @MainLoop {
        if(phase==1&&GetLife<=100){
           phase-=1;
           if(lv==0||GetPoint>0){DeleteEnemyShotImmediatelyInCircle(SHOT, GetX, GetY, 64);}
           PlaySE(se2);
           Tdeath(14,64,2,1);
        }
        if(time>240&&GetY>500){VanishEnemy;}
        if(time>1500){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());
        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<320){
              if(phase==0){return;}
              let p=GetAngleToPlayer();
              SetShotDirectionType(ABSOLUTE);
              let a=-3-rank/2;
              loop(7+rank){
                 CreateShotFromScript( "shot1",GetX()+cos(p)*20, GetY()+sin(p)*20, 2+ex, p+a*4, 0, 05);
                 a++;
              }
           }
           if(lv==0){wait(30-rank*4);}
           wait(30-rank*2);
        }
    }
    task Tshot2{
        yield;
        wait(90);
        loop{
           if(GetX>32&&GetX<416&&GetY>16&&GetY<360){
              let p1=atan2( GetPlayerY()-(GetY()+35), GetPlayerX()-(GetX()+16));
              let a=0;
              loop(5+rank){
                 if(phase==0){return;}
                 loop(1){
                    CreateShotFromScript( "shot1",GetX()+16, GetY()+35, 3.8-a/4+ex, p1-p1%8+4-a*2, 0, 03);
                    a++;
                 }
              wait(0);
              }
           }
           if(lv==0){wait(20-rank*2);}
           wait(12);
           if(GetX>32&&GetX<416&&GetY>16&&GetY<360){
              let p2=atan2( GetPlayerY()-(GetY()+35), GetPlayerX()-(GetX()-16));
              let a=0;
              loop(5+rank){
                 if(phase==0){return;}
                 loop(1){
                    CreateShotFromScript( "shot1",GetX()-16, GetY()+35, 3.8-a/4+ex, p2-p2%8+4+a*2, 0, 03);
                    a++;
                 }
              wait(0);
              }
           }
           if(lv==0){wait(20-rank*2);}
           wait(12);
        }
    }
    task Tmove1{
        yield;
        setmove( 90, 80 );
        wait(200);
        setmove( -90, 80 );
        wait(80);
    }

   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"