
script_enemy_main
{
    let count=0;
    let count2=0;
    let count3=0;
    let count4=0;
    let ye=0;
    let ye2=0;
    let get;
    let try;
    let alp=255;
    let falp=255;
    let la=0;
    let sca=100;
    let om=0;
    let life=0;
    let item=0;
    let N15=80;
    let N16=0;//ショット撃つときの炎
    let N17=0;//付いてくる炎
    let N18=0;
    let N19=0;
    let N20=0;
    let N21=0;
    let xs=0;
    let ys=0;
    let h=0;
    let h2=0;
    let scoreZ=0;
    let OldX=[];
    let OldY=[];
    ascent(i in 0..230)
    {
        OldX = OldX ~ [i];
        OldY = OldY ~ [i];
        i++;
    }
    let mX=0;
    let mY=0;
    let Xloop=0.5;
    let Yloop=0.3;

    let i=0;
    let c=0;
    let c2=0;

    let move=0;

    let pass=GetCurrentScriptDirectory~"Spell.dat";

    let cx=GetCenterX();
    let img=GetCurrentScriptDirectory~"\img\kyozou2.png";
    let mm=0;
    let shot=0;
    let tame=0;
    let tame2=0;
    let pat=0;
    let d=70;
    let ten=0;
    let damage=0;

    task CreateShot021(let x, let y, let speed, let angle, let Accelerate, let MaxSpeed, let grf, let delay)
    {
        let obj = Obj_Create(OBJ_SHOT);
        let N15 = 0;
        Obj_SetX(obj, x);
        Obj_SetY(obj, y);
        Obj_SetSpeed(obj, speed);
        Obj_SetAngle(obj, angle);
        ObjShot_SetGraphic(obj, grf);
        ObjShot_SetDelay(obj, delay);
        ObjShot_SetBombResist(obj,true);
        if (Accelerate<0) {
            N15=1;
        }
        if (Accelerate>0) {
            N15=2;
        }
        while ( !Obj_BeDeleted(obj) )
        {
            if (speed>MaxSpeed&&N15==1) {
                Obj_SetSpeed(obj, speed+Accelerate);
            }
            if (speed<MaxSpeed&&N15==1) {
                Obj_SetSpeed(obj, MaxSpeed);
            }
            if (speed<MaxSpeed&&N15==2) {
                Obj_SetSpeed(obj, speed+Accelerate);
            }
            if (speed>MaxSpeed&&N15==2) {
                Obj_SetSpeed(obj, MaxSpeed);
            }
            yield;
        }
    }

    task Homing(let x, let y, let speed, let angle, let delay)
    {
        //弾タスク初期化
        let count = 0;
        let obj = Obj_Create(OBJ_SHOT);//弾オブジェクトを作成
        Obj_SetX(obj, x);//x座標設定
        Obj_SetY(obj, y);//y座標設定;
        Obj_SetSpeed(obj, speed);//速度設定
        Obj_SetAngle(obj, angle);//移動角度設定
        ObjShot_SetGraphic(obj, 255);//画像設定
        ObjShot_SetDelay(obj, delay);//遅延時間設定
        let dAngle=2;

        while ( !Obj_BeDeleted(obj) )
        {
            //ホーミング
            let toAngle=atan2(GetPlayerY()-Obj_GetY(obj), GetPlayerX()-Obj_GetX(obj));
            if (toAngle>=360) {
                toAngle-=360;
            }
            if (toAngle<0) {
                toAngle+=360;
            }
            let ret=toAngle-angle;
            if ((ret>0&&ret<=180)||(ret<=0&&ret<=-180)) {
                angle+=dAngle;
            }
            if ((ret>0&&ret>180)||(ret<=0&&ret>-180)) {
                angle-=dAngle;
            }
            if (angle>=360) {
                angle-=360;    //360°以上なら0〜360内に補正
            }
            if (angle<0) {
                angle+=360;    //0°未満なら0〜360内に補正
            }
            Obj_SetAngle(obj, angle);
            Obj_SetSpeed(obj, speed);
            ObjShot_SetBombResist(obj,true);
            if (count>=9&&dAngle>0.2) {
                dAngle-=0.1;
                speed-=0.2;
            }
            if (count>=9&&dAngle<=0.2) {
                dAngle=0.2;
            }
            if (count>=120) {
                speed+=0.005;
            }
            count++;
            yield;
        }
    }


    function CreateWayShot02(Way,Gap,PosX,PosY,Dist,Speed,Angle,Accelerate,MaxSpeed,Graphic,Delay) {
        if (Graphic==100||Graphic==211) {
            ascent(let i in 0..Way) {
                CreateShot021(PosX+Dist*cos(Angle+Gap*(i+0.5-(Way * 0.5))),PosY+Dist*sin(Angle+Gap*(i+0.5-(Way * 0.5))),Speed,Angle+Gap*(i+0.5-(Way*0.5)),Accelerate,MaxSpeed,Graphic,Delay);
            }
        }
        else {
            ascent(let i in 0..Way) {
                CreateShot02(PosX+Dist*cos(Angle+Gap*(i+0.5-(Way * 0.5))),PosY+Dist*sin(Angle+Gap*(i+0.5-(Way * 0.5))),Speed,Angle+Gap*(i+0.5-(Way*0.5)),Accelerate,MaxSpeed,Graphic,Delay);
            }
        }
    }

#include_function ".\BGfx.txt"

    @Initialize()
    {
        MagicCircle(false);
        SetEnemyMarker(true);
        SetCommonData("P01",0);
        SetCommonData("P02",0);
        SetCommonData("P03",0);
        SetCommonData("P04",0);
        SetCommonData("Go",-5);
        SetLife(2000000);
        SetDamageRate(20,2);
        SetTimer(20000);
        SetNormPoint(-1);
        LoadGraphic(img);
        SetShotAutoDeleteClip(32,32,32,32);
        SetMovePositionRandom01(0,200,8,cx,120,cx,120);
        LoadGraphic(GetCurrentScriptDirectory~"\img\circle_l.png");
        LoadUserShotData(GetCurrentScriptDirectory~".\shot_All.txt");
        i=228;
        while (i>0) {
            OldX[i]=0;
            OldY[i]=0;
            i--;
        }

    }

    @MainLoop()
    {


        if (count%4==0) {
            life=GetLife();
        }
        if (GetLife()>=9000) {
            if (count%4==3&&GetLife()<life&&8000<life) {
                AddLife(-2400+1200*(pat==4));
                ten=1;
            }
            if (count%4==3&&GetLife()<life&&8000<life&&GetPlayerY-GetY>=-140&&GetPlayerY-GetY<=140&&OnBomb==false) {
                AddLife(-2400+1200*(pat==4));
            }
            if (ten==1&&count%4==1) {
                ten=0;
            }
        }

        if (count2>80&&count2<230&&alp>0) {
            alp-=5;
        }


        if (pat==0)
        {
            SetCommonDataEx("Spell","omake02",1);
            SetCommonData("x",GetX);
            SetCommonData("y",GetY);

            if (count2>1800&&count2<=3550) {
                OldX[0]=GetX;
                OldY[0]=GetY;
                i=228;
                while (i>=0) {
                    OldX[i+1]=OldX[i];
                    OldY[i+1]=OldY[i];
                    i--;
                }
            }


            if (count4>=260&&c<3.5) {
                c+=0.01;
            }

            if (count4==280) {//SetCommonData("Go",1);
                if (GetScore()>=1000000000||GetCommonDataDefault("bomb",0)==2) {
                    scoreZ=1;
                }
                tame2=99;
            }

            if (count4>=800&&count4<1725&&count4%25==0)
            {
                mm=0;
                mm+=GetAngleToPlayer();
                tame=0;
                tame+=rand(-20,20);
            }

            if (count4>=875&&count4<1075) {
                tame2-=0.25;
            }

            if (count2>3450) {
                if (count4>=200&&count4<=720&&count%120==0) {
                    PlaySE(GetCurrentScriptDirectory~"\se\mizu08.wav");
                    CreateEnemyFromFile(GetCurrentScriptDirectory~"Enemy14.txt",GetX(),GetY(),rand(5,7.8),90-33+rand(-5,25),0);
                }

                if (count4>=200&&count4<=720&&count%120==60) {
                    PlaySE(GetCurrentScriptDirectory~"\se\mizu08.wav");
                    CreateEnemyFromFile(GetCurrentScriptDirectory~"Enemy14.txt",GetX(),GetY(),rand(5,7.8),90+33+rand(-25,5),0);
                }

                if (count4>20&&count4<800&&count4%12==2) {
                    PlaySE(GetCurrentScriptDirectory~"\se\Shot02.wav");
                    CreateWayShot02(12,30,GetX,GetY,110,5.2,mm+22-count*0.5,0,8,72,14);
                    CreateWayShot02(12,30,GetX,GetY,110,5.2,mm-22-count*0.5,0,8,72,14);
                }
                if (count4>=600&&count4<900&&count4%44==0) {
                    SetSpeed(0);
                    SetMovePositionRandom01(rand(20,70),rand(10,40),2,cx-84,88,cx+84,168);
                    PlaySE(GetCurrentScriptDirectory~"\se\Beam.wav");
                    CreateWayShot02(60,6,GetX,GetY,49,4.8,GetAngleToPlayer+3,0,8,100,24);
                }
                if (count4>=900&&count4<1100&&count4%34==0) {
                    SetSpeed(0);
                    SetMovePositionRandom01(rand(20,70),40,2,GetCenterX()-84,88,GetCenterX()+84,168);
                    PlaySE(GetCurrentScriptDirectory~"\se\Beam.wav");
                    CreateWayShot02(60,6,GetX,GetY,49,4.8,GetAngleToPlayer+3,0,8,100,24);
                }
                if (count4>=1100&&count4<1150&&count4%14==0) {
                    SetSpeed(0);
                    SetMovePositionRandom01(rand(20,70),40,7,GetCenterX()-84,88,GetCenterX()+84,168);
                    PlaySE(GetCurrentScriptDirectory~"\se\Beam.wav");
                    CreateWayShot02(72,5,GetX,GetY,49,5.8,GetAngleToPlayer+2.5,0,8,100,24);
                }
            }

            if (count2<=3450) {
                if (count4>280&&count4<600&&count4%6==0) {
                    PlaySE(GetCurrentScriptDirectory~"\se\Shot04.wav");
                    CreateWayShot02(10,36,GetX,GetY,tame2,-1.5+count4*0.01,GetAngleToPlayer+(5+(count4-250)*0.05)*sin(count4*(2+(count4-250)*0.001))+22.5,0,8,170,24);
                    CreateWayShot02(10,36,GetX,GetY,tame2,-1.5+count4*0.01,GetAngleToPlayer+(5+(count4-250)*0.05)*sin(count4*(2+(count4-250)*0.001))+22.5,0,8,196,24);
                }

                if (count4>=600&&count4<900&&count4%5==0) {
                    PlaySE(GetCurrentScriptDirectory~"\se\Shot04.wav");
                    CreateWayShot02(10,36,GetX,GetY,tame2,-1.5+count4*0.01,GetAngleToPlayer+(5+(count4-250)*0.05)*sin(count4*(2+(count4-250)*0.001))+22.5,0,8,170,24);
                    CreateWayShot02(10,36,GetX,GetY,tame2,-1.5+count4*0.01,GetAngleToPlayer+(5+(count4-250)*0.05)*sin(count4*(2+(count4-250)*0.001))+22.5,0,8,196,24);
                }

                if (count%120==60&&count4>550&&count4<1050) {
                    PlaySE(GetCurrentScriptDirectory~"\se\mizu08.wav");
                    CreateEnemyFromFile(GetCurrentScriptDirectory~"Enemy14.txt",GetX(),GetY(),rand(4.5,4.8),90-43+rand(-15,15),0);
                }
                if (count%120==0&&count4>550&&count4<1050) {
                    PlaySE(GetCurrentScriptDirectory~"\se\mizu08.wav");
                    CreateEnemyFromFile(GetCurrentScriptDirectory~"Enemy14.txt",GetX(),GetY(),rand(4.5,4.8),90+43+rand(-15,15),0);
                }
                if (count%20==0&&count4>1080&&count4<1150) {
                    PlaySE(GetCurrentScriptDirectory~"\se\mizu08.wav");
                    CreateEnemyFromFile(GetCurrentScriptDirectory~"Enemy14.txt",GetX(),GetY(),5,90+(count-1050),0);
                    CreateEnemyFromFile(GetCurrentScriptDirectory~"Enemy14.txt",GetX(),GetY(),5,90-(count-1050),0);
                }
                if (count4>=600&&count4<1150&&count4%64==0) {
                    SetSpeed(0);
                    SetMovePositionRandom01(rand(20,70),40,1,GetCenterX()-84,88,GetCenterX()+84,168);
                }
            }

            if (count4>=900&&count4<1055&&count4%6==2) {
                PlaySE(GetCurrentScriptDirectory~"\se\Shot04.wav");
                CreateWayShot02(10,36,GetX,GetY,tame2,-1.5+count4*0.01,GetAngleToPlayer+(5+(730-250)*0.05)*sin(count4*(2+(count4-250)*0.001))+22.5,0,8,170,24);
                CreateWayShot02(10,36,GetX,GetY,tame2,-1.5+count4*0.01,GetAngleToPlayer+(5+(730-250)*0.05)*sin(count4*(2+(count4-250)*0.001))+22.5,0,8,196,24);
            }

            if (count4==1170) {
                SetSpeed(0);
                SetMovePositionRandom01(45,40,0.4,GetCenterX(),118,GetCenterX(),118);
            }

            if (count4>=1170&&count4<=1220&&N16<100) {
                N16++;
            }

            if (count4==250) {
                PlaySE(GetCurrentScriptDirectory~"\se\warp.wav");
            }
            if (count4>=250&&count4<350&&om<100) {
                om+=1;
            }

            if (count4>1250&&count4<1525&&count4%6==0) {
                PlaySE(GetCurrentScriptDirectory~"\se\Shot04.wav");
                PlaySE(GetCurrentScriptDirectory~"\se\Beam.wav");
                CreateWayShot02(5,24,GetX+38,GetY+8,0,7.0,mm+tame,0,8,196,14);
                CreateWayShot02(5,24,GetX+31,GetY+8,0,7.0,mm+tame,0,8,196,14);
                CreateWayShot02(5,24,GetX-38,GetY+8,0,7.0,mm-tame,0,8,196,14);
                CreateWayShot02(5,24,GetX-31,GetY+8,0,7.0,mm-tame,0,8,196,14);
                CreateWayShot02(5,24,GetX+38,GetY+8,0,7.0,mm+tame,0,8,100,14);
                CreateWayShot02(5,24,GetX+31,GetY+8,0,7.0,mm+tame,0,8,100,14);
                CreateWayShot02(5,24,GetX-38,GetY+8,0,7.0,mm-tame,0,8,100,14);
                CreateWayShot02(5,24,GetX-31,GetY+8,0,7.0,mm-tame,0,8,100,14);
            }

            if (count4>1525&&count4<1632&&count4%8==0) {
                PlaySE(GetCurrentScriptDirectory~"\se\Shot04.wav");
                PlaySE(GetCurrentScriptDirectory~"\se\Beam.wav");
                CreateWayShot02(1,14,GetX+38,GetY+8,0,5.5,mm+tame,0,8,196,14);
                CreateWayShot02(1,14,GetX+31,GetY+8,0,5.5,mm+tame,0,8,196,14);
                CreateWayShot02(1,14,GetX-38,GetY+8,0,5.5,mm-tame,0,8,196,14);
                CreateWayShot02(1,14,GetX-31,GetY+8,0,5.5,mm-tame,0,8,196,14);
                CreateWayShot02(1,14,GetX+38,GetY+8,0,5.5,mm+tame,0,8,100,14);
                CreateWayShot02(1,14,GetX+31,GetY+8,0,5.5,mm+tame,0,8,100,14);
                CreateWayShot02(1,14,GetX-38,GetY+8,0,5.5,mm-tame,0,8,100,14);
                CreateWayShot02(1,14,GetX-31,GetY+8,0,5.5,mm-tame,0,8,100,14);
            }

            if (count4>=1600&&count4<1650&&count4%12==0) {
                PlaySE(GetCurrentScriptDirectory~"\se\Shot04.wav");
                PlaySE(GetCurrentScriptDirectory~"\se\Beam.wav");
                CreateWayShot02(2,14,GetX+38,GetY+8,0,3.8,mm+tame,0,8,196,14);
                CreateWayShot02(2,14,GetX+31,GetY+8,0,3.8,mm+tame,0,8,196,14);
                CreateWayShot02(2,14,GetX-38,GetY+8,0,3.8,mm-tame,0,8,196,14);
                CreateWayShot02(2,14,GetX-31,GetY+8,0,3.8,mm-tame,0,8,196,14);
                CreateWayShot02(2,14,GetX+38,GetY+8,0,3.8,mm+tame,0,8,100,14);
                CreateWayShot02(2,14,GetX+31,GetY+8,0,3.8,mm+tame,0,8,100,14);
                CreateWayShot02(2,14,GetX-38,GetY+8,0,3.8,mm-tame,0,8,100,14);
                CreateWayShot02(2,14,GetX-31,GetY+8,0,3.8,mm-tame,0,8,100,14);
            }

            if (count4>1460&&count4<1820&&count4%15==5) {
                PlaySE(GetCurrentScriptDirectory~"\se\Shot02.wav");
                CreateWayShot02(12,30,GetX,GetY,110,4.2,mm+22,0,8,72,14);
                CreateWayShot02(12,30,GetX,GetY,110,4.2,mm-22,0,8,72,14);
            }

            if (count4>1760&&count4<1960&&count4%12==2) {
                PlaySE(GetCurrentScriptDirectory~"\se\Shot02.wav");
                CreateWayShot02(12,30,GetX,GetY,110,5.2,mm+22-count*0.5,0,8,72,14);
                CreateWayShot02(12,30,GetX,GetY,110,5.2,mm-22-count*0.5,0,8,72,14);
            }

            if (count4>=1250&&count4<1650&&count4%75==0) {
                SetSpeed(0);
                SetMovePositionRandom01(rand(20,70),rand(2,44),0.2,GetCenterX()-54,68,GetCenterX()+54,128);
            }

            if (count4>=1600&&count4<=1720&&count%30==0) {
                PlaySE(GetCurrentScriptDirectory~"\se\mizu08.wav");
                CreateEnemyFromFile(GetCurrentScriptDirectory~"Enemy14.txt",GetX(),GetY(),rand(5,7.8),90-33+rand(-5,25),0);
            }

            if (count4>=1600&&count4<=1720&&count%30==15) {
                PlaySE(GetCurrentScriptDirectory~"\se\mizu08.wav");
                CreateEnemyFromFile(GetCurrentScriptDirectory~"Enemy14.txt",GetX(),GetY(),rand(5,7.8),90+33+rand(-25,5),0);
            }

            if (count4>=1650&&count4<1725&&count4%75==0) {
                SetSpeed(0);
                SetMovePositionRandom01(0,0,0.4,GetCenterX(),118,GetCenterX(),118);
            }

            if (count4>=2000&&count4<2050&&om>0) {
                om-=2;
            }

            if (count4>=1760&&count4<1800&&count4%20==0)
            {
                mm=0;
                mm+=GetAngleToPlayer();
                tame=0;
                tame+=rand(-11,11);
            }

            if (count4>=1825&&count4<=1875&&N16>0) {
                N16--;
                mX=GetCenterX;
                mY=160;
            }

            if (count4>=1825&&count4<=2400&&N17<255) {
                N17+=1.2;
                if (N17>255) {
                    N17=255;
                }
            }

            if (count4>=1825&&count4<2325) {
                Xloop+=0.00015;
                Yloop+=0.0001;
            }

            if (count4>=2325&&count4<2525) {
                Xloop+=0.0002;
            }

            if (count4>=2100&&count4<2800&&count4%6==0) {
                PlaySE(GetCurrentScriptDirectory~"\se\Shot02.wav");
                CreateWayShot02(6,60,GetX,GetY,95,3.6,count/3,0,8,72,6);
            }

            if (count4>=2180&&count4<2800&&count4%10==0&&count4%110>=20) {
                PlaySE(GetCurrentScriptDirectory~"\se\Shot04.wav");
                ascent( let t in 1..7 ) {
                    CreateWayShot02(6,60,OldX[t*30],OldY[t*30],45-t*4,3.4,GetAngleToPlayer()+16*sin(count/3),0,8,196,6);
                    CreateWayShot02(6,60,OldX[t*30],OldY[t*30],45-t*4,3.4,GetAngleToPlayer()+16*sin(count/3),0,8,196,2);
                }
            }

            if (count4>=2180&&count4<2800&&count4%10==0&&count4%110<20) {
                PlaySE(GetCurrentScriptDirectory~"\se\Shot04.wav");
                ascent( let t in 1..7 ) {
                    CreateWayShot02(1,60,OldX[t*30],OldY[t*30],45-t*4,3.4,GetAngleToPlayer(),0,8,196,6);
                    CreateWayShot02(1,60,OldX[t*30],OldY[t*30],45-t*4,3.4,GetAngleToPlayer(),0,8,196,2);
                }
            }

            if (count4>=2845&&count4<2940&&count4%6==0) {
                PlaySE(GetCurrentScriptDirectory~"\se\Beam.wav");
                ascent( let t in 1..7 ) {
                    CreateWayShot02(6,60,OldX[t*30],OldY[t*30],35-t*4,3.6,-count*0.6,0,8,100,6);
                    CreateWayShot02(6,60,OldX[t*30],OldY[t*30],35-t*4,3.6,-count*0.6,0,8,100,3);
                }
            }

            if (count4>=2950&&count4<3180&&count4%11==0) {
                PlaySE(GetCurrentScriptDirectory~"\se\Beam.wav");
                ascent( let t in 1..7 ) {
                    CreateWayShot02(6,60,OldX[t*30],OldY[t*30],41-t*4,5.6,0,0,8,100,6);
                    CreateWayShot02(6,60,OldX[t*30],OldY[t*30],41-t*4,5.6,0,0,8,100,2);
                }
            }

            if (count4>=3180&&count4<3280&&count4%6==0) {
                PlaySE(GetCurrentScriptDirectory~"\se\Shot04.wav");
                PlaySE(GetCurrentScriptDirectory~"\se\Beam.wav");
                ascent( let t in 1..7 ) {
                    CreateWayShot02(3,120,OldX[t*30],OldY[t*30],41-t*4,6.6-t*0.2,0+(count-3180)*2-t*2,0,8,196,6);
                    CreateWayShot02(3,120,OldX[t*30],OldY[t*30],41-t*4,6.6-t*0.2,0+(count-3180)*2-t*2,0,8,196,2);
                    CreateWayShot02(3,120,OldX[t*30],OldY[t*30],41-t*4,6.6-t*0.2,0+(count-3180)*2-t*2,0,8,100,6);
                    CreateWayShot02(3,120,OldX[t*30],OldY[t*30],41-t*4,6.6-t*0.2,0+(count-3180)*2-t*2,0,8,100,2);
                }
            }

            if (count4>=3280&&count4<3380&&count4%6==0) {
                PlaySE(GetCurrentScriptDirectory~"\se\Shot04.wav");
                PlaySE(GetCurrentScriptDirectory~"\se\Beam.wav");
                ascent( let t in 0..1 ) {
                    CreateWayShot02(3,120,OldX[t*30],OldY[t*30],41-t*4,7.6-t*0.2,0+(count-3180)*2-t*2,0,8,196,6);
                    CreateWayShot02(3,120,OldX[t*30],OldY[t*30],41-t*4,7.6-t*0.2,0+(count-3180)*2-t*2,0,8,196,2);
                    CreateWayShot02(3,120,OldX[t*30],OldY[t*30],41-t*4,7.6-t*0.2,0+(count-3180)*2-t*2,0,8,100,6);
                    CreateWayShot02(3,120,OldX[t*30],OldY[t*30],41-t*4,7.6-t*0.2,0+(count-3180)*2-t*2,0,8,100,2);
                }
            }

            if (count4>=3110&&count4<3215) {
                N18+=1;
                Yloop+=0.0002;
            }

            if (count4>=2060&&count4<2160) {
                N19+=1;
            }

            if (count4>=2460&&count4<2600) {
                N19-=1;
            }

            if (count4>=3500&&count4<3540) {
                N19+=1;
            }

            if (count4>=1825&&count4<3200) {
                SetX((mX+(190-N19)*sin(count4*Xloop))*(N17/255)+(GetCenterX())*((255-N17)/255));
                SetY((mY+N18/1.2+(55+N18)*cos(count4*Yloop))*(N17/255)+(118)*((255-N17)/255));
            }

            if (count4>=3200&&count4<4315) {
                SetX((mX+(195-N19)*sin(count4*Xloop))*(N17/255)+(mX+4*sin(count4*Xloop))*((255-N17)/255));
                SetY((mY+N18/1.2+(55+N18)*cos(count4*Yloop))*(N17/255)+(118)*((255-N17)/255));
            }

            if (count4>=3200&&count4<=3500&&N17>0) {
                N17-=0.2;
                if (N17>10) {
                    N17-=0.5;
                }if (N17>30) {
                    N17-=0.8;
                }if (N17<0) {
                    N17=0;
                }
            }

            if (count4>=3300&&count4<3350&&om<100) {
                om+=2;
            }

            if (count%15==0&&count4>3380&&count4<3450) {
                PlaySE(GetCurrentScriptDirectory~"\se\mizu08.wav");
                CreateEnemyFromFile(GetCurrentScriptDirectory~"Enemy14.txt",GetX(),GetY(),5,90+(count-3350),1);
                CreateEnemyFromFile(GetCurrentScriptDirectory~"Enemy14.txt",GetX(),GetY(),5,90-(count-3350),1);
            }

            if (count2<=4350&&count4>=3700) {
                count4=320;
                N17=0;
                N18=0;
                tame2=90;
                Xloop=0.5;
                Yloop=0.3;
            }

            if (count2>4430&&count4>=1725) {
                count4=320;
                N17=0;
                N18=0;
                tame2=90;
                Xloop=0.5;
                Yloop=0.3;
            }

            if (GetLife()<9000) {
                pat=1;
                count4=0;
            }

            if (GetLife()>=9000&&N17>150) {
                ascent( let t in 1..7 ) {
                    SetCollisionA(OldX[t*30],OldY[t*30],38-t*4);
                    SetCollisionB(OldX[t*30],OldY[t*30],35-t*4);
                }
            }

            if (count2>250) {
                SetCollisionA(GetX(),GetY(),120);
                SetCollisionB(GetX(),GetY(),105);
            }


        }




        if (pat==1)//第２
        {
            if (count4==0) {
                mm=0;
                mm+=GetAngleToPlayer();
                tame=0;
                tame+=rand(5,15);
                SetInvincibility(180);
                SetSpeed(0);
                SetMovePositionRandom01(45,0,0.8,GetX(),GetY-20,GetX(),GetY-20);
                DeleteEnemyShotToItemInCircle(CHILD,GetX(),GetY(),500);
                PlaySE(GetCurrentScriptDirectory~"\se\Baaaaaaaan.wav");
                CreateEnemyFromFile(GetCurrentScriptDirectory~"Servant10.txt",GetX,GetY,0,0,4);
            }

            if (count4<300) {
                if (N19>0) {
                    N19-=1;
                }if (N19<0) {
                    N19+=1;
                }
                if (N17>0) {
                    N17-=1;
                }if (N17<0) {
                    N17=0;
                }
                if (N16>0) {
                    N16-=1;
                }if (N16<0) {
                    N16=0;
                }
            }

            if (count4>=300&&count4<380) {
                N20+=0.5;
            }

            if (count4>=50&&count4<150&&om<100) {
                om+=1;
            }

            if (count4==80) {
                SetMovePositionRandom01(45,0,1,GetCenterX(),256,GetCenterX(),256);
            }

            if (count4>=320&&count4<1200&&count4%160==0) {
                SetSpeed(0);
                SetMovePositionRandom01(rand(20,70),rand(2,44),0.2,GetCenterX()-54,68,GetCenterX()+54,148);
            }

            if (count4>160&&count4<300&&N15>20) {
                N15-=0.6;
            }
            if (count4>160&&count4<360&&N15>0) {
                N15-=0.2;
                if (count3<255) {
                    count3++;
                    AddLife(20000);
                }
            }

            if (count4>250&&count4<820&&count%15==5) {
                PlaySE(GetCurrentScriptDirectory~"\se\Shot04.wav");
                CreateEnemyFromFile(GetCurrentScriptDirectory~"Missile2.txt",GetX()+85,GetY()-55,-7,GetAngleToPlayer()+43*sin(count2*1.4),0.7);
                CreateEnemyFromFile(GetCurrentScriptDirectory~"Missile2.txt",GetX()-85,GetY()-55,-7,GetAngleToPlayer()+43*sin(count2*1.4),0.7);
            }

            if (count4>900&&count4<1120&&count%10==5) {
                PlaySE(GetCurrentScriptDirectory~"\se\Shot04.wav");
                CreateEnemyFromFile(GetCurrentScriptDirectory~"Missile2.txt",GetX()+99*cos(mm+90),GetY()+99*sin(mm+90),-5+1*sin(count2*3),mm,0.7);
                CreateEnemyFromFile(GetCurrentScriptDirectory~"Missile2.txt",GetX()+39*cos(mm+90),GetY()+39*sin(mm+90),-5+1*sin(count2*3),mm,0.7);
                CreateEnemyFromFile(GetCurrentScriptDirectory~"Missile2.txt",GetX()-39*cos(mm+90),GetY()-39*sin(mm+90),-5+1*sin(count2*3),mm,0.7);
                CreateEnemyFromFile(GetCurrentScriptDirectory~"Missile2.txt",GetX()-99*cos(mm+90),GetY()-99*sin(mm+90),-5+1*sin(count2*3),mm,0.7);
            }

            if (count4>=600&&count4<850&&count4%45==4)
            {
                mm=0;
                mm+=GetAngleToPlayer();
                tame=0;
                tame+=rand(2,13);
            }

            if (count4==900&&count4<1100&&count4%100==0)
            {
                mm=0;
                mm+=GetAngleToPlayer();
                tame=0;
                tame+=rand(2,13);
            }

            if (count4>520&&count4<810&&count4%15==5) {
                CreateWayShot02(10,36,GetX,GetY,80,3.2,mm+tame,0,8,72,12);
                CreateWayShot02(10,36,GetX,GetY,80,3.2,mm-tame,0,8,72,12);
            }

            if (count4>860&&count4<1290&&count4%12==5) {
                PlaySE(GetCurrentScriptDirectory~"\se\Shot02.wav");
                CreateWayShot02(12,30,GetX,GetY,80,4.5,mm+tame,0,8,73,12);
                CreateWayShot02(12,30,GetX,GetY,80,4.5,mm-tame,0,8,73,12);
            }

            if (count4>1160&&count4<1360&&N15<50) {
                N15+=0.5;
            }
            if (count4>=1000&&count4<1080) {
                N20-=0.5;
            }

            if (count4>=1170&&count4<=1220&&N16<100) {
                N16++;
            }

            if (count4==1525||count4==1975||count4==1650||count4==2100||count4==1675||count4==2125)
            {
                mm=0;
                mm+=GetAngleToPlayer();
                tame=0;
                tame+=rand(2,15);
            }

            //if(count4>1250&&count4<1550&&count4%5==0){
            //PlaySE(GetCurrentScriptDirectory~"\se\Shot06.wav");
            //CreateWayShot02(7,14,GetX+40,GetY+8,0,4.3+count4%25*0.01,mm+tame,0,8,196,4);
            //CreateWayShot02(7,14,GetX-40,GetY+8,0,4.3+count4%25*0.01,mm-tame,0,8,196,4);
            //CreateWayShot02(7,14,GetX+40,GetY+8,0,4.3+count4%25*0.01,mm+tame,0,8,100,4);
            //CreateWayShot02(7,14,GetX-40,GetY+8,0,4.3+count4%25*0.01,mm-tame,0,8,100,4);}

            if (count4>1320&&count4<1500&&count%8==2) {
                PlaySE(GetCurrentScriptDirectory~"\se\Shot04.wav");
                CreateEnemyFromFile(GetCurrentScriptDirectory~"Missile2.txt",GetX()+85,GetY()-55,0,count*6,0.7);
            }

            if (count4>1320&&count4<1500&&count%5==2) {
                PlaySE(GetCurrentScriptDirectory~"\se\Shot04.wav");
                CreateEnemyFromFile(GetCurrentScriptDirectory~"Missile2.txt",GetX()-85,GetY()-55,1,-count*4,0.7);
            }

            if (count4>1525&&count4<1575&&count4%11==0) {
                PlaySE(GetCurrentScriptDirectory~"\se\Shot04.wav");
                PlaySE(GetCurrentScriptDirectory~"\se\Beam.wav");
                CreateWayShot02(7,25,GetX+40,GetY+8,0,6.3+count4%25*0.01,mm,0,8,196,4);
                CreateWayShot02(7,25,GetX-40,GetY+8,0,6.3+count4%25*0.01,mm,0,8,196,4);
                CreateWayShot02(7,25,GetX+40,GetY+8,0,6.3+count4%25*0.01,mm,0,8,100,4);
                CreateWayShot02(7,25,GetX-40,GetY+8,0,6.3+count4%25*0.01,mm,0,8,100,4);
                CreateWayShot02(7,25,GetX+43,GetY+8,0,6.3+count4%25*0.01,mm,0,8,196,4);
                CreateWayShot02(7,25,GetX-43,GetY+8,0,6.3+count4%25*0.01,mm,0,8,196,4);
                CreateWayShot02(7,25,GetX+43,GetY+8,0,6.3+count4%25*0.01,mm,0,8,100,4);
                CreateWayShot02(7,25,GetX-43,GetY+8,0,6.3+count4%25*0.01,mm,0,8,100,4);
            }

            if (count4>1575&&count4<1650&&count4%3==0) {
                PlaySE(GetCurrentScriptDirectory~"\se\Shot04.wav");
                PlaySE(GetCurrentScriptDirectory~"\se\Beam.wav");
                CreateWayShot02(7,25,GetX+40,GetY+8,0,10.3+count4%25*0.01,mm,0,8,196,4);
                CreateWayShot02(7,25,GetX-40,GetY+8,0,10.3+count4%25*0.01,mm,0,8,196,4);
                CreateWayShot02(7,25,GetX+40,GetY+8,0,10.3+count4%25*0.01,mm,0,8,100,4);
                CreateWayShot02(7,25,GetX-40,GetY+8,0,10.3+count4%25*0.01,mm,0,8,100,4);
                CreateWayShot02(7,25,GetX+43,GetY+8,0,10.3+count4%25*0.01,mm,0,8,196,4);
                CreateWayShot02(7,25,GetX-43,GetY+8,0,10.3+count4%25*0.01,mm,0,8,196,4);
                CreateWayShot02(7,25,GetX+43,GetY+8,0,10.3+count4%25*0.01,mm,0,8,100,4);
                CreateWayShot02(7,25,GetX-43,GetY+8,0,10.3+count4%25*0.01,mm,0,8,100,4);
            }

            if (count4>=1550&&count4<2250&&count4%75==25) {
                SetSpeed(0);
                SetMovePositionRandom01(rand(20,70),rand(2,44),0.2,GetCenterX()-54,48,GetCenterX()+54,108);
            }

            if (count4>=1575&&count4<1625&&count4%4==0) {
                PlaySE(GetCurrentScriptDirectory~"\se\Shot04.wav");
                CreateWayShot02(6,9,GetX+40,GetY+8,0,5.2+count4%25*0.12,mm+tame,0,8,196,14);
                CreateWayShot02(6,9,GetX-40,GetY+8,0,5.2+count4%25*0.12,mm-tame,0,8,196,14);
                CreateWayShot02(6,9,GetX+40,GetY+8,0,5.2+count4%25*0.12,mm+tame,0,8,100,14);
                CreateWayShot02(6,9,GetX-40,GetY+8,0,5.2+count4%25*0.12,mm-tame,0,8,100,14);
                CreateWayShot02(6,9,GetX+40,GetY+8,0,5.2+count4%25*0.12,mm+tame-55,0,8,196,14);
                CreateWayShot02(6,9,GetX-40,GetY+8,0,5.2+count4%25*0.12,mm-tame+55,0,8,196,14);
                CreateWayShot02(6,9,GetX+40,GetY+8,0,5.2+count4%25*0.12,mm+tame-55,0,8,100,14);
                CreateWayShot02(6,9,GetX-40,GetY+8,0,5.2+count4%25*0.12,mm-tame+55,0,8,100,14);
            }

            if (count4>=1650&&count4<1700&&count4%4==0) {
                PlaySE(GetCurrentScriptDirectory~"\se\Shot04.wav");
                CreateWayShot02(6,9,GetX+40,GetY+8,0,5.2+count4%25*0.12,mm+tame,0,8,196,14);
                CreateWayShot02(6,9,GetX-40,GetY+8,0,5.2+count4%25*0.12,mm-tame,0,8,196,14);
                CreateWayShot02(6,9,GetX+40,GetY+8,0,5.2+count4%25*0.12,mm+tame,0,8,100,14);
                CreateWayShot02(6,9,GetX-40,GetY+8,0,5.2+count4%25*0.12,mm-tame,0,8,100,14);
                CreateWayShot02(6,9,GetX+40,GetY+8,0,5.2+count4%25*0.12,mm+tame-55,0,8,196,14);
                CreateWayShot02(6,9,GetX-40,GetY+8,0,5.2+count4%25*0.12,mm-tame+55,0,8,196,14);
                CreateWayShot02(6,9,GetX+40,GetY+8,0,5.2+count4%25*0.12,mm+tame-55,0,8,100,14);
                CreateWayShot02(6,9,GetX-40,GetY+8,0,5.2+count4%25*0.12,mm-tame+55,0,8,100,14);
            }

            if (count4>1730&&count4<1950&&count%5==2) {
                PlaySE(GetCurrentScriptDirectory~"\se\Shot04.wav");
                CreateEnemyFromFile(GetCurrentScriptDirectory~"Missile2.txt",GetX()-85,GetY()-55,0,count*4,0.7);
            }

            if (count4>1730&&count4<1950&&count%3==2) {
                PlaySE(GetCurrentScriptDirectory~"\se\Shot04.wav");
                CreateEnemyFromFile(GetCurrentScriptDirectory~"Missile2.txt",GetX()+85,GetY()-55,1,-count*6,0.7);
            }

            if (count4>1975&&count4<2025&&count4%11==0) {
                PlaySE(GetCurrentScriptDirectory~"\se\Shot04.wav");
                PlaySE(GetCurrentScriptDirectory~"\se\Beam.wav");
                CreateWayShot02(7,25,GetX+40,GetY+8,0,6.3+count4%25*0.01,mm,0,8,196,4);
                CreateWayShot02(7,25,GetX-40,GetY+8,0,6.3+count4%25*0.01,mm,0,8,196,4);
                CreateWayShot02(7,25,GetX+40,GetY+8,0,6.3+count4%25*0.01,mm,0,8,100,4);
                CreateWayShot02(7,25,GetX-40,GetY+8,0,6.3+count4%25*0.01,mm,0,8,100,4);
                CreateWayShot02(7,25,GetX+43,GetY+8,0,6.3+count4%25*0.01,mm,0,8,196,4);
                CreateWayShot02(7,25,GetX-43,GetY+8,0,6.3+count4%25*0.01,mm,0,8,196,4);
                CreateWayShot02(7,25,GetX+43,GetY+8,0,6.3+count4%25*0.01,mm,0,8,100,4);
                CreateWayShot02(7,25,GetX-43,GetY+8,0,6.3+count4%25*0.01,mm,0,8,100,4);
            }

            if (count4>2025&&count4<2100&&count4%3==0) {
                PlaySE(GetCurrentScriptDirectory~"\se\Shot04.wav");
                PlaySE(GetCurrentScriptDirectory~"\se\Beam.wav");
                CreateWayShot02(7,25,GetX+40,GetY+8,0,10.3+count4%25*0.01,mm,0,8,196,4);
                CreateWayShot02(7,25,GetX-40,GetY+8,0,10.3+count4%25*0.01,mm,0,8,196,4);
                CreateWayShot02(7,25,GetX+40,GetY+8,0,10.3+count4%25*0.01,mm,0,8,100,4);
                CreateWayShot02(7,25,GetX-40,GetY+8,0,10.3+count4%25*0.01,mm,0,8,100,4);
                CreateWayShot02(7,25,GetX+43,GetY+8,0,10.3+count4%25*0.01,mm,0,8,196,4);
                CreateWayShot02(7,25,GetX-43,GetY+8,0,10.3+count4%25*0.01,mm,0,8,196,4);
                CreateWayShot02(7,25,GetX+43,GetY+8,0,10.3+count4%25*0.01,mm,0,8,100,4);
                CreateWayShot02(7,25,GetX-43,GetY+8,0,10.3+count4%25*0.01,mm,0,8,100,4);
            }

            if (count4>=2025&&count4<2075&&count4%4==0) {
                PlaySE(GetCurrentScriptDirectory~"\se\Shot04.wav");
                CreateWayShot02(6,9,GetX+40,GetY+8,0,5.2+count4%25*0.12,mm+tame,0,8,196,14);
                CreateWayShot02(6,9,GetX-40,GetY+8,0,5.2+count4%25*0.12,mm-tame,0,8,196,14);
                CreateWayShot02(6,9,GetX+40,GetY+8,0,5.2+count4%25*0.12,mm+tame,0,8,100,14);
                CreateWayShot02(6,9,GetX-40,GetY+8,0,5.2+count4%25*0.12,mm-tame,0,8,100,14);
                CreateWayShot02(6,9,GetX+40,GetY+8,0,5.2+count4%25*0.12,mm+tame-55,0,8,196,14);
                CreateWayShot02(6,9,GetX-40,GetY+8,0,5.2+count4%25*0.12,mm-tame+55,0,8,196,14);
                CreateWayShot02(6,9,GetX+40,GetY+8,0,5.2+count4%25*0.12,mm+tame-55,0,8,100,14);
                CreateWayShot02(6,9,GetX-40,GetY+8,0,5.2+count4%25*0.12,mm-tame+55,0,8,100,14);
            }

            if (count4>=2100&&count4<2150&&count4%4==0) {
                PlaySE(GetCurrentScriptDirectory~"\se\Shot04.wav");
                CreateWayShot02(6,9,GetX+40,GetY+8,0,5.2+count4%25*0.12,mm+tame,0,8,196,14);
                CreateWayShot02(6,9,GetX-40,GetY+8,0,5.2+count4%25*0.12,mm-tame,0,8,196,14);
                CreateWayShot02(6,9,GetX+40,GetY+8,0,5.2+count4%25*0.12,mm+tame,0,8,100,14);
                CreateWayShot02(6,9,GetX-40,GetY+8,0,5.2+count4%25*0.12,mm-tame,0,8,100,14);
                CreateWayShot02(6,9,GetX+40,GetY+8,0,5.2+count4%25*0.12,mm+tame-55,0,8,196,14);
                CreateWayShot02(6,9,GetX-40,GetY+8,0,5.2+count4%25*0.12,mm-tame+55,0,8,196,14);
                CreateWayShot02(6,9,GetX+40,GetY+8,0,5.2+count4%25*0.12,mm+tame-55,0,8,100,14);
                CreateWayShot02(6,9,GetX-40,GetY+8,0,5.2+count4%25*0.12,mm-tame+55,0,8,100,14);
            }

            if (count4>=2220&&count4<2700&&count4%160==0) {
                SetSpeed(0);
                SetMovePositionRandom01(rand(20,70),rand(2,44),0.2,GetCenterX()-54,38,GetCenterX()+54,118);
            }

            if (count4>=2225&&count4<2725&&count4%25==0)
            {
                mm=0;
                mm+=GetAngleToPlayer();
                tame=0;
                tame+=rand(-22,22);
            }

            if (count4>2210&&count4<2750&&count%18==5) {
                PlaySE(GetCurrentScriptDirectory~"\se\Shot04.wav");
                CreateEnemyFromFile(GetCurrentScriptDirectory~"Missile2.txt",GetX()-85,GetY()-55,1,GetAngleToPlayer()-12+rand(-22,22),0.7);
            }

            if (count4>2210&&count4<2750&&count%18==14) {
                PlaySE(GetCurrentScriptDirectory~"\se\Shot04.wav");
                CreateEnemyFromFile(GetCurrentScriptDirectory~"Missile2.txt",GetX()+85,GetY()-55,1,GetAngleToPlayer()+12+rand(-22,22),0.7);
            }

            if (count4>2250&&count4<2420&&count4%10==5) {
                PlaySE(GetCurrentScriptDirectory~"\se\Shot02.wav");
                CreateWayShot02(2,32,GetX+40,GetY+8,0,3.2,mm+tame,0,8,72,4);
                CreateWayShot02(2,32,GetX-40,GetY+8,0,3.2,mm-tame,0,8,72,4);
            }

            if (count4>2420&&count4<2900&&count4%15==5) {
                PlaySE(GetCurrentScriptDirectory~"\se\Shot02.wav");
                CreateWayShot02(2,32,GetX+40,GetY+8,0,3.2,mm+tame,0,8,72,4);
                CreateWayShot02(2,32,GetX-40,GetY+8,0,3.2,mm-tame,0,8,72,4);
            }

            if (count4>2760&&count4<2960&&N15>0) {
                N15-=0.5;
            }
            if (count4>=2770&&count4<=2870&&N16>0) {
                N16--;
            }
            if (count4>=2800&&count4<2980) {
                N20-=0.5;
            }

            if (count4>2850&&count4<3620&&count%18==5) {
                PlaySE(GetCurrentScriptDirectory~"\se\Shot04.wav");
                CreateEnemyFromFile(GetCurrentScriptDirectory~"Missile.txt",GetX()+95,GetY()-55,-5,88-15*sin(count2*3),0.6);
                CreateEnemyFromFile(GetCurrentScriptDirectory~"Missile.txt",GetX()-95,GetY()-55,-5,92-15*sin(count2*3),0.6);
                CreateEnemyFromFile(GetCurrentScriptDirectory~"Missile2.txt",GetX()+175,GetY()-55,-5,90-15*sin(count2*3),0.7);
                CreateEnemyFromFile(GetCurrentScriptDirectory~"Missile2.txt",GetX()-175,GetY()-55,-5,90-15*sin(count2*3),0.7);
            }

            if (count4==2660) {
                SetSpeed(0);
                SetMovePositionRandom01(25,25,0.2,GetCenterX(),328,GetCenterX(),328);
            }

            if (count4>2900&&count4<3560&&count%22==5) {
                PlaySE(GetCurrentScriptDirectory~"\se\Shot06.wav");
                CreateEnemyFromFile(GetCurrentScriptDirectory~"Missile2.txt",GetX()+rand(-100,100),GetY()-55,-5,90-15*sin(count2*3),0.7);
            }

            if (count4>=3660) {
                count4=290;
                N20=0;
                mm=0;
                mm+=GetAngleToPlayer();
                tame=0;
                tame+=rand(5,15);
            }

            SetCollisionA(GetX(),GetY(),120);
            SetCollisionB(GetX(),GetY(),105);

            if (GetLife()<9000&&count4>=290) {
                pat=3;
                count4=0;
            }

        }






        if (pat==3)//第３
        {
            if (count4==0) {
                Explosion01(GetX,GetY,6,0.3,80);
                SetInvincibility(140);
                AddLife(44000);
                SetSpeed(0);
                SetMovePositionRandom01(45,0,0.8,GetX(),GetY-20,GetX(),GetY-20);
                DeleteEnemyShotToItemInCircle(CHILD,GetX(),GetY(),500);
                PlaySE(GetCurrentScriptDirectory~"\se\Baaaaaaaan.wav");
                CreateEnemyFromFile(GetCurrentScriptDirectory~"Servant10.txt",GetX,GetY,0,0,4);
            }

            if (count4==90) {
                Explosion01(GetX,GetY,6,0.3,80);
                PlaySE(GetCurrentScriptDirectory~"\se\Baaaaaaaan.wav");
                CreateEnemyFromFile(GetCurrentScriptDirectory~"Servant10.txt",GetX,GetY,0,0,4);
            }

            if (count4>=120&&count4<190) {
                AddLife(15000);
            }

            if (count4>=30&&count4<=260&&count%6==0&&rand(0,4)>=2) {
                PlaySE(GetCurrentScriptDirectory~"\se\Baaaan.wav");
                CreateEnemyFromFile(GetCurrentScriptDirectory~"Servant10.txt",GetX+rand(-43,43),GetY+rand(-43,43),0,0,2);
            }

            if (count4<100) {
                if (N19>0) {
                    N19-=2;
                }if (N19<0) {
                    N19+=1;
                }
                if (N17>0) {
                    N17-=2;
                }if (N17<0) {
                    N17=0;
                }
                if (N16>0) {
                    N16-=2;
                }if (N16<0) {
                    N16=0;
                }
                if (N20>0) {
                    N20-=2;
                }if (N20<0) {
                    N20=0;
                }
            }

            if (count4>=200&&count4<280) {
                N20+=0.5;
            }

            if (count4==80) {
                SetMovePositionRandom01(45,0,1,GetCenterX(),156,GetCenterX(),156);
            }

            if (count4>=220&&count4<1200&&count4%160==0) {
                SetSpeed(0);
                SetMovePositionRandom01(rand(20,70),rand(2,44),0.2,GetCenterX()-54,68,GetCenterX()+54,148);
            }

            if (count4>350&&count4<960&&count%15==5) {
                PlaySE(GetCurrentScriptDirectory~"\se\Shot04.wav");
                ascent( let t in 0..5 ) {
                    CreateEnemyFromFile(GetCurrentScriptDirectory~"Missile2.txt",GetX(),GetY(),-7,count*2.3+t*28,0.7);
                }
            }

            if (count4>=400&&count4<940&&count4%45==4)
            {
                mm=0;
                mm+=GetAngleToPlayer();
                tame=0;
                tame+=rand(2,13);
            }

            if (count4>530&&count4<810&&count4%15==5) {
                CreateWayShot02(10,36,GetX,GetY,80,3.5,mm+tame,0,8,72,0);
                CreateWayShot02(10,36,GetX,GetY,80,3.5,mm-tame,0,8,72,0);
            }

            if (count4>229&&count4<1050&&count4%4==2) {
                PlaySE(GetCurrentScriptDirectory~"\se\Shot06.wav");
                CreateWayShot02(10,36,GetX,GetY,110,4.5,count4-count4%15,0,8,169,0);
            }

            if (count4>860&&count4<930&&count4%12==5) {
                PlaySE(GetCurrentScriptDirectory~"\se\Shot02.wav");
                CreateWayShot02(12,30,GetX,GetY,80,5.2,mm+tame,0,8,73,0);
                CreateWayShot02(12,30,GetX,GetY,80,5.2,mm-tame,0,8,73,0);
            }

            if (count4>960&&count4<1160&&N15<50) {
                N15+=0.5;
            }

            //if (count4>=970&&count4<=1020&&N16<100) {
            //    N16++;
            //}

            if (count4==1060)
            {
                mm=0;
                mm+=GetAngleToPlayer();
                tame=0;
            }

            if (count4==1160)
            {
                if (GetX<GetPlayerX) {
                    tame2=0.6;
                }else {
                    tame2=-0.6;
                }
            }

            if (count4>=1160&&count4<=1210)
            {
                tame+=tame2;
            }

            if (count4>=1260&&count4<=1310)
            {
                tame-=tame2;
            }

            if (count4>=1400&&count4<=1740)
            {
                tame-=tame2*5;
            }

            if (count4>1060&&count4<1720&&count4%3==0) {
                PlaySE(GetCurrentScriptDirectory~"\se\Shot04.wav");
                PlaySE(GetCurrentScriptDirectory~"\se\Beam.wav");
                CreateWayShot02(7,17,GetX+40,GetY+8,0,7.3+count4%25*0.02,mm+tame,0,8,196,4);
                CreateWayShot02(7,17,GetX-40,GetY+8,0,7.3+count4%25*0.02,mm+tame,0,8,196,4);
                CreateWayShot02(7,17,GetX+40,GetY+8,0,7.3+count4%25*0.02,mm+tame,0,8,100,4);
                CreateWayShot02(7,17,GetX-40,GetY+8,0,7.3+count4%25*0.02,mm+tame,0,8,100,4);
                CreateWayShot02(7,17,GetX+43,GetY+8,0,7.3+count4%25*0.02,mm+tame,0,8,196,4);
                CreateWayShot02(7,17,GetX-43,GetY+8,0,7.3+count4%25*0.02,mm+tame,0,8,196,4);
                CreateWayShot02(7,17,GetX+43,GetY+8,0,7.3+count4%25*0.02,mm+tame,0,8,100,4);
                CreateWayShot02(7,17,GetX-43,GetY+8,0,7.3+count4%25*0.02,mm+tame,0,8,100,4);
            }

            if (count4>1400&&count4<1720&&count4%4==0) {
                ascent( let t in 0..4 ) {
                    CreateWayShot02(1,25,GetX+41,GetY+8,0,5.5+t*0.8,180+mm+tame+15,0,8,169,0);
                    CreateWayShot02(1,25,GetX-41,GetY+8,0,5.5+t*0.8,180+mm+tame-15,0,8,169,0);
                }
            }

            if (count4>1590&&count4<1690&&N15>0) {
                N15-=1;
            }
            if (count4>=1570&&count4<=1670&&N16>0) {
                N16--;
            }
            if (count4>=1500&&count4<1580) {
                N20-=0.5;
            }

            if (count4>970&&count4<1380&&count4%20==10) {
                CreateWayShot02(2,32,GetX+40,GetY+8,0,3.8,mm+tame+rand(-12,12),0,8,72,4);
                CreateWayShot02(2,32,GetX-40,GetY+8,0,3.8,mm-tame+rand(-12,12),0,8,72,4);
            }

            if (count4>=1250&&count4<1650&&count4%75==25) {
                SetSpeed(0);
                SetMovePositionRandom01(rand(20,70),rand(2,44),0.2,GetCenterX()-54,28,GetCenterX()+54,68);
            }

            if (count4==2660) {
                SetSpeed(0);
                SetMovePositionRandom01(25,25,0.2,GetCenterX(),328,GetCenterX(),328);
            }

            if (count4>=1640&&count4<1720) {
                N20+=0.5;
            }

            if (count%15==0&&count4>1720&&count4<1770) {
                PlaySE(GetCurrentScriptDirectory~"\se\mizu08.wav");
                CreateEnemyFromFile(GetCurrentScriptDirectory~"Enemy14.txt",GetX(),GetY(),6,90+(count4-1700),1);
                CreateEnemyFromFile(GetCurrentScriptDirectory~"Enemy14.txt",GetX(),GetY(),6,90-(count4-1700),1);
            }

            if (count4>=1800) {
                count4=390;
            }

            SetCollisionA(GetX(),GetY(),120);
            SetCollisionB(GetX(),GetY(),105);

            if (GetLife()<9000&&count4>=390) {
                pat=4;
                count4=0;
            }

        }



        if (pat==4)//最終
        {
            if (count4==0) {
                Explosion01(GetX,GetY,6,0.3,80);
                SetInvincibility(280);
                AddLife(150);
                SetSpeed(0);
                SetMovePositionRandom01(45,0,0.8,GetX(),GetY-20,GetX(),GetY-20);
                DeleteEnemyShotToItemInCircle(CHILD,GetX(),GetY(),500);
                PlaySE(GetCurrentScriptDirectory~"\se\Baaaaaaaan.wav");
                CreateEnemyFromFile(GetCurrentScriptDirectory~"Servant10.txt",GetX,GetY,0,0,4);
            }

            if (count4==220||count4==280||count4==940) {
                Explosion01(GetX,GetY,6,0.3,80);
                PlaySE(GetCurrentScriptDirectory~"\se\Baaaaaaaan.wav");
                CreateEnemyFromFile(GetCurrentScriptDirectory~"Servant10.txt",GetX,GetY,0,0,4);
            }

            if (count4>=250&&count4<320) {
                AddLife(9000);
            }

            if (count4>=220) {
                if (N17<300) {
                    N17+=15;
                    c=c+0.3;
                    if (N17>300) {
                        N17=300;
                    }
                }
            }

            if (count4>=30&&count4<=120&&count%6==0&&rand(0,4)>=2) {
                PlaySE(GetCurrentScriptDirectory~"\se\Baaaaaaaan.wav");
                CreateEnemyFromFile(GetCurrentScriptDirectory~"Servant102.txt",GetX+rand(-43,43),GetY+rand(-43,43),0,0,2);
            }

            if (count4>=30&&count%16==0) {
                PlaySE(GetCurrentScriptDirectory~"\se\Baaaan.wav");
                CreateEnemyFromFile(GetCurrentScriptDirectory~"Servant10.txt",GetX+rand(-83,83),GetY+rand(-83,83),0,0,2);
            }

            if (count4>70&&ys>0) {
                PlaySE(GetCurrentScriptDirectory~"\se\Shot06.wav");
            }
            if (count4<100) {
                if (N19>0) {
                    N19-=2;
                }if (N19<0) {
                    N19++;
                }
                if (N17>0) {
                    N17-=2;
                }if (N17<0) {
                    N17=0;
                }
                if (N16>0) {
                    N16-=2;
                }if (N16<0) {
                    N16=0;
                }
                if (N20>0) {
                    N20-=2;
                }if (N20<0) {
                    N20=0;
                }
            }

            if (count4>=40&&count4<160&&count4%25==0) {
                SetSpeed(0);
                SetMovePositionRandom01(rand(20,70),rand(2,44),0.8,GetCenterX()-54,128,GetCenterX()+54,158);
            }

            if (count4==230) {
                SetSpeed(0);
                SetMovePositionRandom01(rand(20,70),rand(2,44),0.8,GetCenterX(),148,GetCenterX(),148);
            }


            if (count4>=280) {
                SetX(GetX+xs);
                SetY(GetY+ys);
                ys+=0.15;
            }

            if (h2<=0&&ys>0) {
                ys+=0.5;
                if (GetY>395) {
                    Explosion01(GetX,GetY+78,10,0.4,80);
                    CreateEnemyFromFile(GetCurrentScriptDirectory~"Missile2.txt",GetX(),GetY()+78,4,270+rand(-22,22),2.5);
                    CreateEnemyFromFile(GetCurrentScriptDirectory~"Missile2.txt",GetX(),GetY()+78,3,270+rand(-22,22),2.5);
                    CreateEnemyFromFile(GetCurrentScriptDirectory~"Missile2.txt",GetX(),GetY()+78,3,270+rand(-22,22),2.5);
                    CreateEnemyFromFile(GetCurrentScriptDirectory~"Missile2.txt",GetX(),GetY()+78,2,270+35+rand(-2,2),2.5);
                    CreateEnemyFromFile(GetCurrentScriptDirectory~"Missile2.txt",GetX(),GetY()+78,2,270-35+rand(-2,2),2.5);
                    CreateEnemyFromFile(GetCurrentScriptDirectory~"Missile2.txt",GetX(),GetY()+78,2,270+75+rand(-2,2),2.5);
                    CreateEnemyFromFile(GetCurrentScriptDirectory~"Missile2.txt",GetX(),GetY()+78,2,270-75+rand(-2,2),2.5);
                    PlaySE(GetCurrentScriptDirectory~"\se\Baaaaaaaan.wav");
                    PlaySE(GetCurrentScriptDirectory~"\se\Baaaaaaaan2.wav");
                    ys=-10-1*sin(count4);
                    Explosion01(GetX,GetY+88,8,0.16,80);
                    if (GetPlayerX>GetX) {
                        xs=0.7;
                    }else {
                        xs=-0.7;
                    }
                }
            }


            if (count4%850<350) {
                h2=0;
            }else {
                h2=1;
            }

            if (h2>0) {

                if (GetY<160) {
                    ys=1.4*sin(count*4);
                }

                if (GetY<80) {
                    ys=5;
                }

                if (GetY>180) {
                    ys=-3;
                }

                if (GetX<GetCenterX-150||GetX>GetCenterX+150) {
                    xs=xs*-0.9;
                }

                xs+=(GetPlayerX-GetX)*0.001;

                if (count4%850>350&&count4%850<450) {

                    if (count4%6==0) {
                        PlaySE(GetCurrentScriptDirectory~"\se\Shot04.wav");
                        PlaySE(GetCurrentScriptDirectory~"\se\Beam.wav");

                        CreateWayShot02(18,20,GetX,GetY,5,6,GetAngleToPlayer()+26*sin(count*3),0,8,100,16);
                        CreateWayShot02(18,20,GetX,GetY,5,6,GetAngleToPlayer()+26*sin(count*3),0,8,196,16);

                    }


                }

                if (count4%850>450&&count4%850<750) {

                    if (count4%12==0) {
                        PlaySE(GetCurrentScriptDirectory~"\se\Shot04.wav");
                        PlaySE(GetCurrentScriptDirectory~"\se\Beam.wav");

                        ascent( let t in 0..6 ) {
                            CreateWayShot02(2,2,GetX+120*cos(20*sin(count)+t*60),GetY+120*sin(20*sin(count)+t*60),5,4+sin(count*2),GetAngleToPlayer()+20*sin(count),0,8,100,16);
                            CreateWayShot02(2,2,GetX+120*cos(20*sin(count)+t*60),GetY+120*sin(20*sin(count)+t*60),5,4+sin(count*2),GetAngleToPlayer()+20*sin(count),0,8,196,16);
                        }
                    }


                }


            }
            else if (count4%850<400&&count4%850>40) {
                if (count4%10==0&&count4>900&&ys>-5&&ys<0) {
                    CreateEnemyFromFile(GetCurrentScriptDirectory~"Missile.txt",GetX()+40,GetY(),-3,80,0.6);
                    CreateEnemyFromFile(GetCurrentScriptDirectory~"Missile.txt",GetX()-40,GetY(),-3,100,0.6);
                }

                if (count4%10==0&&count4>900&&ys>-5&&ys<0) {
                    CreateEnemyFromFile(GetCurrentScriptDirectory~"Missile.txt",GetX()+45,GetY()-11,-3,50,0.6);
                    CreateEnemyFromFile(GetCurrentScriptDirectory~"Missile.txt",GetX()-45,GetY()-11,-3,130,0.6);
                }
            }

            SetCollisionA(GetX(),GetY(),120);
            SetCollisionB(GetX(),GetY(),100);

            if (GetLife()<9000&&count4>290) {
                pat=5;
                count4=0;
            }

        }



        if (count2==16660&&pat!=5) {
            count2=19000;
            pat=5;
            count4=0;
            SetLife(4000);
        }


        if (pat==5)//おわり
        {
            SetCommonData("x",GetX);
            SetCommonData("y",GetY);
            SetInvincibility(20);

            if (count4<100) {
                if (N16>0) {
                    N16-=3;
                }if (N16<0) {
                    N16=0;
                }
                if (N20>0) {
                    N20-=3;
                }if (N20<0) {
                    N20=0;
                }
            }

            if (count4==0) {
                MagicCircle(false);
                SetEnemyMarker(false);
                Explosion01(GetX,GetY,6,0.3,80);
                SetInvincibility(280);
                AddLife(6600);
                SetSpeed(0);
                SetMovePositionRandom01(45,0,8,GetX(),GetY-60,GetX(),GetY-60);
                DeleteEnemyShotToItemInCircle(CHILD,GetX(),GetY(),500);
                PlaySE(GetCurrentScriptDirectory~"\se\Baaaaaaaan.wav");
                CreateEnemyFromFile(GetCurrentScriptDirectory~"Servant10.txt",GetX,GetY,0,0,4);
            }

            if (count4==220) {
                SetCommonData("Go",0);
                Explosion01(GetX,GetY,6,0.3,80);
                PlaySE(GetCurrentScriptDirectory~"\se\Baaaaaaaan.wav");
                CreateEnemyFromFile(GetCurrentScriptDirectory~"Servant10.txt",GetX,GetY,0,0,4);
            }

            if (count4>=110&&count4<=146&&count%6==0) {
                PlaySE(GetCurrentScriptDirectory~"\se\Baaaan2.wav");
                CreateEnemyFromFile(GetCurrentScriptDirectory~"Servant102.txt",GetX+60*cos(count*10),GetY+60*sin(count*10),0,0,4);
                Explosion01(GetX+120*cos(count*10),GetY+120*sin(count*10),6,0.2,80);
                SetMovePositionRandom01(45,45,25,GetX()-rand(0,43),GetY-rand(0,43),GetX()+rand(0,43),GetY+rand(0,43));
            }

            if (count4>330&&h<255) {
                h++;
            }

            if (count4>=0&&count4<110) {
                N17-=2.6;
                c=c-0.05
              }

            if (count4>=30&&count4<=160&&count%6==0&&rand(0,4)>=2) {
                PlaySE(GetCurrentScriptDirectory~"\se\Baaaaaaaan.wav");
                CreateEnemyFromFile(GetCurrentScriptDirectory~"Servant102.txt",GetX+rand(-43,43),GetY+rand(-43,43),0,0,2);
            }

            if (count4>=30&&count%16==0&&sca>0.2) {
                PlaySE(GetCurrentScriptDirectory~"\se\Baaaan.wav");
                CreateEnemyFromFile(GetCurrentScriptDirectory~"Servant10.txt",GetX+rand(-83,83),GetY+rand(-83,83),0,0,2);
            }

            if (count4>=50&&count4<120&&count4%25==0) {
                SetSpeed(0);
                SetMovePositionRandom01(rand(20,70),rand(2,44),12.8,GetCenterX()-54,128,GetCenterX()+54,158);
            }

            if (count4==230) {
                SetSpeed(0);
                SetMovePositionRandom01(rand(20,70),rand(2,44),12.8,GetCenterX(),138,GetCenterX(),138);
            }

            if (count4>=160&&count%12==0&&rand(0,4)>=2&&sca>0.2) {
                PlaySE(GetCurrentScriptDirectory~"\se\Baaaan.wav");
                CreateEnemyFromFile(GetCurrentScriptDirectory~"Servant10.txt",GetX+rand(-33,33),GetY+rand(-33,33),0,0,2);
            }

            if (count4==470) {
                PlaySE(GetCurrentScriptDirectory~"\se\bom13.wav");
                SetCommonData("flash2",255);
                if (count2<=18000) {
                    AddScore(100000000);
                }
                if (scoreZ>0) {
                    SetCommonData("Go",2);
                    VanishEnemy;
                }
                CreateEnemyFromFile(GetCurrentScriptDirectory~"Servant10.txt",GetX,GetY,0,0,4);
            }

            if (count4==480) {
                CreateEnemyFromFile(GetCurrentScriptDirectory~"Servant10.txt",GetX+65,GetY-32,0,0,3);
            }

            if (count4==490) {
                CreateEnemyFromFile(GetCurrentScriptDirectory~"Servant10.txt",GetX-65,GetY+12,0,0,3);
            }

            if (count4==500) {
                CreateEnemyFromFile(GetCurrentScriptDirectory~"Servant10.txt",GetX,GetY-11,0,0,3);
            }

            if (count4>=650) {
                SetCommonData("Go",3);
                VanishEnemy;
            }

            if (count4==130) {
                PlaySE(GetCurrentScriptDirectory~"\se\Baaaaaaaan.wav");
                la++;
                SetSpeed(0);
                CreateEnemyFromFile(GetCurrentScriptDirectory~"Servant10.txt",GetX,GetY,0,0,4);
            }

            if (count4>=250&&sca>0) {
                sca-=0.5;
            }


        }

        count++;
        count4++;
        count2++;
        move--;
        ye2--;
        if (ye>0) {
            ye-=4;
        }
        if (ye<0) {
            ye=0;
        }
        if (ye2>0&&ye<244) {
            ye+=6;
        }
        if (GetLife<10000&&falp>0) {
            if (pat==3||pat==5) {
                falp-=5;
            }
        }

        c2+=c;

        yield;
    }

    @Finalize()
    {
        MagicCircle(false);
        SetEnemyMarker(false);
    }

    @DrawLoop()
    {

        SetTexture(GetCurrentScriptDirectory~"\img\ho.png");
        SetRenderState(ALPHA);
        SetAlpha(255);
        SetColor(255,128,128);
        SetGraphicScale((sca/100)*(om/100),(sca/100)*(om/100));
        if (ten==1) {
            SetColor(196,64,64);
        }
        SetGraphicRect(512,0,1028,512);
        SetGraphicAngle(0,0,-90);
        DrawGraphic(GetX()+3,GetY()+1);

        if (N17>0&&pat<2) {
            SetRenderState(ADD);
            SetTexture(GetCurrentScriptDirectory~"\img\NuclearSpark2.png");
            SetGraphicScale(0.7-count%3*0.05-N17*0.0005,0.7-count%3*0.05-N17*0.0005);
            SetGraphicRect(0,0,256,256);
            SetAlpha(255);
            SetColor(N17,0,0);
            DrawGraphic(GetX(),GetY());
            SetColor(N17,N17/4,N17/4);
            ascent( let t in 1..7 ) {
                SetGraphicScale(0.5-count%3*0.05-t*0.035,0.5-count%3*0.05-t*0.035);
                DrawGraphic(OldX[t*30],OldY[t*30]);
            }
            ascent( let t in 1..7 ) {
                SetColor(N17,N17/3,N17/3);
                SetGraphicScale(0.16,0.16);
                DrawGraphic(OldX[t*30-15],OldY[t*30-15]);
            }
        }

        if (la==0) {
            SetTexture(GetCurrentScriptDirectory~"\img\laserbit.png");
            SetGraphicScale(0.4-+N17*0.001,0.5+0.1*sin(count)+N17*0.004);
            SetAlpha(255);
            SetRenderState(ADD);
            if (count%4<=1) {
                SetGraphicRect(0,0,128,256);
            }else {
                SetGraphicRect(128,0,256,256);
            }
            if (count<=220) {
                SetColor(0,0,0);
            }
            else if (count<320) {
                SetColor((count-220)*2.5,(count-220)*2.5,(count-220)*2.5);
            }
            else {
                SetColor(255,255,255);
            }
            ascent( let t in 0..8 ) {
                SetGraphicAngle(0,0,t*30+count*3-90);
                DrawGraphic(GetX()+110*cos(count*3+45*t),GetY()+110*sin(count*3+45*t));
                SetGraphicAngle(0,0,t*30+count*2-90);
                DrawGraphic(GetX()+110*cos(count*2+45*t),GetY()+110*sin(count*2+45*t));
            }
            if (count<=120) {
                SetColor(0,0,0);
            }
            else if (count<220) {
                SetColor((count-120)*2.5,(count-120)*2.5,(count-120)*2.5);
            }
            else {
                SetColor(255,255,255);
            }
            if (N16>0) {
                SetGraphicScale(N16*0.02,N16*0.05);
                SetGraphicAngle(0,0,-135+60*(count3/255));
                DrawGraphic(GetX()+40,GetY()+8);
                SetGraphicAngle(0,0,135-60*(count3/255));
                DrawGraphic(GetX()-40,GetY()+8);
            }
            if (N20>0) {
                if (count%4<=1) {
                    SetGraphicRect(256,0,384,256);
                }else {
                    SetGraphicRect(384,0,512,256);
                }
                SetGraphicScale(N20*0.04,N20*0.05);
                SetGraphicAngle(0,0,-125);
                DrawGraphic(GetX()+100,GetY()-18);
                SetGraphicAngle(0,0,-55);
                DrawGraphic(GetX()+82,GetY()+44);
                SetGraphicAngle(0,0,125);
                DrawGraphic(GetX()-100,GetY()-18);
                SetGraphicAngle(0,0,55);
                DrawGraphic(GetX()-82,GetY()+44);
            }
        }

        SetTexture(GetCurrentScriptDirectory~"\img\moon3-2.png");
        SetRenderState(ADD);
        if (count<250) {
            SetAlpha(count);
            SetColor(count,0,0);
            SetGraphicScale(0.5+count*0.002,0.5+count*0.002);
        }
        else {
            SetAlpha(255);
            SetColor(255,ye,ye);
            SetGraphicScale(sca/100,sca/100);
        }
        if (ten==1) {
            SetColor(190,0,0);
        }
        SetGraphicRect(0,0,512,512);
        SetGraphicAngle(0,0,-c2);
        DrawGraphic(GetX(),GetY());
        SetRenderState(ALPHA);
        if (count<100) {
            SetAlpha(count*0.5);
        }
        else {
            SetAlpha(55);
        }
        DrawGraphic(GetX(),GetY());

        if (scoreZ!=0) {
            SetTexture(GetCurrentScriptDirectory~"\img\kyozou.png");
            SetRenderState(ADD);
            SetAlpha(255*(count%2==0));
            SetColor(h,h,h);
            SetGraphicScale(1.2,1);
            SetGraphicRect(0,0,256,256);
            SetGraphicAngle(0,0,0);
            DrawGraphic(GetX(),GetY()+5);
        }

    }


}

