script_enemy_main {
    let time = 0;
    let phase = 1;
    let rate = 1;
    let kaku = 10;
    let score = 80;
    let lv = 0;
    let angle = GetAngle();
    let rank = GetSpeed();
    let arg = GetArgument();
    let ex = GetCommonData("ex");
    let imgEnemy = GetCurrentScriptDirectory~"img\zakoheli1.png";
    let tama = GetCurrentScriptDirectory~"tama.txt";
    let se1 = GetCurrentScriptDirectory~"wav\se1.wav";
    let se3 = GetCurrentScriptDirectory~"wav\se3.wav";
    @Initialize(){
        SetLife( 105 );
        SetInvincibility( 5 );
        SetSpeed(3.3);
        LoadGraphic( imgEnemy );
        LoadUserShotData( tama );
        if(arg==0){Tserch;Tshot1;}
        if(arg==1){Tshot2;Tshot2a;}
        if(arg==2){Tshot3;Tshot3a;}
    }
    @MainLoop {
        if(phase==1&&GetLife<=100){
           phase-=1;
           if(lv==0||GetPoint>0){DeleteEnemyShotImmediatelyInCircle(SHOT, GetX, GetY, 25);}
           PlaySE(se3);
           Tdeath(2,24,2,1);
        }
        if(time>240&&GetY>500){VanishEnemy;}
        if(time>1000){VanishEnemy;}
        if(phase>=1){
           SetCollisionA(GetX, GetY, 24);
           SetCollisionB(GetX, GetY, 16);
        }
        if(GetCommonData("kakusei")>0){lv=1}
        else{lv=0}
        time++;
        yield;
    }
    @Finalize() {
    }
    @DrawLoop {
	SetTexture( imgEnemy );
        SetGraphicRect( 1, 1, 48, 48 );
        SetGraphicAngle(0,30,angle-90);
	DrawGraphic( GetX()-cos(angle)*6, GetY()-sin(angle)*6 );
        SetGraphicRect( 48, 0, 96, 48 );
        SetGraphicAngle(0,30,-time*17);
	DrawGraphic( GetX()-cos(angle)*15, GetY()-sin(angle)*15 );
    }

    task Tshot1{
        yield;
        wait(20);
        loop{
           if(phase<=0){return;}
           if(GetX>32&&GetX<416&&GetY>16&&GetY<400){
              SetShotDirectionType(ABSOLUTE);
              CreateShotFromScript( "shot1",GetX()+cos(angle)*20, GetY()+sin(angle)*20, 2.7+ex, angle, 0, 12);
              if(ex==1){
                 CreateShotFromScript( "shot1",GetX()+cos(angle)*20, GetY()+sin(angle)*20, 2.7+ex, angle+6, 0, 12);
                 CreateShotFromScript( "shot1",GetX()+cos(angle)*20, GetY()+sin(angle)*20, 2.7+ex, angle-6, 0, 12);
              }
           }
           if(lv==0){wait(32-rank*6);}
           wait(5);
        }
    }
    task Tserch {
        yield;
        loop(150){
           let a=GetAngleToPlayer()-angle;
           if((a>0&&a<=180)||(a<0&&a<=-180)){angle+=1.5;}
           else if((a>0&&a>180)||(a<0&&a>-180)){angle-=1.5;}
           if(angle>=360){angle-=360;}
           if(angle<0){angle+=360;}
           SetAngle(angle);
           yield;
        }
        wait(120);
        VanishEnemy();
    }
    task Tshot2{
        yield;
        SetMovePosition03( GetX(), GetY()+180, 20, 4);
        loop(60) { angle=GetAngleToPlayer;yield; }
        SetMovePositionHermite(GetX(), GetY(), 300, angle, 300, 270, 60);
        loop(60) { angle=GetAngle;yield; }
        SetMovePosition01( GetX(), GetY()-200, 3);
        loop(60) { angle=GetAngle;yield; }
        VanishEnemy();
    }
    task Tshot2a{
        yield;
        wait(15-rank*2);
        while(time<80){
           if(phase<=0){return;}
           if(GetX>32&&GetX<416&&GetY>16&&GetY<400){
              let p=genteikaku(GetAngleToPlayer(),36);
              CreateShotFromScript( "shot1",GetX()+cos(p)*20, GetY()+sin(p)*20, 2.7+ex, p, 0, 12);
              if(ex==1){
                 CreateShotFromScript( "shot1",GetX()+cos(angle)*20, GetY()+sin(angle)*20, 2.7+ex, angle+6, 0, 12);
                 CreateShotFromScript( "shot1",GetX()+cos(angle)*20, GetY()+sin(angle)*20, 2.7+ex, angle-6, 0, 12);
              }
           }
           if(lv==0){wait(30-rank*6);}
           wait(5);
        }
    }
    task Tshot3{
        yield;
        SetMovePosition03( GetX(), GetY()+180, 20, 4);
        loop(60) { angle=GetAngleToPlayer;yield; }
        SetMovePositionHermite(GetX(), GetY(), 300, angle, 300, 270, 60);
        loop(60) { angle=GetAngle;yield; }
        SetMovePosition01( GetX(), GetY()-200, 1.5);
        loop(130) { angle=GetAngle;yield; }
        VanishEnemy();
    }
    task Tshot3a{
        yield;
        wait(15-rank*2);
        while(time<80){
           if(phase<=0){return;}
           if(GetX>32&&GetX<416&&GetY>16&&GetY<400){
              let p=genteikaku(GetAngleToPlayer(),36);
              CreateShotFromScript( "shot1",GetX()+cos(p)*20, GetY()+sin(p)*20, 2.7+ex, p, 0, 12);
              if(ex==1){
                 CreateShotFromScript( "shot1",GetX()+cos(angle)*20, GetY()+sin(angle)*20, 2.7+ex, angle+6, 0, 12);
                 CreateShotFromScript( "shot1",GetX()+cos(angle)*20, GetY()+sin(angle)*20, 2.7+ex, angle-6, 0, 12);
              }
           }
           if(lv==0){wait(30-rank*6);}
           wait(6);
        }
        wait(60);
        loop{
           if(phase<=0){return;}
           if(GetX>32&&GetX<416&&GetY>16&&GetY<400){
              let p=GetAngleToPlayer();
              p+=-p%10+5;
              let r=rand(-ex*8,+ex*8);
              CreateShotFromScript( "shot1",GetX(), GetY(), 2.7+ex, p+r, 0, 12);
              if(ex==1){
                 CreateShotFromScript( "shot1",GetX(), GetY(), 4.6, p+r, 0, 12);
              }
           }
           if(lv==0){wait(4-rank*0.5);}
           wait(3-ex*1);
        }
    }




    #include_function".\efanction.txt"
}

#include_script".\escript.txt"