script_enemy_main {
    let time = -100;
    let phase = 3;
    let sephase = 3;
    let rate = 0;
    let kaku = 80;
    let score = 0;
    let lv = 0;
    let life = 34040;
    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( 34040 );
        SetInvincibility( 0 );
        SetTimer(300);
        LoadGraphic( imgEnemy );
        LoadUserShotData( tama );
        let life = GetLife;
        Tmain1;
    }
    @MainLoop {
        SetCommonData("bossx",GetX);
        SetCommonData("bossy",GetY);
        if(phase==3&&GetLife<=23540){
           phase-=1;
           time=-100;
           score=200000;
           SetCommonData("bossphase",2);
           SetCommonData("bossatack",0);
           if(lv==0||GetPoint>0){DeleteEnemyShotImmediatelyInCircle(SHOT, 224, 240, 600);}
           PlaySE(se2);
           Tdeath(15,100,2,0);
           Tmain2;
           SetCommonData("prerank",GetCommonData("prerank")+1);
        }
        if(phase==2&&GetLife<=13540){
           phase-=1;
           time=-100;
           score=300000;
           SetCommonData("bossphase",1);
           SetCommonData("bossatack",0);
           if(lv==0||GetPoint>0){DeleteEnemyShotImmediatelyInCircle(SHOT, 224, 240, 600);}
           PlaySE(se2);
           Tdeath(15,100,2,0);
           Tshot3a;
           Tshot3b;
           Tshot3c;
           SetCommonData("prerank",GetCommonData("prerank")+1);
        }
        if(phase==1&&GetLife<=40){
           phase-=1;
           score=400000;
           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-70, 90);
           SetCollisionA(GetX+70, GetY+0, 50);
           SetCollisionA(GetX-70, GetY+0, 50);
           SetCollisionA(GetX, GetY+60, 50);
           SetCollisionB(GetX, GetY-60, 90);
        }
        if(sephase==3&&GetLife<=23940){PlaySE(se6);sephase=2;}
        if(sephase==2&&GetLife<=13940){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 );
        SetGraphicRect( 0, 0, 256, 320 );
        SetGraphicAngle(0,0,0);
	DrawGraphic( GetX(), GetY() );

        SetGraphicRect( 512, 64, 800, 352 );
        SetGraphicAngle(0,0,90-50);
	DrawGraphic( GetX()+65, GetY()-70 );
        SetGraphicAngle(180,0,90-50);
	DrawGraphic( GetX()-65, GetY()-70 );


    }

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

        if(phase<=2){return;}
        SetCommonData("bossatack",2);
        Tshot12;
        wait(700);
        if(phase<=2){return;}
        SetCommonData("bossatack",0);
        wait(120);

        if(phase<=2){return;}
        SetCommonData("bossatack",3);
        Tshot13;
        wait(700);
        if(phase<=2){return;}
        SetCommonData("bossatack",0);
        wait(180);

        if(phase<=2){return;}
        SetCommonData("bossatack",1);
        Tshot11;
        wait(800);
        if(phase<=2){return;}
        SetCommonData("bossatack",0);
        wait(80);

        }
    }
    task Tmain2{
        yield;
        wait(180);
        loop(2){

        if(phase<=1){return;}
        SetCommonData("bossatack",1);
        Tshot21;
        wait(700);
        if(phase<=1){return;}
        SetCommonData("bossatack",0);
        wait(240);

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

        if(phase<=1){return;}
        SetCommonData("bossatack",3);
        Tshot23a;
        wait(800);
        if(phase<=1){return;}
        SetCommonData("bossatack",0);
        wait(300);

        }
        loop{

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

        if(phase<=1){return;}
        SetCommonData("bossatack",3);
        Tshot23a;
        wait(900);
        if(phase<=1){return;}
        SetCommonData("bossatack",0);
        wait(300);

        }
    }

    task Tshot11{
        yield;
        let a=0;
        while(GetCommonData("bossatack")==1){
           if(phase<=2){return;}
           let b=0;
           loop(36){
              CreateShotFromScript( "shot1",GetX()+cos(time*3+b*10)*90, GetY+sin(time*3+b*10)*25-110, 3.5, time*3+b*10+a*4.8, 0, 07);
              b++;
           }
           a++;
           PlaySE(seshot2);
           wait(30-lv*5);
        }
    }
    task Tshot12{
        yield;
        let a=rand(0,1);
        while(GetCommonData("bossatack")==2){
           if(phase<=2){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<=2){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 Tshot21{
        yield;
        let a=0;
        while(GetCommonData("bossatack")==1){
           if(phase<=1){return;}
           let b=0;
           loop(1){
              CreateEnemyFromScript("bit", GetX+(a%2-0.5)*120, GetY-130, 0, 90-(a%2-0.5)*(170-sin(a*110)*55), (a%2-0.5)*2);
              b++;
           }
           a+=1;
           wait(30-lv*5);
        }
    }
    task Tshot22{
        yield;
        let a=rand(0,10);
        while(GetCommonData("bossatack")==2){
           let ang=atan2( GetPlayerY()-(GetY()-110), GetPlayerX()-(GetX()));
           loop(2){
              if(phase<=1){return;}
              ang = ang+cos(a*70)*10;
              CreateShotFromScript( "shot5",GetX()+cos(ang)*90, GetY+sin(ang)*25-110, 2.5, ang, 0, 08);
              PlaySE(seshot2);
              wait(40);
              a++;
           }
           wait(200-lv*35);
        }
    }
    task Tshot23a{
        yield;
        let a=rand(0,1);
        while(GetCommonData("bossatack")==3){
           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 Tshot3a{
        wait(900);
        let a=0;
        loop{
           if(phase<=0){return;}
           let b=0;
           loop(45){
              CreateShotFromScript( "shot1",GetX()+cos(time*3+b*8)*90, GetY+sin(time*3+b*8)*25-110, 2.3, time*3+b*8+(a%2-0.5)*180, 0, 11);
              b++;
           }
           a++;
           PlaySE(seshot1);
           wait(70-lv*11);
        }
    }
    task Tshot3b{
        wait(450);
        let a=0;
        loop{
           if(phase<=0){return;}
           let b=0;
           loop(1){
              CreateShotFromScript( "shot5",224+170, 24, 1, 90, 0, 10);
              CreateShotFromScript( "shot5",224-170, 24, 1, 90, 0, 10);
              b++;
           }
           a++;
           wait(130-lv*20);
        }
    }
    task Tshot3c{
        wait(180);
        let a=0;
        loop{
           if(phase<=0){return;}
           let b=0;
           loop(1){
              CreateShotFromScript( "shot5",GetX, GetY-110, 1.6, 90+36*(a%2-0.5)+sin(a*57)*10, 0, (a%2-0.5)*2*11);
              b++;
           }
           a++;
           PlaySE(seshot2);
           wait(150-lv*27);
        }
    }

    #include_function".\efanction.txt"
}
script_enemy bit {
    let time = 0;
    let phase = 1;
    let rate = 0;
    let life = 0;
    let kaku = 30;
    let score = 0;
    let lv = 0;
    let size = 30;
    let bitangle = 0;
    let angle = GetAngle();
    let rank = GetSpeed();
    let arg = GetArgument();
    let spd = GetSpeed();
    let ex = GetCommonData("ex");
    let imgEnemy = GetCurrentScriptDirectory~"img\st3boss.png";
    let tama = GetCurrentScriptDirectory~"tama.txt";
    let se1 = GetCurrentScriptDirectory~"wav\se1.wav";
    let se3 = GetCurrentScriptDirectory~"wav\se3.wav";
    let seshot1 = GetCurrentScriptDirectory~"wav\shot1.wav";
    let seshot2 = GetCurrentScriptDirectory~"wav\shot2.wav";
    @Initialize(){
        SetLife( 120 );
        SetInvincibility( 60 );
        LoadGraphic( imgEnemy );
        LoadUserShotData( tama );
        Tshot1;
        Tkakudo;
    }
    @MainLoop {
        rate=life-GetLife;
        life=GetLife;
        if(phase==1&&GetLife<=100){
           phase-=1;
           PlaySE(se3);
           Tdeatha(3,30,2,1);
        }
        if(phase>=1){
           SetCollisionA(GetX, GetY, 20);
           SetCollisionB(GetX, GetY, 20);
        }
        if(GetCommonData("bossphase")==1){VanishEnemy;}
        lv=GetCommonData("rank");
        time++;
        yield;
    }
    @Finalize() {
    }
    @DrawLoop {
	SetTexture( imgEnemy );
        SetGraphicRect( 512, 0, 560, 48 );
        SetGraphicAngle( 0, 0, time*4);
	DrawGraphic( GetX(), GetY() );
    }
    task Tkakudo{
        SetSpeed(0.5);
        let a=0;
        while(a<240){
           SetAngle(GetAngle+0.8*arg);
           SetSpeed(GetSpeed+0.016);
           wait(1);
           a+=0.8;
        }
        wait(40);VanishEnemy;
    }
    task Tshot1{
        yield;
        loop{
           if(phase==0||GetCommonData("bossphase")==1){return;}
           let a=0;
           loop(1){
              CreateShotFromScript( "shot1",GetX(), GetY(), 2.5+ex*0.5, GetAngle+160*arg, 0, 06);
              CreateShotFromScript( "shot1",GetX(), GetY(), 2.5+ex*0.5, GetAngle-160*arg, 0, 06);
              a++;
           }
           wait(8-lv*1);
        }
    }

    #include_function".\efanction.txt"
}

#include_script".\escript.txt"