
script_enemy_main
{
    let count=0;//GtFNgǗ

    let endB=15;

    task bak(let X,let Y,let scaleX,let scaleY,let Speed,let Angle,let GrAngle,let Alpha,let Layer,let Type,let Delay)
    {

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

        if (Type==0||Type==4||Type==5) {
            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*count8);
            Obj_SetY(obj, Y+sin(Angle)*Speed*count8);
            ObjEffect_SetScale(obj,scaleX,scaleY);
            if (Type==5) {
                ObjEffect_SetScale(obj,scaleX+count8*0.05,scaleY+count8*0.05);
            }
            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+(Type==5)*640,160*N02);
            ObjEffect_SetVertexUV(obj,1,160*N01+(Type==5)*640,160*(N02+1));
            ObjEffect_SetVertexUV(obj,2,160*(N01+1)+(Type==5)*640,160*N02);
            ObjEffect_SetVertexUV(obj,3,160*(N01+1)+(Type==5)*640,160*(N02+1));

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

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

            endB=2;

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

            yield;
        }

    }

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


    @MainLoop
    {
        if (GetArgument!=1&&GetArgument!=6) {
            if (count==1) {
                bak(GetX,GetY,1.7,1.7,0,0,rand(0,360),155,3,2,5);
            }
            if (count%6==4&&count<=12) {
                bak(GetX+rand(-40,40),GetY+rand(-40,40),1.7,1.7,0,0,rand(0,360),155,3,2,5);
            }
            //if(count>10&&count%8==6&&count<=20){bak(GetX+rand(-80,80),GetY+rand(-70,70),1.2,1.2,0,0,rand(0,360),155,3,rand_int(0,2),5);}
            endB--;
            if (endB<=0) {
                VanishEnemy;
            }
            if (count>=35) {
                VanishEnemy;
            }
        }

        if (GetArgument==1) {
            if (count%6==4&&count<=365&&count>65) {
                bak(GetX+rand(-30,30),GetY+rand(-30,30),0.5,0.5,7,26+rand(-10,10)+(count>200)*(count-200)*0.4,rand(0,360),255-(count>200)*(count-200)*1.5,3,5,5);
            }
            if (count>105) {
                endB--;
            }SetX(GetPlayerX+rand(-20,20));
            SetY(GetPlayerY+rand(-20,20));
            //if(endB<=0&&count>105){VanishEnemy;}
            if (count>=430) {
                VanishEnemy;
            }
        }

        if (GetArgument==5) {
            if (count<60&&count%3==0) {
                bak(GetX+rand(-20,20),GetY+rand(-20,20),1.5,1.5,3,rand(0,360),rand(0,360),255,3,2,5);
            }
            if (count>4) {
                SetSpeed(12);
                SetAngle(rand(0,360));
                endB-=0.2;
            }
            if (count>=166) {
                VanishEnemy;
            }
        }

        if (GetArgument==6) {
            if (count==4) {
                bak(GetX+rand(-20,20),GetY+rand(-20,20),0.5,0.5,5,90+rand(-10,10),rand(0,360),255,3,2,5);
            }
            if (count>4) {
                endB--;
            }
            if (endB<=0||count>=32) {
                VanishEnemy;
            }
        }

        count++;
        yield;


    }

    @DrawLoop
    {
        if (GetArgument==1) {
            SetTexture(GetCurrentScriptDirectory~"\img\moon3-2.png");
            SetAlpha(255);
            SetRenderState(ADD);
            SetColor(70-(count>200)*(count-200)*0.3,10,10);
            SetGraphicScale(0.32+count%3*0.06*(count<=300)+0.1*(count>300),0.32+count%3*0.06*(count<=300)+0.1*(count>300));
            SetGraphicAngle(0,0,0);
            SetGraphicRect(256,768,512,1024);
            //SetColor(200,10,10);
            if (count<=300) {
                DrawGraphic(GetPlayerX(),GetPlayerY());
            }
            if (count>300&&count<350) {
                DrawGraphic(GetPlayerX()+rand(-11,11),GetPlayerY()+rand(-11,11));
            }
            if (count>=350&&count%4==0) {
                DrawGraphic(GetPlayerX(),GetPlayerY());
            }
        }
        yield;
    }
}
