script_enemy_main {
    let time = 0;
    let phase = 1;
    let rate = 7;
    let kaku = 40;
    let score = 1200;
    let lv = 0;
    let houdai = GetAngleToPlayer;
    let angle = GetAngle();
    let muki = 0;
    if(angle==32||angle==-148){
       muki=0;
    }
    else{
       muki=1;
    }
    let rank = GetSpeed();
    let arg = GetArgument();
    let ex = GetCommonData("ex");
    let mapx = GetX();
    let mapy = GetY();
    let imgEnemy = GetCurrentScriptDirectory~"img\land1.png";
    let tama = GetCurrentScriptDirectory~"tama.txt";
    let se1 = GetCurrentScriptDirectory~"wav\se1.wav";
    let se2 = GetCurrentScriptDirectory~"wav\se2.wav";
    @Initialize(){
        SetLife( 500 );
        SetInvincibility( 90 );
        LoadGraphic( imgEnemy );
        LoadUserShotData( tama );
        SetX(mapx-GetCommonData("bgx"));
        SetY(GetCommonData("bgy")-mapy);
        Tmove;
        Tshot1;
        Tserch;
    }
    @MainLoop {
        if((GetX<32||GetX>416||GetY<16)&&time<300){SetInvincibility( 3 );}
        if(phase==1&&GetLife<=100){
           phase-=1;
           if(lv==0||GetPoint>0){DeleteEnemyShotImmediatelyInCircle(SHOT, GetX, GetY+30, 64);}
           PlaySE(se2);
           Tdeath(14,64,2,1);
        }
        if(phase>=1){SetCollisionA(GetX(), GetY(), 35);}
        SetX(mapx-GetCommonData("bgx"));
        SetY(GetCommonData("bgy")-mapy);
        if(GetCommonData("kakusei")>0){lv=1}
        else{lv=0}
        time++;
        yield;
    }
    @Finalize() {
    }
    @DrawLoop {
	SetTexture( imgEnemy );
        SetGraphicRect( 1, 1, 128, 128 );
        SetGraphicAngle(muki*180,0,0);
	DrawGraphic( GetX(), GetY()-10 );
        SetGraphicRect( 128, 1, 256, 128 );
        SetGraphicAngle(0,30,houdai);
	DrawGraphic( GetX(), GetY() );
    }
    task Tserch {
        yield;
        let b=GetCommonData("ransu")%2-0.5;
        SetCommonData("ransu",GetCommonData("ransu")+1);
        while(GetLife>=400){
           let a=GetAngleToPlayer()-houdai;
           if((a>0&&a<=180)||(a<0&&a<=-180)){houdai+=3;}
           else if((a>0&&a>180)||(a<0&&a>-180)){houdai-=3;}
           if(houdai>=360){houdai-=360;}
           if(houdai<0){houdai+=360;}
           yield;
        }
        loop{houdai+=11.2*b;yield;}
    }

    task Tshot1{
        yield;
        wait(30);
        loop{
           if(GetX>32&&GetX<416&&GetY>16&&GetY<420){
              if(GetLife<400){Tshot2;return;}
              SetShotDirectionType(ABSOLUTE);
              let a=0;
              let b=rand(0,5);
              loop(3+ex*1){
                 CreateShotFromScript( "shot1",GetX()+cos(houdai)*28, GetY()+sin(houdai)*22, 2.2+a*0.5+ex, houdai, 0, 13);
                 a++;
                 b++;
              }
           }
           wait(30-lv*15);
        }
    }
    task Tshot2{
        yield;
        loop{
           if(GetX>32&&GetX<416&&GetY>16&&GetY<420){
              if(phase<1){return;}
              SetShotDirectionType(ABSOLUTE);
              let a=-1-ex;
              loop(3+ex*2){
                 CreateShotFromScript( "shot1",GetX()+cos(houdai)*28, GetY()+sin(houdai)*22, 2.8+ex, houdai+a*31, 0, 13);
                 a++;
              }
           }
           wait(3-lv*1);
        }
    }
    task Tmove{
       setmove(angle,arg);
       wait(arg+120);
       setmove(angle+180,arg+100);
       wait(arg+100);
       VanishEnemy();
    }

   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"