
script_enemy_main
{
    let count=0;//GtFNgǗ

    let endB=15;

    task bak2()
    {
        let obj = Obj_Create(OBJ_SHOT);
        let count8 = 0;
        Obj_SetX(obj,GetX);
        Obj_SetY(obj,GetY);
        ObjShot_ToItem(obj,false);
        Obj_SetSpeed(obj, rand(-12,12));
        if (rand(0,2)<0.3) {
            Obj_SetSpeed(obj, 16);
        }
        Obj_SetAngle(obj, rand(180,360));
        ObjShot_SetGraphic(obj, 194);

        while (!Obj_BeDeleted(obj))
        {
            if (count8%3<=0&&count8<=33) {
                bak(Obj_GetX(obj)+rand(-8,8),Obj_GetY(obj)+rand(-8,8),0.5,0.5,0,0,rand(180,360),rand(125,225),2,0,rand(1,4));
            }
            if (count8>33) {
                Obj_Delete(obj);
            }
            endB=2;
            count8++;
            yield;
        }
    }

    task bak3()
    {
        let obj = Obj_Create(OBJ_SHOT);
        let count8 = 0;
        Obj_SetX(obj,GetX);
        Obj_SetY(obj,GetY);
        ObjShot_ToItem(obj,false);
        Obj_SetSpeed(obj, rand(3,12));
        Obj_SetAngle(obj, rand(220,320));
        ObjShot_SetGraphic(obj, 194);

        while (!Obj_BeDeleted(obj))
        {
            if (count8%3<=0&&count8<=63) {
                bak(Obj_GetX(obj)+rand(-8,8),Obj_GetY(obj)+rand(-8,8),0.55,0.55,0,0,rand(180,360),rand(125,225),2,0,rand(1,4));
            }
            if (count8>63) {
                Obj_Delete(obj);
            }
            if (count8==33) {
                Obj_SetAngle(obj, rand(220,320));
            }
            endB=2;
            count8++;
            yield;
        }
    }

    task bak(let X,let Y,let scaleX,let scaleY,let Speed,let Angle,let GrAngle,let Alpha,let Layer,let Type,let Delay)
    {//^Cv@0F@1F唚@2F֔@3F@4F

        let obj = Obj_Create(OBJ_EFFECT);
        let flamecount = 0;
        let N01=0;//x
        let N02=0;//y

        if (Type==0||Type==4) {
            ObjEffect_SetTexture(obj, GetCurrentScriptDirectory~"\img\ba3.png");
        }
        else if (Type==1) {
            ObjEffect_SetTexture(obj, GetCurrentScriptDirectory~"\img\ba2.png");
        }
        else if (Type==2) {
            ObjEffect_SetTexture(obj, GetCurrentScriptDirectory~"\img\ba1.png");
        }
        else if (Type==3) {
            ObjEffect_SetTexture(obj, GetCurrentScriptDirectory~"\img\ba4.png");
        }

        ObjEffect_SetRenderState(obj, ADD);
        ObjEffect_SetPrimitiveType(obj, PRIMITIVE_TRIANGLESTRIP);
        ObjEffect_CreateVertex(obj, 4);
        ObjEffect_SetAngle(obj,0,0,GrAngle);

        while (!Obj_BeDeleted(obj))
        {
            Obj_SetX(obj, X+cos(Angle)*Speed);
            Obj_SetY(obj, Y+sin(Angle)*Speed);
            ObjEffect_SetScale(obj,scaleX,scaleY);
            ObjEffect_SetLayer(obj,Layer);

            if (N01>=4) {
                N01=0;
                N02++;
                if (N02>=4) {
                    Obj_Delete(obj);
                }
            }

            ObjEffect_SetVertexXY(obj,0,-32,-32);
            ObjEffect_SetVertexXY(obj,1,-32,32);
            ObjEffect_SetVertexXY(obj,2,32,-32);
            ObjEffect_SetVertexXY(obj,3,32,32);

            ObjEffect_SetVertexUV(obj,0,160*N01,160*N02+640*(GetArgument>=6&&GetArgument<=7));
            ObjEffect_SetVertexUV(obj,1,160*N01,160*(N02+1)+640*(GetArgument>=6&&GetArgument<=7));
            ObjEffect_SetVertexUV(obj,2,160*(N01+1),160*N02+640*(GetArgument>=6&&GetArgument<=7));
            ObjEffect_SetVertexUV(obj,3,160*(N01+1),160*(N02+1)+640*(GetArgument>=6&&GetArgument<=7));

            ascent(let t in 0..4) {
                ObjEffect_SetVertexColor(obj,t,Alpha,255,255,255);
            }

            if (flamecount>=Delay) {
                N01+=1;
                flamecount=0;
            }

            endB=2;

            flamecount++;
            if (Type==4) {
                ObjEffect_SetRenderState(obj, SUBTRACT);
            }

            yield;
        }

    }

    @Initialize
    {
        SetLife(1);
        endB=20;
    }


    @MainLoop
    {
        if (GetArgument<1) {
            if (count<=0) {
                SetSpeed(4);
                SetAngle(rand(0,360));
            }
            if (count==1&&GetArgument==0) {
                bak(GetX+rand(-2,2),GetY+rand(-2,2),1.4,1.4,0,0,rand(0,360),255,1,2,3);
            }
            if (count==1&&GetArgument==0.5) {
                bak(GetX+rand(-2,2),GetY+rand(-2,2),1.2,1.2,0,0,rand(0,360),255,1,2,3);
            }
            endB--;
            if (endB<=0) {
                VanishEnemy;
            }
        }

        if (GetArgument==1) {

            if (count==1) {
                bak(GetX,GetY,1.4,1.4,0,0,rand(0,360),255,3,3,3);
                if (rand(0,100)<=10) {
                    bak2();
                }
            }
            if (count==2) {
                if (rand(0,100)<=60) {
                    bak2();
                }
            }
            endB--;
            if (endB<=0) {
                VanishEnemy;
            }

        }

        if (GetArgument==1.5) {

            if (count==1) {
                bak(GetX+rand(-50,50),GetY+rand(-20,50),1.2,1.2,0,0,rand(0,360),255,2,4,3);
                if (rand(0,100)<=10) {
                    bak2();
                }
            }
            if (count==2) {
                if (rand(0,100)<=70) {
                    bak2();
                }
            }
            endB--;
            if (endB<=0) {
                VanishEnemy;
            }

        }

        if (GetArgument==2) {

            if (count==1) {
                bak(GetX,GetY,1.4,1.4,0,0,rand(0,360),255,3,2,3);
            }
            if (count%6==4&&count<=12) {
                bak(GetX+rand(-60,60),GetY+rand(-60,60),1.3,1.3,0,0,rand(0,360),255,3,2,3);
            }
            if (count%5==0&&count<=12) {
                if (rand(0,100)<=65) {
                    bak3();
                }
            }
            if (count>10&&count%8==6&&count<=20) {
                bak(GetX+rand(-40,40),GetY+rand(-40,40),1.2,1.2,0,0,rand(0,360),255,3,rand_int(0,2),3);
            }
            endB--;
            if (endB<=0) {
                VanishEnemy;
            }

        }

        if (GetArgument==3) {

            if (count==1) {
                bak(GetX,GetY,1.7,1.7,0,0,rand(0,360),255,3,2,3);
            }
            if (count%6==4&&count<=12) {
                bak(GetX+rand(-60,60),GetY+rand(-60,60),1.8,1.8,0,0,rand(0,360),255,3,2,3);
                if (rand(0,100)<=30) {
                    bak2();
                }
            }
            if (count>10&&count%8==6&&count<=30) {
                bak(GetX+rand(-80,80),GetY+rand(-70,70),1.2,1.2,0,0,rand(0,360),255,3,rand_int(0,2),3);
            }
            endB--;
            if (endB<=0) {
                VanishEnemy;
            }

        }

        if (GetArgument==4) {

            if (count==2) {
                bak(GetX+rand(-20,20),GetY+62+rand(-20,20),2.8,2.8,0,0,rand(0,360),255,3,2,3);
            }
            if (count==6) {
                bak(GetX-66+rand(-30,30),GetY+12+rand(-20,20),2.8,2.8,0,0,rand(0,360),255,3,2,3);
            }
            if (count==10) {
                bak(GetX+66+rand(-30,30),GetY-52+rand(-20,20),2.8,2.8,0,0,rand(0,360),255,3,2,3);
                if (rand(0,100)<=20) {
                    bak2();
                }
            }
            if (count==14) {
                bak(GetX+rand(-10,10),GetY-75+rand(-20,20),2.8,2.8,0,0,rand(0,360),255,3,2,3);
                if (rand(0,100)<=20) {
                    bak2();
                }
            }
            if (count%8<=0&&count<=50) {
                bak(GetX+rand(-130,130),GetY+rand(-90,90),1.6,1.6,rand(0,3),rand(0,360),rand(0,360),255,3,rand_int(0,2),3);
                if (rand(0,100)<=30) {
                    bak2();
                }
            }
            endB--;
            if (endB<=0) {
                VanishEnemy;
            }

        }

        if (GetArgument==5) {

            if (count==2) {
                bak(GetX+rand(-20,20),GetY+62+rand(-20,20),2.8,2.8,0,0,rand(0,360),255,3,2,3);
            }
            if (count==6) {
                bak(GetX-66+rand(-30,30),GetY+12+rand(-20,20),2.8,2.8,0,0,rand(0,360),255,3,2,3);
            }
            if (count==10) {
                bak(GetX+66+rand(-30,30),GetY-52+rand(-20,20),2.8,2.8,0,0,rand(0,360),255,3,2,3);
                if (rand(0,100)<=80) {
                    bak2();
                }
            }
            if (count==14) {
                bak(GetX+rand(-10,10),GetY-75+rand(-20,20),2.8,2.8,0,0,rand(0,360),255,3,2,3);
                if (rand(0,100)<=80) {
                    bak2();
                }
            }
            if (count%8<=0&&count<=50) {
                bak(GetX+rand(-130,130),GetY+rand(-90,90),1.6,1.6,rand(0,3),rand(0,360),rand(0,360),255,3,4,3);
                if (rand(0,100)<=80) {
                    bak2();
                }
            }
            endB--;
            if (endB<=0) {
                VanishEnemy;
            }

        }

        if (GetArgument==6) {

            if (count==1) {
                bak(GetX,GetY,1.7,1.7,0,0,rand(0,360),255,3,2,3);
            }
            if (count%6==4&&count<=12) {
                bak(GetX+rand(-60,60),GetY+rand(-60,60),1.8,1.8,0,0,rand(0,360),255,3,2,3);
                if (rand(0,100)<=30) {
                    bak2();
                }
            }
            if (count>10&&count%8==6&&count<=30) {
                bak(GetX+rand(-80,80),GetY+rand(-70,70),1.2,1.2,0,0,rand(0,360),255,3,rand_int(0,2),3);
            }
            endB--;
            if (endB<=0) {
                VanishEnemy;
            }

        }

        if (GetArgument==7) {

            if (count==2) {
                bak(GetX+rand(-20,20),GetY+62+rand(-20,20),2.8,2.8,0,0,rand(0,360),255,3,2,3);
            }
            if (count==6) {
                bak(GetX-66+rand(-30,30),GetY+12+rand(-20,20),2.8,2.8,0,0,rand(0,360),255,3,2,3);
            }
            if (count==10) {
                bak(GetX+66+rand(-30,30),GetY-52+rand(-20,20),2.8,2.8,0,0,rand(0,360),255,3,2,3);
                if (rand(0,100)<=20) {
                    bak2();
                }
            }
            if (count==14) {
                bak(GetX+rand(-10,10),GetY-75+rand(-20,20),2.8,2.8,0,0,rand(0,360),255,3,2,3);
                if (rand(0,100)<=20) {
                    bak2();
                }
            }
            if (count%8<=0&&count<=50) {
                bak(GetX+rand(-130,130),GetY+rand(-90,90),1.6,1.6,rand(0,3),rand(0,360),rand(0,360),255,3,rand_int(0,2),3);
                if (rand(0,100)<=30) {
                    bak2();
                }
            }
            endB--;
            if (endB<=0) {
                VanishEnemy;
            }

        }

        count++;
        yield;


    }

    @DrawLoop
    {
        yield;
    }
}
