script_enemy_main {
    let time = -60;
    let phase = 3;
    let sephase = 3;
    let rate = 0;
    let kaku = 80;
    let score = 0;
    let lv = 0;
    let life = 25020;
    let angle = GetAngle();
    let rank = GetSpeed();
    let arg = GetArgument();
    let ex = GetCommonData("ex");
    let ky = 180;
    let kx = 0;
    let bity = 35;
    let bitspeed = 0.7;
    let bitmuki = 1;
    SetCommonData("bossx",GetX);
    SetCommonData("bossy",GetY);
    SetCommonData("bossphase",2);
    SetCommonData("bossparts1",0);
    SetCommonData("bossparts2",0);
    SetCommonData("bossatack",0);
    let imgEnemy = GetCurrentScriptDirectory~"img\trueboss.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( 21020 );
        SetInvincibility( 0 );
        SetTimer(300);
        SetDamageRate(100,0);
        LoadGraphic( imgEnemy );
        LoadUserShotData( tama );
        let life = GetLife;
        Tmain1;
        Tmove;
        SetMovePositionHermite( 224, 180, 400, 140, 500, 70, 60);
    }
    @MainLoop {
        SetCommonData("bossx",GetX);
        SetCommonData("bossy",GetY);
        if(phase==1&&GetTimeOfPlayerInvincibility>0){SetInvincibility( 10 );}
        if(phase==3&&GetLife<=13520){
           phase-=1;
           time=-100;
           score=30000;
           SetCommonData("bossphase",2);
           SetCommonData("bossatack",0);
           if(lv==0||GetPoint>0){DeleteEnemyShotImmediatelyInCircle(SHOT, 224, 240, 600);}
           PlaySE(se2);
           Tdeath(15,100,2,0);
           Tmain2;ky=100;kx=0;
        }
        if(phase==2&&GetLife<=6520){
           phase-=1;
           time=-100;
           score=40000;
           SetCommonData("bossphase",1);
           SetCommonData("bossatack",0);
           if(lv==0||GetPoint>0){DeleteEnemyShotImmediatelyInCircle(SHOT, 224, 240, 600);}
           PlaySE(se2);
           Tdeath(15,100,2,0);
           ky=180;Tshot3;Tmove1;
        }
        if(phase==1&&GetLife<=20){
           phase-=1;
           time=-100;
           score=60000;
           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;
        }
        if(phase>0&&time>=0){
           SetCollisionA(GetX, GetY, 40);
           SetCollisionB(GetX, GetY, 40);
           SetCollisionA(GetX+60, GetY, 50);
           SetCollisionA(GetX-60, GetY, 50);
        }
        if(sephase==3&&GetLife<=13920){PlaySE(se6);sephase=2;}
        if(sephase==2&&GetLife<=6920){PlaySE(se6);sephase=1;}
        if(sephase==1&&GetLife<=420){PlaySE(se6);sephase=0;}
        if(GetCommonData("kakusei")>0){lv=1}
        else{lv=0}
        if(phase==2&&time>80){
           bity+=bitspeed*bitmuki;
           if(bity>460&&bitmuki>0){bitmuki*=-1;}
           if(bity<20&&bitmuki<0){bitmuki*=-1;}
        }
        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);}
        }
        if(phase==3&&time<=0){
           SetGraphicScale(1.0+time/100,1.0+time/100);
        }


	SetTexture( imgEnemy );
        SetGraphicRect( 0, 0, 256, 320 );
        SetGraphicAngle(0,0,0);
	DrawGraphic( GetX(), GetY()+25 );
        if(phase==2&&time>0){
           SetGraphicRect( 256, 0, 352, 96 );
           SetColor(255,255,255);
           SetGraphicAngle(0,0,time*37);
	   DrawGraphic( 224+185, bity );
	   DrawGraphic( 224-185, 480-bity );
        }
        if(phase==1&&GetTimeOfPlayerInvincibility>0){
           SetAlpha(100);
           SetGraphicRect( 256, 96, 384, 223 );
	   DrawGraphic( GetX(), GetY()+10 );
           SetAlpha(255);
        }



    }

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


        if(phase<=2){return;}
        SetCommonData("bossatack",1);
        Tshot11;ky=180;
        wait(420);
        if(phase<=2){return;}
        SetCommonData("bossatack",0);
        wait(140-lv*60);

        if(phase<=2){return;}
        SetCommonData("bossatack",3);
        Tshot13;ky=150;kx=60;
        wait(280);
        if(phase<=2){return;}
        SetCommonData("bossatack",0);kx=0;
        wait(90-lv*40);

        if(phase<=2){return;}
        SetCommonData("bossatack",4);
        Tshot14a;Tshot14b;ky=180;
        wait(470);
        if(phase<=2){return;}
        SetCommonData("bossatack",0);
        wait(120-lv*50);


        if(phase<=2){return;}
        SetCommonData("bossatack",2);
        Tshot12;ky=150;
        wait(130);
        if(phase<=2){return;}
        SetCommonData("bossatack",0);
        wait(50-lv*25);


        }
    }
    task Tmain2{
        yield;
        wait(180);
        Tshot2;
        bity = 35;
        loop{

        if(phase<=1){return;}
        SetCommonData("bossatack",1);
        wait(120);
        Tshot21;
        while(bitspeed<1.8){bitspeed+=0.01;wait(1);}
        wait(650);
        if(phase<=1){return;}
        SetCommonData("bossatack",0);
        while(bitspeed>0.7){bitspeed-=0.01;wait(1);}

        if(phase<=1){return;}
        SetCommonData("bossatack",2);
        Tshot22;
        wait(300);
        if(phase<=1){return;}
        SetCommonData("bossatack",0);
        }
    }

    task Tshot11{
        yield;
        let a=0;
        while(GetCommonData("bossatack")==1){
           if(phase<=2){return;}
           let b=0;
           let c=0;
           if(a%3==1){c=1}
           let x=GetX+rand(130,-130);
           let y=GetY+rand(50,-50)-40;
           loop(24){
              CreateShotFromScript( "shota", x, y, (a%2-0.5)*2, b*15, 0, c);
              b++;
           }
           a++;
           PlaySE(seshot2);
           wait(14-lv*7);
        }
    }
    task Tshot12{
        yield;
        let a=0;
        while(GetCommonData("bossatack")==2){
           if(phase<=2){return;}
           let b=0;
           loop(120){
              let x=GetX()+cos(b*71)*sin(rand(0,360))*130;
              let y=GetY()+sin(b*71)*sin(rand(0,360))*80-40;
              CreateShotFromScript( "shot2", x, y, rand(1,4), b*120+rand(50,-50), 0, 02);
              b++;
           }
           a++;
           PlaySE(seshot2);
           wait(60-lv*30);
        }
    }

    task Tshot13{
        yield;
        let a=0;
        while(GetCommonData("bossatack")==3){
           if(phase<=2){return;}
           let b=0;
           let c=rand_int(8,-8);
           loop(3){
              Tshot13a(b*120+a);
              b++;
           }
           a+=rand(67,72);
           wait(4-lv*2);
        }
    }
    task Tshot13a(ang){
        yield;
        let a=0;
        loop(7){
           if(phase<=2){return;}
           CreateShotFromScript( "shote", GetX, GetY, 4.2+a*0.7, ang, 0, 0);
           a++;
           PlaySE(seshot1);
           wait(2);
        }
    }
    task Tshot14a{
        yield;
        let a=0;
        while(GetCommonData("bossatack")==4){
           if(phase<=2){return;}
           let b=0;
           loop(1){
              CreateShotFromScript( "shot3", GetX+80, GetY-10, 0.07, 93+sin(a*15)*20, 0, 13);
              CreateShotFromScript( "shot3", GetX-80, GetY-10, 0.07, 87+sin(a*15)*20, 0, 13);
              CreateShotFromScript( "shot3", GetX+80, GetY-10, 0.07, 93+sin(a*15)*20-25, 0, 13);
              CreateShotFromScript( "shot3", GetX-80, GetY-10, 0.07, 87+sin(a*15)*20+25, 0, 13);
              b++;
           }
           a++;
           PlaySE(seshot1);
           wait(6-lv*3);
        }
    }
    task Tshot14b{
        yield;
        let a=0;
        while(GetCommonData("bossatack")==4){
           if(phase<=2){return;}
           let b=-5+rand(0.5,-0.5);
           loop(11){
              CreateShotFromScript( "shot1", GetX, GetY, 3, GetAngleToPlayer+b*10, 0, 05);
              b++;
           }
           a++;
           PlaySE(seshot2);
           wait(12-lv*6);
        }
    }
    task Tshot2{
        yield;
        let a=0;
        loop{
           if(phase<=1){return;}
           if(a%15<8){
              let b=-1.5;
              loop(4){
                 CreateShotFromScript( "shot1", 224+185, bity, 3, 180+b*20, 0, 11);

                 CreateShotFromScript( "shot1", 224-185, 480-bity, 3, 0+b*20, 0, 11);

                 /*CreateShotFromScript( "shot1", 224+185, GetPlayerY, 3, 180, 0, 11);

                 CreateShotFromScript( "shot1", 224-185, GetPlayerY, 3, 0, 0, 11);*/
                 b++;
              }
              PlaySE(seshot1);
           }
           a++;
           wait(3-lv*1);
        }
    }
    task Tshot21{
        yield;
        let a=0;
        let c=0;
        while(GetCommonData("bossatack")==1){
           if(phase<=1){return;}
           if(a>360){a-=360;}
           let d=a;
           if(d>180){d*=-1;}
           let b=-3;
           loop(7){
              CreateShotFromScript( "shotb", GetX+cos(d+b*10)*30, GetY+sin(d+b*10)*30, trunc(50-c*1.2), d+b*5, 0, b*7);
              b++;
           }
           a+=rand(65,75)/3;
           PlaySE(seshot2);
           c+=0.4-lv*0.2;
           wait(10-lv*5);
        }
    }
    task Tshot22{
        yield;
        let a=0;
        wait(40);
        while(GetCommonData("bossatack")==2){
           if(phase<=1){return;}
           let b=0;
           loop(1){
              CreateShotFromScript( "shot4", GetX, GetY, rand(4,6), 90+rand(60,-60), 0, 01);
              b++;
           }
           a++;
           PlaySE(seshot2);
           wait(4-lv*2);
        }
    }
    task Tshot3{
        wait(150);
        let a=0;
        let b=0;
        let c=0;
        loop{
           if(phase<=0){return;}
           let d=0;
           loop(2){
              CreateShotFromScript( "shotd", GetX+rand(30,-30), GetY+rand(30,-20), 0, d*180+a*27+rand(20,-20), 0, 1);
              CreateShotFromScript( "shotd", GetX+rand(30,-30), GetY+rand(30,-20), 0, d*180+a*27+rand(20,-20), 0, -1);
              d++;
           }
           a++;b++;
           c+=b*1.6;
           PlaySE(seshot1);
           wait(2-lv*1);
        }
    }
    task Tshot3a{
        yield;
        let a=0;
        wait(150);
        loop{
           if(phase<=0){return;}
           let b=0;
           loop(5){
              CreateShotFromScript( "shot1", GetX, GetY, 4.5, (b*64+a*4)%320+110, 0, 01);
              CreateShotFromScript( "shot1", GetX, GetY, 4.5, -(b*64+a*4)%320+70, 0, 01);
              b++;
           }
           a++;
           PlaySE(seshot1);
           wait(4-lv*2);
        }
    }

    task Tmove {
        wait(60);
        let a=0;
        loop{
           if(phase<=1){return;}
           SetMovePosition02(224+rand(50,-50)+kx*(a%2-0.5)*2, ky+rand(35,-35),40);
           wait(40);
           a++;
        }
    }
    task Tmove1 {
        let a=0;
        loop{
           let b=GetPlayerX;
           if(b>224+40){b=224+40}
           if(b<224-40){b=224-40}
           SetMovePosition02(b+rand(35,-35), ky+rand(35,-35),40);
           wait(40);
           a++;
        }
    }


    #include_function".\efanction.txt"
}

   script_shot shota{//二択
       let out=false;
       let gr=05;
       let arg=GetArgument;
       let spin=GetSpeed;
       let lv=0;
       let time=0;
       let ex = GetCommonData("ex");
       @Initialize{
          SetDefault(gr+lv*20);
          SetSpeed(6);
       }
       @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}
          if(time<80){
             SetAngle(GetAngle+6*spin);
          }
          if(time==80&&arg==1){SetAngle(GetAngleToPlayer);}
          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);
             }
          }
       }
    }    
   script_shot shotb{//縮む
       let out=false;
       let gr=02;
       let arg=GetArgument;
       let magari=GetSpeed;
       let lv=0;
       let time=0;
       let ex = GetCommonData("ex");
       @Initialize{
          SetDefault(gr+lv*20);
          SetSpeed(3);
       }
       @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}
          if(time==magari){SetAngle(GetAngle-arg*2);}
          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);
             }
          }
       }
    }  
   script_shot shotc{//弾を撃つ弾直進
       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);
          SetSpeed(3);
       }
       @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%7==0&&time<90){
              CreateShotFromScript( "shot1", GetX, GetY, 3, GetAngle-90*arg, 0, 12);
          }
          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 shotd{//発狂
       let out=false;
       let gr=09;
       let arg=GetArgument;
       let spin=GetAngle;
       /*let xspd=GetSpeed;*/
       let xspd=2.4;
       let ykasoku=0.035*arg;
       let yspd=-1.5*arg;
       let xkioku=GetX;
       let lv=0;
       let time=0;
       let ex = GetCommonData("ex");
       @Initialize{
          SetDefault(gr+lv*20);
          SetAngle(90);
          SetSpeed(1);
       }
       @MainLoop {
          if(GetX<20||GetX>428||GetY<20||GetY>460){
             out=true;
             End;
          }
          if(GetCommonData("kakusei")>0){
             lv=1;
             if(GetPoint==0){lv=2;yspd+=0.02*arg;xspd*=1.003}
          }
          else{lv=0}

          yspd+=ykasoku;
          SetY(GetY+yspd);
          spin+=xspd;
          SetX(xkioku+sin(spin)*(90+time*0.45));

          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);
             }
          }
       }
    }    
   script_shot shote{//うにょ
       let out=false;
       let gr=13;
       let phase=1;
       let lv=0;
       let time=0;
       let ex = GetCommonData("ex");
       @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}
          if(GetSpeed<0.6){phase++;}
          if(phase==1){SetSpeed(GetSpeed-0.1)}
          else{SetSpeed(GetSpeed+0.1)}
          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);
             }
          }
       }
    }  
#include_script".\escript.txt"