script_enemy_main {
    let time = 0;
    let phase = 1;
    let rate = 0;
    let life = 0;
    let kaku = 40;
    let score = 5200;
    let lv = 0;
    let angle = GetAngle();
    let ex = GetCommonData("ex");
    let rank = GetSpeed();
    let arg = GetArgument();
    let imgEnemy = GetCurrentScriptDirectory~"img\sky3.png";
    let tama = GetCurrentScriptDirectory~"tama.txt";
    let se1 = GetCurrentScriptDirectory~"wav\se1.wav";
    let se2 = GetCurrentScriptDirectory~"wav\se2.wav";
    @Initialize(){
        SetLife( 350 );
        SetInvincibility( 50 );
        LoadGraphic( imgEnemy );
        LoadUserShotData( tama );
        Tshot1;Tshot2;Tmove1;
    }
    @MainLoop {
        rate=life-GetLife;
        life=GetLife;
        if(phase==1&&GetLife<=100){
           phase-=1;
           PlaySE(se2);
           Tdeath(14,64,2,1);
           CreateEnemyFromFile(GetCurrentScriptDirectory~"airitem.txt",GetX,GetY, -3, 0, 1);
           CreateEnemyFromFile(GetCurrentScriptDirectory~"airitem.txt",GetX+35,GetY, -3, 0, 2);
           CreateEnemyFromFile(GetCurrentScriptDirectory~"airitem.txt",GetX-35,GetY, -3, 0, 2);
        }
        if(phase>=1){
           SetCollisionA(GetX, GetY, 64);
           SetCollisionB(GetX, GetY, 32);
        }
        lv=GetCommonData("rank");
        time++;
        yield;
    }
    @Finalize() {
    }
    @DrawLoop {
	SetTexture( imgEnemy );
        SetGraphicRect( 1, 1, 128, 128 );
        SetGraphicAngle(0,0,0);
	DrawGraphic( GetX(), GetY() );
    }

    task Tshot1{
        yield;
        wait(30);
        loop{
           if(GetX>62&&GetX<396&&GetY<330){
              if(phase==0){return;}
              let p=90;
              if(GetY>GetPlayerY){p=270}
              SetShotDirectionType(ABSOLUTE);
              let a=-1.5-rank/4;
              loop(4+rank/2){
                 let b=0;
                 loop(3+rank/2){
                    CreateShotFromScript( "shot1",GetX(), GetY(), 2+b*0.6+ex, p+a*20, 0, 05);
                    b++;
                 }
              a++;
              }
           }
           wait(92-lv*16);
        }
    }
    task Tshot2{
        yield;
        wait(20);
        let b=0;
        loop{
              if(phase==0){return;}
              let p1=atan2( GetPlayerY()-(GetY()), GetPlayerX()-(GetX()+45));
              let p2=atan2( GetPlayerY()-(GetY()), GetPlayerX()-(GetX()-45));
              let a=0;
              loop(2+rank/2+ex){
                 CreateShotFromScript( "shot1",GetX()+45, GetY(), 3+a/7+ex, p1, 0, 13);
                 CreateShotFromScript( "shot1",GetX()-45, GetY(), 3+a/7+ex, p2, 0, 13);
                 if(ex==1){
                    CreateShotFromScript( "shot1",GetX()+45, GetY(), 3+a/7+ex, p1-2, 0, 13);
                    CreateShotFromScript( "shot1",GetX()-45, GetY(), 3+a/7+ex, p2+2, 0, 13);
                 }
                 a++;
              }
           wait(78-lv*14);
        }
    }
    task Tmove1 {
        SetInvincibility( 30 );
        SetMovePosition03(GetX+cos(angle)*240, GetY+sin(angle)*240, 80, 4);
        wait(90);
        loop(2){
           let p=GetAngleToPlayer;
           SetMovePosition03(GetX+cos(p)*220, GetY+sin(p)*220, 100, 3);
           wait(70);
           SetMovePosition03(GetX, GetY-220, 100, 3);
           wait(70);
           let p=atan2( 100-(GetY()), 224-(GetX()));
           SetMovePosition03(GetX+cos(p)*220, GetY+sin(p)*220, 100, 3);
           wait(70);
        }
        SetMovePosition01(GetX+cos(angle)*600, GetY+sin(angle)*600, 2.5);
        wait(200);
        VanishEnemy();
    }




    #include_function".\efanction.txt"
}

#include_script".\escript.txt"