script_enemy_main
{
    let count=0;//裏・3
    let Z=0;
    let Ang=0;
    let N15=0;
    let N16=0;

    task nuc(let l,let s)
{
    let count=0;
    let obj = Obj_Create(OBJ_EFFECT);
    ObjEffect_SetTexture(obj, GetCurrentScriptDirectory~"\img\NuclearRing4.png");
    ObjEffect_SetRenderState(obj, ADD);
    ObjEffect_SetPrimitiveType(obj, PRIMITIVE_TRIANGLESTRIP);
    ObjEffect_CreateVertex(obj, 4);
    ObjEffect_SetLayer(obj,l);

    while (!Obj_BeDeleted(obj))
    {

        if (GetArgument<3) {
            Obj_SetX(obj, GetX());
            Obj_SetY(obj, GetY());
            Obj_SetAlpha(obj,255);
            ObjEffect_SetAngle(obj,0,0,-count*12);
        }

        if (N15<100) {
            N15+=5;
        }
        ObjEffect_SetScale(obj,(N15/100)*s-0.04*(count%3),(N15/100)*s+0.04*(count%3));

        if (N16==0) {
            if (GetArgument!=1) {
                SetCollisionA(GetX(),GetY(),N15*s*0.6);
            }
            SetCollisionB(GetX(),GetY(),N15*s*0.6);
        }

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

        ObjEffect_SetVertexUV(obj,0,0,0);
        ObjEffect_SetVertexUV(obj,1,0,512);
        ObjEffect_SetVertexUV(obj,2,512,0);
        ObjEffect_SetVertexUV(obj,3,512,512);

        ascent(let t in 0..4) {
            ObjEffect_SetVertexColor(obj,t,255,255*((100-N16)/100),255*((100-N16)/100),255*((100-N16)/100));
        }
        if (N16>0) {
            ascent(let t in 0..4) {
                ObjEffect_SetVertexColor(obj,t,255,255*((100-N16)/100),255*((100-N16)/100)/3,255*((100-N16)/100)/3);
            }
        }

        count++;
        yield;
    }

}

task fire(let l)
{
    let obj = Obj_Create(OBJ_EFFECT);
    let col = 0;
    ObjEffect_SetTexture(obj, GetCurrentScriptDirectory~"\img\laserbit.png");
    ObjEffect_SetPrimitiveType(obj, PRIMITIVE_TRIANGLESTRIP);
    ObjEffect_SetLayer(obj,l);
    ObjEffect_SetRenderState(obj, ADD);
    ObjEffect_CreateVertex(obj, 4);

    while (!Obj_BeDeleted(obj))
    {

        Obj_SetAlpha(obj,255);

        if (GetArgument<=0.5) {
            if (count>=40) {
                ObjEffect_SetLayer(obj,3);
            }
            Obj_SetX(obj, GetX()-12*cos(Ang)*Z);
            Obj_SetY(obj, GetY()-12*sin(Ang)*Z);
            ObjEffect_SetAngle(obj,0,0,Ang-270);
            ObjEffect_SetScale(obj,0.3*Z*(col/100),0.4*Z*(col/100));
            if (count>20&&count<50&&col<100) {
                col+=5;
            }
            if (count>90&&col>0) {
                col-=5;
            }
        }

        else if (GetArgument<=1) {
            if (count>=50) {
                ObjEffect_SetLayer(obj,3);
            }
            Obj_SetX(obj, GetX()-12*cos(Ang)*Z);
            Obj_SetY(obj, GetY()-12*sin(Ang)*Z);
            ObjEffect_SetAngle(obj,0,0,Ang-270);
            ObjEffect_SetScale(obj,0.3*Z*(col/100),0.4*Z*(col/100));
            if (count>20&&count<50&&col<100) {
                col+=5;
            }
            if (count>150&&col>0) {
                col-=5;
            }
        }

        if (GetArgument>=3) {
            Obj_SetX(obj, GetX()-6*cos(Ang)*Z);
            Obj_SetY(obj, GetY()-6*sin(Ang)*Z);
            ObjEffect_SetAngle(obj,0,0,Ang-270);
            ObjEffect_SetScale(obj,0.2*Z*(col/100),0.3*Z*(col/100));
            if (count>20&&count<50&&col<100) {
                col+=5;
            }
            if (count>90&&col>0) {
                col-=5;
            }
        }




        ObjEffect_SetVertexXY(obj,0,-64,-128);
        ObjEffect_SetVertexXY(obj,1,-64,128);
        ObjEffect_SetVertexXY(obj,2,64,-128);
        ObjEffect_SetVertexXY(obj,3,64,128);

        if (count%4<=1) {
            SetGraphicRect(0,0,128,256);
            ObjEffect_SetVertexUV(obj,0,0,0);
            ObjEffect_SetVertexUV(obj,1,0,256);
            ObjEffect_SetVertexUV(obj,2,128,0);
            ObjEffect_SetVertexUV(obj,3,128,256);
        }
        else {
            SetGraphicRect(128,0,256,256);
            ObjEffect_SetVertexUV(obj,0,128,0);
            ObjEffect_SetVertexUV(obj,1,128,256);
            ObjEffect_SetVertexUV(obj,2,256,0);
            ObjEffect_SetVertexUV(obj,3,256,256);
        }

        ascent(let t in 0..4) {
            if (N16>0) {
                ObjEffect_SetVertexColor(obj,t,255,col*((100-N16)/100),col*((100-N16)/100),col*((100-N16)/100));
            }
        }

        yield;
    }

}

task miss(let t)
{
    let obj = Obj_Create(OBJ_EFFECT);
    let col = 0;
    Obj_SetX(obj, GetX);
    Obj_SetY(obj, GetY);
    Obj_SetSpeed(obj, 0);
    ObjEffect_SetTexture(obj, GetCurrentScriptDirectory~"\img\dot-kaze-ti.png");
    ObjEffect_SetRenderState(obj, ALPHA);
    ObjEffect_SetPrimitiveType(obj, PRIMITIVE_TRIANGLESTRIP);
    ObjEffect_SetScale(obj,1,1);
    ObjEffect_SetAngle(obj,0,0,0);
    ObjEffect_CreateVertex(obj, 4);
    ObjEffect_SetLayer(obj,t);

    while (!Obj_BeDeleted(obj))
    {

        Obj_SetX(obj, GetX());
        Obj_SetY(obj, GetY());


        if (GetArgument<=1) {
            if (count>=50) {
                ObjEffect_SetLayer(obj,3);
            }
            Obj_SetAlpha(obj,255);
            ObjEffect_SetAngle(obj,0,0,Ang-90);
            if (GetArgument!=0.7) {
                ObjEffect_SetScale(obj,Z*0.8,Z*0.8);
            }
            else {
                ObjEffect_SetScale(obj,Z*1.0,Z*1.0);
            }

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

            ObjEffect_SetVertexUV(obj,0,416,336);
            ObjEffect_SetVertexUV(obj,1,416,400);
            ObjEffect_SetVertexUV(obj,2,448,336);
            ObjEffect_SetVertexUV(obj,3,448,400);
        }


        if (GetArgument>=3) {
            if (count>=20) {
                ObjEffect_SetLayer(obj,3);
            }
            Obj_SetAlpha(obj,255);
            ObjEffect_SetAngle(obj,0,0,Ang-90);
            ObjEffect_SetScale(obj,Z*0.8,Z*0.8);

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

            ObjEffect_SetVertexUV(obj,0,448,320);
            ObjEffect_SetVertexUV(obj,1,448,400);
            ObjEffect_SetVertexUV(obj,2,512,320);
            ObjEffect_SetVertexUV(obj,3,512,400);
        }


        if (count>0&&col<100) {
            col+=5;
        }

        ascent(let t in 0..4) {
            ObjEffect_SetVertexColor(obj,t,255*((100-N16)/100)*(col/100),255*((100-N16)/100),255*((100-N16)/100),255*((100-N16)/100));
            if (N16>0) {
                ObjEffect_SetVertexColor(obj,t,255*((100-N16)/100)*(col/100),255*((100-N16)/100),255*((100-N16)/100)/2,255*((100-N16)/100)/2);
            }
        }
        yield;
    }

}


@Initialize
{
    SetLife(500);
    SetDamageRate(1,50);
    SetScore(50);
}


@MainLoop
{
    if (GetArgument==0) {//Speed指定なし:Angle指定なし:ホーミングしない
        if (count<=0) {
            SetColor(0,0,0);
            SetLife(525);
            Z=0;
            Ang=GetAngle;
            fire(1);
            miss(1);
        }
        if (count>=40&&count<60) {
            SetSpeed(6);
            SetDamageRate(80,10);
        }
        if (GetLife<=500||GetY>460) {
            SetDamageRate(0,0);
            if (N16==10) {
                if (GetLife<=500) {
                    CreateEnemyFromFile(GetCurrentScriptDirectory~"Missile.txt",GetX(),GetY(),3,Ang,1);
                }
                else {
                    CreateEnemyFromFile(GetCurrentScriptDirectory~"Missile.txt",GetX(),GetY(),1,rand(0,360),1.6);
                }
                PlaySE(GetCurrentScriptDirectory~"\se\Baaaan.wav");
            }
            if (N16<100) {
                N16+=10;
            }
            if (N16>=100) {
                VanishEnemy;
            }
        }
        if (Z<1) {
            Z+=0.05;
        }
        if (GetLife>500&&count>=3&&Z>=1) {
            SetCollisionA(GetX(),GetY(),25);
            SetCollisionB(GetX()+15*cos(Ang),GetY()+15*sin(Ang),3);
        }
        if (count>200) {
            VanishEnemy;
        }
    }

    if (GetArgument>=0.5&&GetArgument<1) {//加速
        if (count<=0) {
            SetColor(0,0,0);
            SetLife(501);
            Z=0;
            Ang=GetAngle;
            fire(1);
            miss(1);
        }
        if (count>=20&&count<60) {
            SetSpeed(GetSpeed+0.4);
            SetDamageRate(80,10);
        }
        if (GetLife<=500||GetY>445) {
            SetDamageRate(0,0);
            if (N16==10) {
                if (GetLife<=500) {
                    if (GetArgument!=0.7) {
                        AddScore(100000);
                        PlaySE(GetCurrentScriptDirectory~"\se\Baaaan.wav");
                    }
                    else {
                        PlaySE(GetCurrentScriptDirectory~"\se\Baaaaaaaan.wav");
                    }
                    CreateEnemyFromFile(GetCurrentScriptDirectory~"Missile.txt",GetX(),GetY(),4-(GetArgument==0.6),Ang,1.5+(GetArgument==0.6)+1.1*(GetArgument==0.7));
                }
                else {
                    PlaySE(GetCurrentScriptDirectory~"\se\Baaaan.wav");
                    CreateEnemyFromFile(GetCurrentScriptDirectory~"Missile.txt",GetX(),GetY(),0.2,rand(180,360),1.5+(GetArgument==0.6));
                }
            }
            if (N16<100) {
                N16+=10;
            }
            if (N16>=100) {
                VanishEnemy;
            }
        }
        if (Z<1) {
            Z+=0.025;
        }
        if (GetArgument==0.7&&count==40) {
            AddLife(-100);
        }
        if (GetX<GetCenterX-400||GetX>GetCenterX+400) {
            VanishEnemy;
        }
        if (GetLife>500&&count>=18&&Z>=1) {
            SetCollisionA(GetX(),GetY(),25);
            SetCollisionB(GetX()+15*cos(Ang),GetY()+15*sin(Ang),5);
        }
        if (count>200) {
            VanishEnemy;
        }
    }

    if (GetArgument==1) {//爆発極小
        if (count<=0) {
            SetColor(0,0,0);
            SetLife(512);
            nuc(4,0.12);
            SetDamageRate(0,0);
        }
        if (count>20) {
            SetDamageRate(0,0);
            if (N16<100) {
                N16+=5;
            }
            if (N16>=100) {
                VanishEnemy;
            }
        }
        if (count>200||GetY>500||GetY<-120) {
            VanishEnemy;
        }
    }

    if (GetArgument==1.5||GetArgument==2.5) {//爆発小
        if (count<=0) {
            SetColor(0,0,0);
            SetLife(512);
            nuc(3+0.2*(GetArgument==2.5),0.26+0.02*(GetArgument==2.5)+0.08*(GetArgument==2.6));
            SetDamageRate(0,0);
        }
        if (count>(30+15*(GetArgument==2.5)+125*(GetArgument==2.6))) {
            SetDamageRate(0,0);
            if (N16<100) {
                N16+=5;
            }
            if (N16>=100) {
                VanishEnemy;
            }
        }
        if (GetArgument==2.5) {
            SetSpeed(GetSpeed-0.05);
        }
        if (GetArgument==2.6) {
            SetSpeed(GetSpeed+0.05);
        }
        if (count>200||GetY>500||GetY<-120||GetX>GetCenterX+250||GetX<GetCenterX-250) {
            VanishEnemy;
        }
    }

    if (GetArgument==3) {//Speed指定なし:Angle指定なし:ホーミングしない
        if (count<=0) {
            SetColor(0,0,0);
            SetLife(501);
            Z=0;
            Ang=GetAngle;
            fire(1);
            miss(1);
        }
        if (count>=20&&count<60) {
            SetSpeed(GetSpeed+0.4);
            SetDamageRate(80,10);
        }
        if (GetLife<=500||GetY>470) {
            SetDamageRate(0,0);
            if (N16==10) {
                if (GetLife<=500) {
                    CreateEnemyFromFile(GetCurrentScriptDirectory~"Missile.txt",GetX(),GetY(),3.8,GetAngle+rand(-20,20),1.5);
                }
                else {
                    CreateEnemyFromFile(GetCurrentScriptDirectory~"Missile.txt",GetX(),GetY(),0.5,rand(180,360),1.5);
                }
                PlaySE(GetCurrentScriptDirectory~"\se\Baaaan.wav");
            }
            if (N16<100) {
                N16+=10;
            }
            if (N16>=100) {
                VanishEnemy;
            }
        }
        if (Z<1) {
            Z+=0.025;
        }
        if (count>=10&&count<80) {
            SetAngle(GetAngle+3);
            Ang=GetAngle;
        }
        if (GetLife>500&&count>=3&&Z>=1) {
            SetCollisionA(GetX(),GetY(),25);
            SetCollisionB(GetX()+15*cos(Ang),GetY()+15*sin(Ang),6);
        }
        if (count>70||GetY>500) {
            VanishEnemy;
        }
    }

    if (GetArgument==3.5) {//Speed指定なし:Angle指定なし:ホーミングしない
        if (count<=0) {
            SetColor(0,0,0);
            SetLife(501);
            Z=0;
            Ang=GetAngle;
            fire(1);
            miss(1);
        }
        if (count>=20&&count<60) {
            SetSpeed(GetSpeed+0.4);
            SetDamageRate(80,10);
        }
        if (GetLife<=500||GetY>470) {
            SetDamageRate(0,0);
            if (N16==10) {
                if (GetLife<=500) {
                    CreateEnemyFromFile(GetCurrentScriptDirectory~"Missile.txt",GetX(),GetY(),3.8,GetAngle+rand(-20,20),1.5);
                }
                else {
                    CreateEnemyFromFile(GetCurrentScriptDirectory~"Missile.txt",GetX(),GetY(),0.5,rand(180,360),1.5);
                }
                PlaySE(GetCurrentScriptDirectory~"\se\Baaaan.wav");
            }
            if (N16<100) {
                N16+=10;
            }
            if (N16>=100) {
                VanishEnemy;
            }
        }
        if (Z<1) {
            Z+=0.025;
        }
        if (count>=10&&count<80) {
            SetAngle(GetAngle-3);
            Ang=GetAngle;
        }
        if (GetLife>500&&count>=3&&Z>=1) {
            SetCollisionA(GetX(),GetY(),25);
            SetCollisionB(GetX()+15*cos(Ang),GetY()+15*sin(Ang),6);
        }
        if (count>70||GetY>500) {
            VanishEnemy;
        }
    }


    if (GetArgument==2) {
        if (count>5) {
            VanishEnemy;
        }
    }

    yield;
    count++;
}

@Finalize
{
}

@DrawLoop
{
    yield;
}
}
