script_enemy_main {
    let time = 0;
    let phase = 1;
    let rate = 0;
    let life = 0;
    let kaku = 40;
    let score = 1300;
    let lv = 0;
    let angle = GetAngle();
    let rank = GetSpeed();
    let arg = GetArgument();
    let ex = GetCommonData("ex");
    let imgEnemy = GetCurrentScriptDirectory~"img\sky1.png";
    let tama = GetCurrentScriptDirectory~"tama.txt";
    let se1 = GetCurrentScriptDirectory~"wav\se1.wav";
    let se2 = GetCurrentScriptDirectory~"wav\se2.wav";
    @Initialize(){
        SetLife( 350 );
        SetSpeed(3.3);
        LoadGraphic( imgEnemy );
        LoadUserShotData( tama );
        if(arg<=1&&arg>=-1){
           SetInvincibility( 20 );
           Tshot1;
           Tshot2;
           if(angle==0){Tmove0;}
           if(angle==1){Tmove1;}
        }
        if(arg==2){
           SetInvincibility( 50 );
           Tshot1a;
           Tshot2a;
           SetSpeed(1.3);
        }
    }
    @MainLoop {
        if(phase==1&&GetLife<=100){
           phase-=1;
           PlaySE(se2);
           Tdeath(14,64,2,1);
           CreateEnemyFromFile(GetCurrentScriptDirectory~"airitem.txt",GetX+35,GetY, -3, 0, 4);
           CreateEnemyFromFile(GetCurrentScriptDirectory~"airitem.txt",GetX-35,GetY, -3, 0, 4);
        }
        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(20);
        loop{
           if(GetX>62&&GetX<396&&GetY<250){
              let a=cos(GetAngle);
              loop(6+rank){
                 if(phase==0){return;}
                 SetShotDirectionType(ABSOLUTE);
                 CreateShotFromScript( "shot2",GetX()+30, GetY()-20, (0.3^2+(|a|)^2)^(1/2), 270+a*90+6, 0, 02);
                 CreateShotFromScript( "shot2",GetX()-30, GetY()-20, (0.3^2+(|a|)^2)^(1/2), 270+a*90+6, 0, 02);
                 CreateShotFromScript( "shot2",GetX()+30, GetY()-20, (0.3^2+(|a|)^2)^(1/2), 270+a*90-6, 0, 02);
                 CreateShotFromScript( "shot2",GetX()-30, GetY()-20, (0.3^2+(|a|)^2)^(1/2), 270+a*90-6, 0, 02);
                 wait(4);
              }
           }
           wait(75-lv*14);
        }
    }
    task Tshot1a{
        yield;
        wait(20);
        loop{
           if(GetX>62&&GetX<396&&GetY<290){
              let a=cos(GetAngle);
              loop(6+rank){
                 if(phase==0){return;}
                 SetShotDirectionType(ABSOLUTE);
                 CreateShotFromScript( "shot2",GetX()+30, GetY()-20, 1, 270+2, 0, 02);
                 CreateShotFromScript( "shot2",GetX()-30, GetY()-20, 1, 270+2, 0, 02);
                 CreateShotFromScript( "shot2",GetX()+30, GetY()-20, 1, 270-2, 0, 02);
                 CreateShotFromScript( "shot2",GetX()-30, GetY()-20, 1, 270-2, 0, 02);
                 wait(4);
              }
           }
           wait(75-lv*14);
        }
    }
    task Tshot2{
        yield;
        wait(130);
        let b=0;
        loop{
           if(GetX>62&&GetX<396&&GetY>16&&GetY<300){
              let p1=atan2( GetPlayerY()-(GetY()), GetPlayerX()-(GetX()+30));
              let p2=atan2( GetPlayerY()-(GetY()), GetPlayerX()-(GetX()-30));
              loop(4+ex){
                 if(phase==0){return;}
                 let a=-1-rank/4;
                 loop(3+rank/2+ex){
                    CreateShotFromScript( "shot1",GetX()+30, GetY(), 3+ex, p1-p1%8+4-a*(6+b*4), 0, 12);
                    CreateShotFromScript( "shot1",GetX()-30, GetY(), 3+ex, p2-p2%8+4+a*(6+b*4), 0, 12);
                    a++;
                 }
              wait(4);
              }
           b++;
           }
           wait(65-lv*12);
        }
    }
    task Tshot2a{
        yield;
        wait(30);
        let b=0;
        loop{
           if(GetX>32&&GetX<426&&GetY>16&&GetY<300){
              let p1=atan2( GetPlayerY()-(GetY()), GetPlayerX()-(GetX()+30));
              let p2=atan2( GetPlayerY()-(GetY()), GetPlayerX()-(GetX()-30));
              loop(4+ex*2){
                 if(phase==0){return;}
                 let a=-1-rank/4;
                 loop(3+rank/2+ex*2){
                    CreateShotFromScript( "shot1",GetX()+30, GetY(), 3+ex, p1-p1%8+4-a*(8+b*2), 0, 12);
                    CreateShotFromScript( "shot1",GetX()-30, GetY(), 3+ex, p2-p2%8+4+a*(8+b*2), 0, 12);
                    a++;
                 }
              wait(6);
              }
           b++;
           }
           wait(65-lv*12);
        }
    }
    task Tmove0 {
        SetInvincibility( 140 );
        SetMovePositionHermite(GetX+160*arg, GetY+160, 500, 90-70*arg, 100, 90, 300);
        wait(300);
        SetMovePosition02(GetX, GetY+200, 250);
        wait(250);
        SetMovePosition02(GetX, GetY+200, 100);
        wait(100);
        VanishEnemy();
    }
    task Tmove1 {
        SetInvincibility( 100 );
        SetMovePosition02(GetX, GetY+360, 400);
        wait(400);
        SetMovePosition02(GetX, GetY+200, 100);
        wait(100);
        VanishEnemy();
    }




    #include_function".\efanction.txt"
}

#include_script".\escript.txt"