script_enemy_main {
    let time = 0;
    let phase = 1;
    let rate = 0;
    let life = 0;
    let kaku = 40;
    let score = 7000;
    let lv = 0;
    let angle = GetAngle();
    let ex = GetCommonData("ex");
    let rank = GetSpeed()+ex*2;
    let arg = GetArgument();
    let imgEnemy = GetCurrentScriptDirectory~"img\skybig1.png";
    let tama = GetCurrentScriptDirectory~"tama.txt";
    let se1 = GetCurrentScriptDirectory~"wav\se1.wav";
    let se2 = GetCurrentScriptDirectory~"wav\se2.wav";
    let seshot1 = GetCurrentScriptDirectory~"wav\shot1.wav";
    let seshot2 = GetCurrentScriptDirectory~"wav\shot2.wav";
    @Initialize(){
        SetLife( 1300 );
        SetInvincibility( 120 );
        LoadGraphic( imgEnemy );
        LoadUserShotData( tama );
        Tshot1;Tshot2;Tmove1;
    }
    @MainLoop {
        rate=life-GetLife;
        life=GetLife;
        if(phase==1&&GetLife<=100){
           phase-=1;
           DeleteEnemyShotImmediatelyInCircle(SHOT, 224, 240, 600);
           PlaySE(se2);
           Tdeath(25,100,2,1);
           let a=0;
           loop(4){
              CreateEnemyFromFile(GetCurrentScriptDirectory~"airitem.txt",GetX()+40+a*20, GetY()-25+a*4, -3, 0, 4);
              CreateEnemyFromFile(GetCurrentScriptDirectory~"airitem.txt",GetX()-40-a*20, GetY()-25+a*4, -3, 0, 4);
              a++;
           }
           if(rate%1>0){Tkunsyon(10,2);}
        }
        if(phase>=1){
           SetCollisionA(GetX, GetY, 100);
           SetCollisionB(GetX, GetY, 64);
        }
        lv=GetCommonData("rank");
        time++;
        yield;
    }
    @Finalize() {
    }
    @DrawLoop {
	SetTexture( imgEnemy );
        SetGraphicRect( 1, 1, 256, 256 );
        SetGraphicAngle(0,0,0);
	DrawGraphic( GetX(), GetY() );
        SetGraphicRect( 256, 1, 320, 64 );
        SetGraphicAngle(0,0,atan2( GetPlayerY()-(GetY()+30), GetPlayerX()-(GetX()))-90);
	DrawGraphic( GetX(), GetY()+30 );
    }

    task Tshot1{
        yield;
        wait(30);
        let b=0;
        loop{
              if(phase==0||GetY>280){return;}
              let p1=atan2( GetPlayerY()-(GetY()+2), GetPlayerX()-(GetX()+65));
              let p2=atan2( GetPlayerY()-(GetY()+2), GetPlayerX()-(GetX()-65));
              SetShotDirectionType(ABSOLUTE);
              let a=-4;
              loop(9){
                 CreateShotFromScript( "shot1",GetX()+65, GetY()+2, 2.6, p1+a*12, 0, 03);
                 CreateShotFromScript( "shot1",GetX()-65, GetY()+2, 2.6, p2-a*12, 0, 03);
                 CreateShotFromScript( "shot1",GetX()+65, GetY()+2, 3.4, p1+a*12, 0, 03);
                 CreateShotFromScript( "shot1",GetX()-65, GetY()+2, 3.4, p2-a*12, 0, 03);
                 if(ex==1){
                    CreateShotFromScript( "shot1",GetX()+60, GetY()+2, 4.2, p1+a*12, 0, 03);
                    CreateShotFromScript( "shot1",GetX()-60, GetY()+2, 4.2, p2-a*12, 0, 03);
                 }
                 a++;
              }
           wait(60-lv*10);
           b++;
        }
    }
    task Tshot2{
        yield;
        wait(110);
        loop(2){
           let p=atan2( GetPlayerY()-(GetY()+30), GetPlayerX()-(GetX()));
           let a=0;
           loop(26){
              if(phase==0||GetY>280){return;}
              let b=-1;
              loop(3){
                 CreateShotFromScript( "shot1",GetX()+cos(p+30)*30, GetY()+30+sin(p+30)*30, 3.5+a/3, p+b*30, 0, 13);
                 CreateShotFromScript( "shot1",GetX()+cos(p-30)*30, GetY()+30+sin(p-30)*30, 3.5+a/3, p+b*30, 0, 13);
                 if(ex==1){
                    CreateShotFromScript( "shot1",GetX()+cos(p+90)*40, GetY()+30+sin(p+90)*40, 3.5+a/3, p+b*30, 0, 13);
                    CreateShotFromScript( "shot1",GetX()+cos(p-90)*40, GetY()+30+sin(p-90)*40, 3.5+a/3, p+b*30, 0, 13);
                 }
                 b++;
              }
              a++;
              PlaySE(seshot1);
              wait(3);
           }
           wait(20);
        }
        wait(30);
        loop{
           if(phase==0){return;}
           let a=0;
           loop(4){
              if(phase==0||GetY>280){return;}
              let p1=atan2( GetPlayerY()-(GetY()-25+a*4), GetPlayerX()-(GetX()+40+a*20));
              let p2=atan2( GetPlayerY()-(GetY()-25+a*4), GetPlayerX()-(GetX()-40-a*20));
              let b=-2-ex;
              loop(5+ex*2){
                 let c=0;
                 loop(3){
                    CreateShotFromScript( "shot1",GetX()+40+a*20, GetY()-25+a*4, 3+c, p1+b*(15-ex*4), 0, 13);
                    CreateShotFromScript( "shot1",GetX()-40-a*20, GetY()-25+a*4, 3+c, p2+b*(15-ex*4), 0, 13);
                    c++;
                 }
                 b++;
              }
              a++;
              PlaySE(seshot2);
              wait(20-lv*3);
           }
           wait(42-lv*7);
        }
    }
    task Tmove1 {
        SetSpeed(1.3);
        SetAngle(90+55*angle);
        wait(338);
        SetSpeed(0.3);
        SetAngle(90);
        wait(450);
        SetSpeed(2);
        SetAngle(90);
        wait(200);
        VanishEnemy();
    }




    #include_function".\efanction.txt"
}

#include_script".\escript.txt"