script_enemy_main {
    let time = 0;
    let phase = 1;
    let rate = 12;
    let kaku = 50;
    let score = 4000;
    let lv = 0;
    let angle = GetAngle();
    let rank = GetSpeed();
    let arg = GetArgument();
    let ex = GetCommonData("ex");
    let mapx = GetX();
    let mapy = GetY();
    let imgEnemy = GetCurrentScriptDirectory~"img\cannonbig1.png";
    let tama = GetCurrentScriptDirectory~"tama.txt";
    let se1 = GetCurrentScriptDirectory~"wav\se1.wav";
    let se2 = GetCurrentScriptDirectory~"wav\se2.wav";
    @Initialize(){
        SetLife( 800 );
        SetInvincibility( 10 );
        LoadGraphic( imgEnemy );
        LoadUserShotData( tama );
        SetX(mapx-GetCommonData("bgx"));
        SetY(GetCommonData("bgy")-mapy);
        Tshot1;Tshot2;
    }
    @MainLoop {
        if(phase==1&&GetLife<=100){
           phase-=1;
           if(lv==0||GetPoint>0){DeleteEnemyShotImmediatelyInCircle(SHOT, 224, 240, 600);}
           PlaySE(se2);
           Tdeath(15,60,2,1);
        }
        if(GetX<12||GetX>436||GetY<30){
           SetInvincibility( 5 );
        }
        if(time>240&&GetY>500){VanishEnemy;}
        if(time>1600){VanishEnemy;}
        if(phase>=1){SetCollisionA(GetX, GetY, 70);}
        SetX(mapx-GetCommonData("bgx"));
        SetY(GetCommonData("bgy")-mapy);
        if(GetCommonData("kakusei")>0){lv=1}
        else{lv=0}
        time++;
        yield;
    }
    @Finalize() {
    }
    @DrawLoop {
	SetTexture( imgEnemy );
        /*SetGraphicRect( 0, 0, 192, 192 );
        SetGraphicAngle(0,0,0);
	DrawGraphic( GetX(), GetY() );*/
        SetGraphicRect( 192, 0, 384, 192 );
        SetGraphicAngle(0,30,genteikaku(GetAngleToPlayer(),48));
	DrawGraphic( GetX(), GetY() );
    }

    task Tshot1{
        yield;
        wait(50);
        loop{
           if(phase<=0){return;}
           if(GetX>32&&GetX<416&&GetY>16&&GetY<(300+rank*20)){
              let p=genteikaku(GetAngleToPlayer(),48);
              let a=-2-ex;
              loop(5+ex*2){
                 CreateShotFromScript( "shot5",GetX()+cos(p)*40, GetY()+sin(p)*40, 3.5+ex, p+a*(15-ex*4), 0, 1);
                 a++;
              }
              if(lv==0){wait(110-rank*10-ex*30);}
              else{wait(60-rank*5-ex*30)}
           }
           wait(20);
        }
    }
    task Tshot2{
        yield;
        wait(50);
        loop{
           if(GetX>32&&GetX<416&&GetY>40&&GetY<(300+rank*20)){
              let a=-1;
              let p=genteikaku(GetAngleToPlayer(),48);
              /*let p1=atan2( GetPlayerY()-(GetY()+sin(p+90)*30), GetPlayerX()-(GetX()+cos(p+90)*30));
              let p2=atan2( GetPlayerY()-(GetY()+sin(p-90)*30), GetPlayerX()-(GetX()+cos(p-90)*30));*/
              loop(5){
                 if(phase==0){return;}
                 let b=-1-ex*2;
                 loop(3+ex*4){
                    CreateShotFromScript( "shota",GetX()+cos(p+90)*30, GetY()+sin(p+90)*30, 5+ex, genteikaku(p,24)+b*(16-ex*5)+a*(22-ex*5), 0, 06);
                    CreateShotFromScript( "shota",GetX()+cos(p-90)*30, GetY()+sin(p-90)*30, 5+ex, genteikaku(p,24)-b*(16-ex*5)-a*(22-ex*5), 0, 06);
                    b++;
                 }
              wait(12-lv*5);
              a++;
              }
              if(lv==0){wait(30-rank*5);}
           }
           wait(20);
        }
    }


    #include_function".\efanction.txt"
}
    script_shot shota{
       let out=false;
       let gr=GetArgument;
       let lv=0;
       let time=0;
       @Initialize{
          SetDefault(gr+lv*20);
       }
       @MainLoop {
          if(GetX<20||GetX>428||GetY<20||GetY>460){
             out=true;
             End;
          }
          if(GetCommonData("kakusei")>0){
             lv=1;
             if(GetPoint==0){lv=2;SetSpeed(GetSpeed+0.04)}
          }
          else{lv=0}
          SetDefault(gr+lv*20);
          if(time==25){SetSpeed(GetSpeed-2.5);}
          if((GetX-GetPlayerX)^2+(GetY-GetPlayerY)^2<=4){SetCommonData("gekitui",1);}
          time++;
       }
       @DrawLoop {
          DrawGraphicDefault();
       }
       @Finalize{
          if(out==false&&OnBomb==false){
             if(GetCommonData("kakusei")>0){
                let a=(200+GetCommonData("kinkaiten")*100);
                CreateShotFromScript( "kinka",GetX(), GetY(), a, 270, 0, 99-GetCommonData("kinkaiten")/20);
             }
             if(OnBomb==false&&GetCommonData("kakusei")==0){
                CreateShotFromScript( "isi",GetX(), GetY(), 0, 270, 0, 0);
             }
          }
       }
    }    
#include_script".\escript.txt"