script_enemy_main {
    let time = -100;
    let phase = 2;
    let sephase = 2;
    let rate = 0;
    let kaku = 80;
    let score = 0;
    let lv = 0;
    let life = 29040;
    let angle = GetAngle();
    let rank = GetSpeed();
    let arg = GetArgument();
    let ex = GetCommonData("ex");
    let houdai = 90;
    SetCommonData("bossx",GetX);
    SetCommonData("bossy",GetY);
    SetCommonData("bossphase",2);
    SetCommonData("bossparts1",0);
    SetCommonData("bossparts2",0);
    SetCommonData("bossatack",0);
    let imgEnemy = GetCurrentScriptDirectory~"img\st3boss.png";
    let tama = GetCurrentScriptDirectory~"tama.txt";
    let se1 = GetCurrentScriptDirectory~"wav\se1.wav";
    let se2 = GetCurrentScriptDirectory~"wav\se2.wav";
    let se6 = GetCurrentScriptDirectory~"wav\se6.wav";
    let seshot1 = GetCurrentScriptDirectory~"wav\shot1.wav";
    let seshot2 = GetCurrentScriptDirectory~"wav\shot2.wav";
    @Initialize(){
        SetLife( 29040 );
        SetInvincibility( 0 );
        SetTimer(300);
        LoadGraphic( imgEnemy );
        LoadUserShotData( tama );
        let life = GetLife;
        Tmain1;
    }
    @MainLoop {
        SetCommonData("bossx",GetX);
        SetCommonData("bossy",GetY);
        if(phase==2&&GetLife<=15540){
           phase-=1;
           time=-100;
           score=25000;
           SetCommonData("bossphase",1);
           SetCommonData("bossatack",0);
           if(lv==0||GetPoint>0){DeleteEnemyShotImmediatelyInCircle(SHOT, 224, 240, 600);}
           PlaySE(se2);
           Tdeath(15,100,2,0);
           Tshot2;Tmove;
           SetCommonData("prerank",GetCommonData("prerank")+1);
        }
        if(phase==1&&GetLife<=40){
           phase-=1;
           score=35000;
           SetCommonData("bossphase",0);
           SetCommonData("bossatack",0);
           if(lv==0||GetPoint>0){DeleteEnemyShotImmediatelyInCircle(SHOT, 224, 240, 600);}
           PlaySE(se2);
           Tdeath(0,80,2,0);
           Tbaku;
           Tbossbaku;
           SetMovePosition02(224, 600, 300);
        }
        if(phase>0&&time>=0){
           SetCollisionA(GetX, GetY-70, 90);
           SetCollisionA(GetX+80, GetY+0, 50);
           SetCollisionA(GetX-80, GetY+0, 50);
           if(phase==1){
              SetCollisionA(GetX+150, GetY-10, 50);
              SetCollisionA(GetX-150, GetY-10, 50);
           }
           SetCollisionA(GetX, GetY+60, 50);
           SetCollisionB(GetX, GetY-60, 90);
        }
        if(sephase==2&&GetLife<=15940){PlaySE(se6);sephase=1;}
        if(sephase==1&&GetLife<=440){PlaySE(se6);sephase=0;}
        
        lv=GetCommonData("rank");
        time++;
        yield;
    }
    @Finalize() {
    }
    @DrawLoop {
        if(time%5==0){
           if(life==GetLife){SetColor(255,255,255);}
           else{SetColor(210,210,255);}
           life=GetLife;
           if(phase==0||(time%30<5&&GetLife<2020)){SetColor(255,200,200);}
        }

	SetTexture( imgEnemy );
        if(phase<=1){
           SetGraphicRect( 256, 0, 512, 320 );
        }
        else{SetGraphicRect( 0, 0, 256, 320 );}
        SetGraphicAngle(0,0,0);
	DrawGraphic( GetX(), GetY() );

        let a=0;
        if(phase==1&&time<0){a=100+time*0.5}
        else if(phase<=1){a=100}
        else{a=50}
        SetGraphicRect( 512, 64, 800, 352 );
        SetGraphicAngle(0,0,90-a);
	DrawGraphic( GetX()+65, GetY()-70 );
        SetGraphicAngle(180,0,90-a);
	DrawGraphic( GetX()-65, GetY()-70 );



    }

    task Tmain1{
        yield;
        wait(180);
        loop{

        if(phase<=1){return;}
        SetCommonData("bossatack",1);
        Tshot11;
        wait(600);
        if(phase<=1){return;}
        SetCommonData("bossatack",0);
        wait(120-lv*20);

        if(phase<=1){return;}
        SetCommonData("bossatack",2);
        Tshot12;
        wait(700);
        if(phase<=1){return;}
        SetCommonData("bossatack",0);
        wait(180-lv*30);

        if(phase<=1){return;}
        SetCommonData("bossatack",3);
        Tshot13;
        wait(600);
        if(phase<=1){return;}
        SetCommonData("bossatack",0);
        wait(120-lv*20);

        if(phase<=1){return;}
        SetCommonData("bossatack",4);
        Tshot14;
        wait(700);
        if(phase<=1){return;}
        SetCommonData("bossatack",0);
        wait(240-lv*60);

        }
    }

    task Tshot11{
        yield;
        let a=rand(0,1);
        while(GetCommonData("bossatack")==1){
           if(phase<=1){return;}
           let b=0;
           loop(1){
              CreateShotFromScript( "shot5",GetX()+cos(a*110)*90, GetY+sin(a*110)*25-110, 3, a*110, 0, 6);
              b++;
           }
           a++;
           PlaySE(seshot2);
           wait(18-lv*3);
        }
    }

    task Tshot13{
        yield;
        let a=0;
        let c=rand(0,1);
        while(GetCommonData("bossatack")==3){
           if(phase<=1){return;}
           let b=0;
           loop(6){
              let ang=a*13.7+b*60+c*5;//4.6
              CreateShotFromScript( "shot5",GetX()+cos(ang)*90, GetY+sin(ang)*25-110, 3, ang, 0, 7);
              b++;
           }
           PlaySE(seshot2);
           wait(36-lv*6);
           a++;
        }
    }

    task Tshot12{
        yield;
        let a=rand(0,10);
        while(GetCommonData("bossatack")==2){
           let ang=atan2( GetPlayerY()-(GetY()-110), GetPlayerX()-(GetX()));
           loop(1){
              if(phase<=1){return;}
              ang = ang+cos(a*70)*90;
              CreateShotFromScript( "shot5",GetX()+cos(ang)*90, GetY+sin(ang)*25-110, 2.5, ang, 0, 08);
              PlaySE(seshot2);
              a++;
           }
           wait(36-lv*6);
        }
    }
    task Tshot14{
        yield;
        let a=rand(0,1);
        while(GetCommonData("bossatack")==4){
           if(phase<=1){return;}
           let b=0;
           loop(1){
              let ang=a*110;
              CreateShotFromScript( "shot5",GetX()+cos(ang)*90, GetY+sin(ang)*25-110, 3, ang, 0, 9);
              b++;
           }
           PlaySE(seshot2);
           wait(45-lv*8);
           a++;
        }
    }


    task Tshot2{
        wait(180);
        let j=rand_int(0,4);
        let k=rand_int(0,3);
        loop{

        SetCommonData("bossatack",1);
        let a=rand(1,-1);
        loop(40){
           if(phase<=0){return;}
           CreateShotFromScript( "shota",GetX(), GetY-110, 5, -90+a*9, 0, k%4);
           a++;
           PlaySE(seshot1);
           wait(6-lv);
        }

        if(j%5==0){Fshot21;}
        if(j%5==1){Fshot22;}
        if(j%5==2){Fshot23;}
        if(j%5==3){Fshot24;}
        if(j%5==4){Fshot25;}

        SetCommonData("bossatack",0);
        wait(85-lv*15);
        k++;
        j++;
        }
    }
    function Fshot21{
        wait(40-lv*30);
        let a=0;
        loop(13){
           let p1=atan2( GetPlayerY()-(GetY()-70), GetPlayerX()-(GetX()+65));
           let p2=atan2( GetPlayerY()-(GetY()-70), GetPlayerX()-(GetX()-65));
           if(phase<=0){return;}
           let b=-3;
           loop(7){
              CreateShotFromScript( "shot1",GetX()+65, GetY-70, 3, p1+b*3, 0, 05);
              CreateShotFromScript( "shot1",GetX()-65, GetY-70, 3, p2+b*3, 0, 05);
              b++;
           }
           PlaySE(seshot2);
           a++;
           wait(60-lv*10);
        }
        wait(120-lv*20);
    }
    function Fshot22{
        wait(40-lv*30);
        let a=0;
        let b=0;
        loop(300){
           if(phase<=0){return;}
           CreateShotFromScript( "shot1",GetX(), GetY-110, 5, 90+sin(a*2)*45+170-b*5.1, 0, 13);
           CreateShotFromScript( "shot1",GetX(), GetY-110, 5, 90+sin(a*2)*45-170+b*5.1, 0, 13);
           CreateShotFromScript( "shot1",GetX(), GetY-110, 5, 90+sin(a*2)*45+180-b*4.8, 0, 13);
           CreateShotFromScript( "shot1",GetX(), GetY-110, 5, 90+sin(a*2)*45-180+b*4.8, 0, 13);
           PlaySE(seshot1);
           if(b<30){b++;}
           if(b>29){a++;}
           wait(3-lv*0.4);
        }
        wait(120-lv*20);
    }
    function Fshot23{
        yield;
        let a=rand(0,360);
        loop(45){
           if(phase<=0){return;}
           let b=0;
           loop(1){
              let ang=a*110;
              CreateShotFromScript( "shotc",GetX(), GetY-110, 3, a, 0, 1);
              b++;
           }
           PlaySE(seshot2);
           wait(36-lv*6);
           a+=rand(90,130);
        }
        wait(210-lv*35);
    }
    function Fshot24{
        yield;
        wait(50);
        let a=rand(0,360);
        loop(2){
           if(phase<=0){return;}
           let b=0;
           loop(36){
              let ang=a*110;
              CreateShotFromScript( "shotc",GetX(), GetY-110, 2.5, a+b*10, 0, 2);
              b++;
           }
           PlaySE(seshot2);
           wait(180-lv*30);
           a+=rand(90,130);
        }
        wait(300-lv*50);
    }
    function Fshot25{
        wait(40-lv*30);
        let a=0;
        loop(4){
           if(phase<=0){return;}
           let p=atan2( GetPlayerY()-(GetY()-110), GetPlayerX()-(GetX()));
           CreateShotFromScript( "shotc",GetX(), GetY-110, 3, p, 0, 03);
           PlaySE(seshot2);
           a++;
           wait(180-lv*30);
        }
        wait(180-lv*30);
    }

    task Tmove {
        loop{
           if(phase<=0){return;}
           SetMovePosition02(224+rand(8,-8), 200+rand(8,-8),100);
           wait(100);
        }
    }

    #include_function".\efanction.txt"
}

   script_shot shota{//eei
       let out=false;
       let gr=01;
       let arg=GetArgument;
       let pl=GetAngleToPlayer;
       let ex = GetCommonData("ex");
       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((GetX-GetPlayerX)^2+(GetY-GetPlayerY)^2<=4){SetCommonData("gekitui",1);}
          if(time%8==0&&time>5){
             CreateShotFromScript( "shotb",GetX(), GetY(), 0, GetAngle, 0, arg);
          }
          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);
             }
          }
       }
    }    
   script_shot shotb{
       let out=false;
       let gr=06;
       let arg=GetArgument;
       let pl=GetAngleToPlayer;
       let ex = GetCommonData("ex");
       let lv=0;
       let time=0;
       let phase=1;
       @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;
                if(phase==2){SetSpeed(GetSpeed+0.04);}
             }
          }
          else{lv=0}
          SetDefault(gr+lv*20);
          if((GetX-GetPlayerX)^2+(GetY-GetPlayerY)^2<=4){SetCommonData("gekitui",1);}

          if(GetCommonData("bossatack")==0&&phase==1){
             phase=2;
             if(arg==0){SetAngle(GetAngle+130)}
             else if(arg==1){SetAngle(GetAngleToPlayer)}
             else if(arg==2){SetAngle(GetAngle-70)}
             else if(arg==3){SetAngle(90)}
          }
          if(time<60&&phase==2){SetSpeed(GetSpeed+0.04);}
          if(phase==2){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);
             }
          }
       }
    }    
   script_shot shotc{//eei
       let out=false;
       let gr=01;
       let arg=GetArgument;
       let pl=GetAngleToPlayer;
       let ex = GetCommonData("ex");
       let lv=0;
       let time=0;
       @Initialize{
          SetDefault(gr+lv*20);
       }
       @MainLoop {
          if(time%20==10&&arg==3){
             let p=GetAngleToPlayer;
             let a=0;
             loop(20){
                CreateShotFromScript( "shot4",GetX(), GetY(), 3.5, a*18, 0, 05);
                a++;
             }
          }
          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((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);
             }
          }
          if(out==true&&arg==1){
             let p=GetAngleToPlayer;
             let a=0;
             loop(3){
                CreateShotFromScript( "shot1",GetX()+cos(GetAngle+180)*12, GetY()+sin(GetAngle+180)*12, 2.3+a*0.16, p, 0, 13);
                a++;
             }
          }
          if(out==true&&arg==2){
             let p=GetAngleToPlayer;
             let a=0;
             loop(1){
                CreateShotFromScript( "shot1",GetX()+cos(GetAngle+180)*12, GetY()+sin(GetAngle+180)*12, 2, p, 0, 13);
                a++;
             }
          }
       }
    }    

#include_script".\escript.txt"