script_enemy_main {
    let time = 0;
    let phase = 2;
    let rate = 0;
    let life = 0;
    let kaku = 80;
    let lv = 0;
    let score = 0;
    let angle = GetAngle();
    let rank = GetSpeed();
    let arg = GetArgument();
    let ex = GetCommonData("ex");
    let mapx = GetX();
    let mapy = GetY();
    let imgEnemy = GetCurrentScriptDirectory~"img\hunebig1.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";
    SetCommonData("haya",0);
    @Initialize(){
        SetLife( 2000 );
        SetInvincibility( 160 );
        LoadGraphic( imgEnemy );
        LoadUserShotData( tama );
        SetX(mapx-GetCommonData("bgx"));
        SetY(GetCommonData("bgy")-mapy);
        Tshot1;
        Tshot2;
    }
    @MainLoop {
        rate=life-GetLife;
        life=GetLife;
        if(phase==2&&GetLife<=1000){
           phase-=1;
           score = 20000;
           if(lv==0||GetPoint>0){DeleteEnemyShotImmediatelyInCircle(SHOT, 224, 240, 500);}
           PlaySE(se2);
           Tdeath(14,64,2,0);
           Tshot3;
        }
        if(phase==1&&GetLife<=100){
           phase-=1;
           score = 25000;
           if(lv==0||GetPoint>0){DeleteEnemyShotImmediatelyInCircle(SHOT, 224, 240, 500);}
           PlaySE(se2);
           Tdeath(14,64,2,1);
        }
        if(time>240&&GetY>500){VanishEnemy;}
        if(time>2000){VanishEnemy;}
        if(phase>=1){
           SetCollisionA(GetX()+60, GetY(),45);
           SetCollisionA(GetX(), GetY(), 45);
           SetCollisionA(GetX()-60, GetY(), 45);
        }
        SetX(mapx-GetCommonData("bgx"));
        SetY(GetCommonData("bgy")-mapy);
        lv=GetCommonData("rank");
        time++;
        yield;
    }
    @Finalize() {
       SetCommonData("haya",1);
    }
    @DrawLoop {
	SetTexture( imgEnemy );
        SetGraphicRect( 1, 1, 320, 160 );
        SetGraphicAngle(0,0,0);
	DrawGraphic( GetX(), GetY() );
        if(phase==2){
           SetGraphicRect( 1, 1, 320, 160 );
           SetGraphicAngle(0,0,0);
        }
    }

    task Tshot1{
        yield;
        wait(60);
        let a=0;
        loop{
           if(GetX>32&&GetX<416&&GetY>16&&GetY<360){
              if(phase==0){return;}
              SetShotDirectionType(ABSOLUTE);
              let b=0;
              loop(3){
                 CreateShotFromScript( "shot2",GetX()-17, GetY()-25, 2+ex/2, a*(13.1-ex*3)+b*120, 0, 05);
                 b++;
              }
           }
           wait(9-lv*1);
           a++;
        }
    }
    task Tshot2{
        yield;
        wait(130);
        loop{
           if(GetX>32&&GetX<416&&GetY>16&&GetY<360){
              let p2=atan2( GetPlayerY()-(GetY()-10), GetPlayerX()-(GetX()-88));
              let a=0;
              loop(2+ex){
                 if(phase==1){return;}
                 let b=0;
                 loop(1+ex){
                    CreateShotFromScript( "shot1",GetX()-88, GetY()-10, 3+a*0.8+ex, p2-p2%12+6-b*8, 0, 13);
                    b++;
                 }
                 a++;
              }
           }
           PlaySE(seshot1);
           wait(lv-rank*10);
           if(GetX>32&&GetX<416&&GetY>16&&GetY<360){
              let p1=atan2( GetPlayerY()-(GetY()-10), GetPlayerX()-(GetX()+103));
              let a=0;
              loop(2+ex){
                 if(phase==1){return;}
                 let b=0;
                 loop(1+ex){
                    CreateShotFromScript( "shot1",GetX()+103, GetY()-10, 3+a*0.8+ex, p1-p1%12+6+b*8, 0, 13);
                    b++;
                 }
                 a++;
              }
           }
           PlaySE(seshot1);
           wait(60-lv*10);
        }
    }
    task Tshot3{
        yield;
        wait(60);
        let a=0;
        loop{
           if(GetX>32&&GetX<416&&GetY>16&&GetY<360){
              if(phase==0){return;}
              SetShotDirectionType(ABSOLUTE);
              let b=0;
              loop(4){
                 CreateShotFromScript( "shot1",GetX()+40, GetY()-43, 3.7+ex/2, -a*(11.3-ex*2)+b*90, 0, 03);
                 b++;
              }
           }
           PlaySE(seshot1);
           wait(8-lv*1);
           a++;
        }
    }
   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"