script_enemy_main {
    let time = -150;
    let phase = 2;
    let sephase = 2;
    let rate = 0;
    let kaku = 80;
    let score = 0;
    let lv = 0;
    let life = 8740;
    let angle = GetAngle();
    let rank = GetSpeed();
    let arg = GetArgument();
    let ex = GetCommonData("ex");
    SetCommonData("bossx",GetX);
    SetCommonData("bossy",GetY);
    SetCommonData("bossphase",2);
    SetCommonData("bossparts1",0);
    SetCommonData("bossparts2",0);
    SetCommonData("bossatack",0);
    let imgEnemy = GetCurrentScriptDirectory~"img\st1boss.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( 8740 );
        SetInvincibility( 0 );
        SetTimer(180);
        LoadGraphic( imgEnemy );
        LoadUserShotData( tama );
        CreateEnemyFromScript("kata", GetX+127, GetY-30, 0, 0, 1);
        CreateEnemyFromScript("kata", GetX-127, GetY-30, 0, 0, -1);
        CreateEnemyFromScript("mae", GetX+96, GetY+80, 0, 0, 1);
        CreateEnemyFromScript("mae", GetX-96, GetY+80, 0, 0, -1);
        Tmain1;Tmove;
        SetMovePositionHermite(224, 150, 100, 90, 100, 270, 150);
    }
    @MainLoop {
        SetCommonData("bossx",GetX);
        SetCommonData("bossy",GetY);
        if(phase==2&&(GetLife<=4140||GetCommonData("bossparts1")==2)){
           phase-=1;
           time=0;
           score=100000;
           SetCommonData("bossphase",1);
           if(lv==0||GetPoint>0){DeleteEnemyShotImmediatelyInCircle(SHOT, 224, 240, 600);}
           PlaySE(se2);
           Tdeath(15,80,2,0);
           Tmain2;
           sephase=1;
           SetCommonData("prerank",GetCommonData("prerank")+1);
        }
        if(phase==1&&GetLife<=40){
           phase-=1;
           score=150000;
           SetCommonData("bossphase",0);
           if(lv==0||GetPoint>0){DeleteEnemyShotImmediatelyInCircle(SHOT, 224, 240, 600);}
           PlaySE(se2);
           Tdeath(0,80,2,0);
           Tbaku;
           Tbossbaku;
           SetCommonData("prerank",GetCommonData("prerank")+1);
        }
        if(phase>=1&&time>=0){
           SetCollisionA(GetX, GetY-40, 64);
           SetCollisionB(GetX, GetY-40, 70);
           SetCollisionA(GetX, GetY+50, 64);
           SetCollisionB(GetX, GetY+50, 70);

           SetCollisionB(GetX+127, GetY-30, 40);
           SetCollisionB(GetX-127, GetY-30, 40);
        }
        if(sephase==2&&GetLife<=4540){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<920)){SetColor(255,200,200);}
        }

	SetTexture( imgEnemy );
        SetGraphicRect( 480, 0, 577, 97 );
        SetGraphicAngle( 0, 0, time*11);
	DrawGraphic( GetX()+127, GetY()-30 );
        SetGraphicAngle( 180, 0, -time*11);
	DrawGraphic( GetX()-127, GetY()-30 );
        SetGraphicRect( 320, 0, 480, 160 );
        SetGraphicAngle( 0, 0, 0);
	DrawGraphic( GetX()+127, GetY()-30 );
        SetGraphicAngle( 180, 0, 0);
	DrawGraphic( GetX()-127, GetY()-30 );

        SetGraphicRect( 0, 0, 320, 320 );
        SetGraphicAngle(0,0,0);
	DrawGraphic( GetX(), GetY() );

    }

    task Tmain1{
        yield;
        wait(180);
        loop(2){
        if(phase<=1){return;}
        SetCommonData("bossatack",2);
        Tshot12;
        wait(500);
        SetCommonData("bossatack",0);
        wait(100);

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

        if(phase<=1){return;}
        SetCommonData("bossatack",1);
        Tshot11;
        wait(400);
        SetCommonData("bossatack",0);
        wait(40);
        }

        loop{
        if(phase<=1){return;}
        SetCommonData("bossatack",2);
        Tshot12;
        wait(500);
        SetCommonData("bossatack",0);
        wait(100);

        if(phase<=1){return;}
        SetCommonData("bossatack",1);
        Tshot11;
        wait(400);
        SetCommonData("bossatack",0);
        wait(40);
        }
    }
    task Tmain2{
        yield;
        wait(120);
        loop{
        if(phase<=0){return;}
        Fshot21;
        wait(40);

        if(phase<=0){return;}
        SetCommonData("bossatack",2);
        Tshot22a;
        Tshot22b;
        wait(450);
        SetCommonData("bossatack",0);
        wait(100);
        }
    }

    task Tshot11{
        yield;
        let a=0;
        while(GetCommonData("bossatack")==1){
           let p=atan2( GetPlayerY()-(GetY()+80), GetPlayerX()-(GetX()))+sin(a*113)*4;
              if(phase<=1){return;}
              CreateShotFromScript( "shot1",GetX(), GetY()+80, 3.2+ex*0.5, p, 0, 13);
              CreateShotFromScript( "shot1",GetX(), GetY()+80, 3.9+ex*0.4, p, 0, 13);
              if(ex==1){
                 CreateShotFromScript( "shot1",GetX(), GetY()+80, 3.7, p+7, 0, 13);
                 CreateShotFromScript( "shot1",GetX(), GetY()+80, 3.7, p-7, 0, 13);
                 CreateShotFromScript( "shot1",GetX(), GetY()+80, 4.9, p, 0, 13);
              }
           a++;
           PlaySE(seshot1);
           wait(32-lv*5);
        }
    }

    task Tshot12{
        yield;
        while(GetCommonData("bossatack")==2){
           let p1=atan2( GetPlayerY()-(GetY()-25), GetPlayerX()-(GetX()+65))+rand(20,-20);
           let p2=atan2( GetPlayerY()-(GetY()-25), GetPlayerX()-(GetX()-65))+rand(20,-20);
           let a=-1;
           loop(3){
              if(phase<=1){return;}
              let b=-1;
              loop(3+GetCommonData("bossparts1")*2){
                 CreateShotFromScript( "shot1",GetX()+65, GetY()-25, 2.1+ex, p1+b*2.5+a*30, 0, 03);
                 CreateShotFromScript( "shot1",GetX()-65, GetY()-25, 2.1+ex, p2+b*2.5+a*30, 0, 03);
                 b++;
              }
              a++;
           }
           wait(75-lv*10);
        }
    }

    task Tshot13{
        yield;
        while(GetCommonData("bossatack")==3){
           let p=atan2( GetPlayerY()-(GetY()+80), GetPlayerX()-(GetX()));
           let a=0;
           loop(3+ex*3){
              if(phase<=1){return;}
              CreateShotFromScript( "shot1",GetX(), GetY()+80, 2.7+ex, p+a*(20-10*ex), 0, 02);
              CreateShotFromScript( "shot1",GetX(), GetY()+80, 2.7+ex, p-a*(20-10*ex), 0, 02);
              a++;
           }
           wait(67-lv*10);
        }
    }

    function Fshot21{
        yield;
        let a=0;
        loop(3){
           let t=0;
           while(t<60+a*50){
              if(phase<=0){return;}
              let p=atan2( GetPlayerY()-(GetY()-20), GetPlayerX()-(GetX()))+rand(1,-1);
              let b=0.5;
              loop(1){
                 CreateShotFromScript( "shot1",GetX(), GetY()-20, 4.5+ex, p+b*2.5, 0, 12);
                 CreateShotFromScript( "shot1",GetX(), GetY()-20, 4.5+ex, p-b*2.5, 0, 12);
                 b++;
              }
              loop(3+ex){
                 CreateShotFromScript( "shot1",GetX(), GetY()-20, 4.5+ex, p+b*2.5, 0, 12);
                 CreateShotFromScript( "shot1",GetX(), GetY()-20, 4.5+ex, p-b*2.5, 0, 12);
                 b+=8-ex*3;
              }
              PlaySE(seshot1);
              t+=3-lv*0.2;
              wait(3-lv*0.2);
           }
           a++;
           wait(50-lv*9);
        }
    }
    task Tshot22a{
        yield;
        let b=0;
        while(GetCommonData("bossatack")==2){
           if(phase<=0){return;}
           let a=0;
           loop(24){
              let r=a*15+b*5.7;
              CreateShotFromScript( "shot4",GetX()+127+cos(r)*10, GetY()-30+sin(r)*10, 3+ex, r, 0, 05);
              CreateShotFromScript( "shot4",GetX()-127+cos(r)*10, GetY()-30+sin(r)*10, 3+ex, r, 0, 05);
              if(ex==1){
                 CreateShotFromScript( "shot4",GetX()+127+cos(r)*10, GetY()-30+sin(r)*10, 5, r, 0, 05);
                 CreateShotFromScript( "shot4",GetX()-127+cos(r)*10, GetY()-30+sin(r)*10, 5, r, 0, 05);
              }
              a++;
           }
           PlaySE(seshot2);
           wait(70-lv*10);
           b++;
        }
    }
    task Tshot22b{
        yield;
        let b=0;
        while(GetCommonData("bossatack")==2){
           if(phase<=0){return;}
           let a=0;
           if(b%11<6){
           loop(4){
              CreateShotFromScript( "shot1",GetX()+65, GetY()-25, 2.7, a*90+b*1.7+45, 0, 13);
              CreateShotFromScript( "shot1",GetX()-65, GetY()-25, 2.7, a*90-b*1.7, 0, 13);
              if(ex==1){
                 CreateShotFromScript( "shot1",GetX()+65, GetY()-25, 4, a*90+b*1.7+45, 0, 13);
                 CreateShotFromScript( "shot1",GetX()-65, GetY()-25, 4, a*90-b*1.7, 0, 13);
              }
              a++;
           }
           }
           wait(6-lv*1);
           b++;
        }
    }

    task Tmove {
        wait(150);
        loop{
           SetMovePosition02(224+rand(10,-10), 130+rand(10,-10),90);
           wait(90);
           SetMovePosition02(224+rand(10,-10), 130+rand(10,-10),90);
           wait(90);
        }
    }


    #include_function".\efanction.txt"
}

script_enemy kata {
    let time = -150;
    let phase = 2;
    let rate = 10;
    let kaku = 40;
    let score = 12000;
    let lv = 0;
    let stg = false;
    let life = 1400;
    let angle = GetAngle();
    let rank = GetSpeed();
    let arg = GetArgument();
    let ex = GetCommonData("ex");
    let imgEnemy = GetCurrentScriptDirectory~"img\st1boss.png";
    let tama = GetCurrentScriptDirectory~"tama.txt";
    let se1 = GetCurrentScriptDirectory~"wav\se1.wav";
    let se2 = GetCurrentScriptDirectory~"wav\se2.wav";
    let seshot1 = GetCurrentScriptDirectory~"wav\shot1.wav";
    let seshot2 = GetCurrentScriptDirectory~"wav\shot2.wav";
    @Initialize(){
        SetLife( 1400 );
        SetInvincibility( 50 );
        LoadGraphic( imgEnemy );
        LoadUserShotData( tama );
    }
    @MainLoop {
        rate=life-GetLife;
        life=GetLife;
        SetX(GetCommonData("bossx")+127*arg);SetY(GetCommonData("bossy")-30);
        if(phase==2&&(GetLife<=100||GetCommonData("bossphase")==1)){
           phase-=1;
           time=0;
           SetCommonData("bossparts1",GetCommonData("bossparts1")+1);
           PlaySE(se2);
           Tdeath(10,40,2,0);
           SetDamageRateEx(0,0,100,0);
           CreateEnemyFromFile(GetCurrentScriptDirectory~"airitem.txt",GetX,GetY, -3, 0, 3);
           SetCommonData("prerank",GetCommonData("prerank")+0.5);
        }
        if(GetCommonData("bossphase")==0){VanishEnemy;}
        if(phase>=1&&time>=0){
           SetCollisionA(GetX, GetY, 40);
        }
        lv=GetCommonData("rank");
        if(GetCommonData("bossatack")==2&&stg==false){stg=true;Tshot1;}
        if(GetCommonData("bossatack")==3&&stg==false){stg=true;Tshot3;}
        time++;
        yield;
    }
    @Finalize() {
    }
    @DrawLoop {
	SetTexture( imgEnemy );
        if(phase==2||(phase==1&&time<20)){
           if(rate==0){SetColor(255,255,255);}
           else{SetColor(220,220,255);}
           if(time%30<5&&GetLife<400){SetColor(255,200,200);}
           if(phase==1){SetColor(255,180,180);}

           SetGraphicRect( 480, 96, 576, 192 );
           SetGraphicAngle( 90+90*arg, 0, 0);
	   DrawGraphic( GetX(), GetY() );

           SetGraphicRect( 480, 192, 576, 288 );
           SetGraphicAngle( 0, 0, GetAngleToPlayer-90);
	   DrawGraphic( GetX(), GetY() );
        }
    }

    task Tshot1{
        yield;
        wait(30);
        while(GetCommonData("bossatack")==2){
           let p=GetAngleToPlayer;
           loop(7){
              if(phase<=1){return;}
              let a=0;
              loop(1+GetCommonData("bossparts1")){
                 CreateShotFromScript( "shot1",GetX()+cos(p+10)*(20-a*4), GetY()+sin(p+10)*(20-a*4), 3.1-a*0.1+ex, p+a*2, 0, 12);
                 CreateShotFromScript( "shot1",GetX()+cos(p-10)*(20-a*4), GetY()+sin(p-10)*(20-a*4), 3.1-a*0.1+ex, p-a*2, 0, 12);
                 a++;
              }
              PlaySE(seshot1);
              wait(3);
           }
           wait(80-lv*14);
        }
        stg=false;
    }
    task Tshot3{
        yield;
        if(phase<=1){return;}
        CreateEnemyFromScript("bit", GetX, GetY, 1, 90, -arg);
        wait(50);
        if(phase<=1){return;}
        if(GetCommonData("bossparts1")==1){CreateEnemyFromScript("bit", GetX, GetY, 1, 90+40*arg, -arg);}
        wait(260);
        stg=false;
    }


    #include_function".\efanction.txt"
}

script_enemy mae {
    let time = -150;
    let phase = 1;
    let rate = 10;
    let kaku = 10;
    let score = 10000;
    let lv = 0;
    let stg = false;
    let life = 800;
    let angle = GetAngle();
    let rank = GetSpeed();
    let arg = GetArgument();
    let ex = GetCommonData("ex");
    let imgEnemy = GetCurrentScriptDirectory~"img\st1boss.png";
    let tama = GetCurrentScriptDirectory~"tama.txt";
    let se1 = GetCurrentScriptDirectory~"wav\se1.wav";
    let se2 = GetCurrentScriptDirectory~"wav\se2.wav";
    @Initialize(){
        SetLife( 800 );
        SetInvincibility( 50 );
        LoadGraphic( imgEnemy );
        LoadUserShotData( tama );
    }
    @MainLoop {
        rate=life-GetLife;
        life=GetLife;
        SetX(GetCommonData("bossx")+96*arg);SetY(GetCommonData("bossy")+80);
        if(phase==1&&GetLife<=100){
           phase-=1;
           SetCommonData("bossparts2",GetCommonData("bossparts2")+1);
           PlaySE(se2);
           Tdeath(10,30,2,1);
           CreateEnemyFromFile(GetCurrentScriptDirectory~"airitem.txt",GetX,GetY, -3, 0, 2);
           SetCommonData("prerank",GetCommonData("prerank")+0.5);
        }
        if(phase>=1&&time>=0){
           SetCollisionA(GetX, GetY, 16);
           SetCollisionB(GetX, GetY, 16);
           SetCollisionB(GetX, GetY-30, 16);
        }
        if(GetCommonData("bossphase")==0){VanishEnemy;}
        lv=GetCommonData("rank");
        if(GetCommonData("bossatack")==1&&stg==false){stg=true;Tshot1;}
        time++;
        yield;
    }
    @Finalize() {
    }
    @DrawLoop {
        if(rate==0){SetColor(255,255,255);}
        else{SetColor(220,220,255);}
        if(time%30<5&&GetLife<400){SetColor(255,200,200);}
        if(phase==0){SetColor(255,180,180);}

	SetTexture( imgEnemy );
        SetGraphicRect( 320, 160, 416, 320 );
        SetGraphicAngle( 90-90*arg, 0, 0);
	DrawGraphic( GetX(), GetY() );
    }

    task Tshot1{
        yield;
        while(GetCommonData("bossatack")==1){
           if(phase<=0||GetCommonData("bossphase")==1){return;}
           let p=GetAngleToPlayer;
           CreateShotFromScript( "shot1",GetX(), GetY(), 4+ex, 90, 0, 12);
           CreateShotFromScript( "shot1",GetX()+8, GetY(), 4+ex, 90, 0, 12);
           CreateShotFromScript( "shot1",GetX()-8, GetY(), 4+ex, 90, 0, 12);
           wait(37-lv*7);
        }
        stg=false;
    }

    #include_function".\efanction.txt"
}
script_enemy bit {
    let time = 0;
    let phase = 1;
    let rate = 0;
    let life = 0;
    let kaku = 30;
    let score = 1000;
    let lv = 0;
    let size = 30;
    let bitangle = 0;
    let angle = GetAngle();
    let rank = GetSpeed();
    let arg = GetArgument();
    let ex = GetCommonData("ex");
    let imgEnemy = GetCurrentScriptDirectory~"img\st1boss.png";
    let tama = GetCurrentScriptDirectory~"tama.txt";
    let se1 = GetCurrentScriptDirectory~"wav\se1.wav";
    let se2 = GetCurrentScriptDirectory~"wav\se2.wav";
    @Initialize(){
        SetLife( 120 );
        SetInvincibility( 60 );
        LoadGraphic( imgEnemy );
        LoadUserShotData( tama );
        Tshot1;
        Tmain;
    }
    @MainLoop {
        rate=life-GetLife;
        life=GetLife;
        if(phase==1&&GetLife<=100){
           phase-=1;
           SetCommonData("bossparts2",GetCommonData("bossparts2")+1);
           PlaySE(se2);
           Tdeath(10,30,2,1);
           CreateEnemyFromFile(GetCurrentScriptDirectory~"airitem.txt",GetX+30,GetY+30, 0, 0, 1);
           CreateEnemyFromFile(GetCurrentScriptDirectory~"airitem.txt",GetX+30,GetY-30, 0, 0, 1);
           CreateEnemyFromFile(GetCurrentScriptDirectory~"airitem.txt",GetX-30,GetY+30, 0, 0, 1);
           CreateEnemyFromFile(GetCurrentScriptDirectory~"airitem.txt",GetX-30,GetY-30, 0, 0, 1);
        }
        if(phase>=1){
           SetCollisionA(GetX, GetY, 40);
           SetCollisionB(GetX, GetY, 40);
        }
        if(GetCommonData("bossphase")==1){VanishEnemy;}
        lv=GetCommonData("rank");
        time++;
        yield;
    }
    @Finalize() {
    }
    @DrawLoop {
	SetTexture( imgEnemy );
        SetGraphicRect( 576, 0, 608, 32 );
        let a=0;
        loop(8){
           SetGraphicAngle( 0, 0, a*45+time*arg+cos(time*3)*45*arg-90);
	   DrawGraphic( GetX()+cos(a*45+time*arg)*40, GetY()+sin(a*45+time*arg)*40 );
           a++;
        }
    }
    task Tmain{
        SetSpeed(0);
        wait(30);
        loop(120){SetSpeed(GetSpeed+0.01);wait(1);}
    }

    task Tshot1{
        yield;
        wait(rand(5,20));
        while(GetY<400){
           if(phase==0||GetCommonData("bossphase")==1){return;}
           let a=0;
           loop(8){
              let r=a*45+time*arg;
              CreateShotFromScript( "shot1",GetX()+cos(r)*40, GetY()+sin(r)*40, 2.5+ex*0.5, r+cos(time*3)*45*arg, 0, 12);
              if(ex==1){CreateShotFromScript( "shot1",GetX()+cos(r)*40, GetY()+sin(r)*40, 4, r+cos(time*3)*45*arg, 0, 12);}
              a++;
           }
           wait(85-lv*15);
        }
    }

    #include_function".\efanction.txt"
}
#include_script".\escript.txt"