script_enemy_main
{
    let count=0;
    let count2=0;
    let MT=0;
    let type=0;
    let t=0;
    let N17=0;

function dead {
    SetDamageRate(0,0);

    if (N17==50) {
        PlaySE(GetCurrentScriptDirectory~"\se\bom27_b.wav");
        CreateEnemyFromFile(GetCurrentScriptDirectory~"Servant10.txt",GetX,GetY,0,0,1);
        SetCommonData("ii1",GetCommonDataDefault("ii1",0)+GetCommonDataDefault("ii2",0));
        SetCommonData("ii3",1);
        loop(3) {
            CreateItem(ITEM_SCORE,GetX()+rand(-30,30),GetY()+rand(10,30));
        }
    }

    if (N17<100) {
        N17+=50;
    }
    if (N17>=100) {
        VanishEnemy;
    }
}

@Initialize
{
    SetLife(5402);
    if (GetPlayerType()==REIMU_A) {
        SetLife(5415);
    }
    SetScore(15000);
    SetDamageRate(100,8);
}

@MainLoop
{

    if (count<=10&&GetX<GetCenterX) {
        MT=345;
        type=0;
    }
    if (count<=10&&GetX>=GetCenterX) {
        MT=195;
        type=1;
    }
    if (type==0) {
        SetAngle(MT+18*sin(count*2));
    }else {
        SetAngle(MT-18*sin(count*2));
    }
    if (GetPlayerLife<4) {
        SetDamageRate(165,3);
        if (count%26<=0&&count>80&&count<170&&GetY+82<GetPlayerY) {
            PlaySE(GetCurrentScriptDirectory~"\se\Shot00.wav");
            CreateShot02(GetX(),GetY(),0,90,0.03,2,196,24);
        }
    }
    if (GetPlayerLife>=5&&GetPlayerLife>=4) {
        if (count%(65-10*(GetCommonDataDefault("miss",0)==0))==6&&count>80&&count<220&&GetY+82<GetPlayerY) {
            PlaySE(GetCurrentScriptDirectory~"\se\Shot00.wav");
            ascent(let t in 0..4) {
                CreateShot01(GetX(),GetY(),3+(GetCommonDataDefault("miss",0)==0),GetAngleToPlayer(),196,12+t*(3-(GetCommonDataDefault("miss",0)==0)));
            }
        }
    }
    SetSpeed(1.7);
    if (count>320) {
        VanishEnemy;
    }if (count>0&&GetArgument==13) {
        VanishEnemy;
    }
    if (GetLife<5400) {
        dead;
    }
    else {
        SetCollisionA(GetX(),GetY(),20);
    }

    if (GetArgument==13) {
        if (count>3) {
            VanishEnemy;
        }
    }

    count++;
    count2++;


}

@Finalize
{
}

@DrawLoop
{


    SetTexture(GetCurrentScriptDirectory~"\img\NuclearRing.png");
    SetColor(125,125,125);
    SetGraphicAngle(0,0,count2*8);
    SetGraphicScale(0.24-0.03*sin(count2*4),0.24-0.03*sin(count2*4));
    if (count2<=10) {
        SetGraphicScale(count2*0.02,count2*0.02);
    }
    SetRenderState(ADD);
    SetGraphicRect(0,0,256,256);
    DrawGraphic(GetX(),GetY()+4);

    SetTexture(GetCurrentScriptDirectory~"\img\dot-kaze-ti.png");
    SetColor(255,255,255);
    SetGraphicAngle(0,0,0);
    SetGraphicScale(1.2-0.03*(count2%12),1.2-0.03*(count2%12));
    if (count2<=10) {
        SetGraphicScale(count2*0.1,count2*0.1);
    }
    SetRenderState(ADD);

    if (count2/2%4>=0) {
        SetGraphicRect(0,320,64,384);
    }
    if (count2/2%4>=1) {
        SetGraphicRect(64,320,128,384);
    }
    if (count2/2%4>=2) {
        SetGraphicRect(128,320,192,384);
    }
    if (count2/2%4>=3) {
        SetGraphicRect(192,320,256,384);
    }

    if (GetArgument==5||GetArgument==7) {
        if (count2/2%2>=0) {
            SetGraphicRect(0,384,64,448);
        }
        if (count2/2%2>=1) {
            SetGraphicRect(64,384,128,448);
        }
        if (count2/2%2>=2) {
            SetGraphicRect(128,384,192,448);
        }
        if (count2/2%2>=3) {
            SetGraphicRect(192,384,256,448);
        }
    }

    if (GetArgument==6) {
        if (count2/2%2>=0) {
            SetGraphicRect(0,448,64,512);
        }
        if (count2/2%2>=1) {
            SetGraphicRect(64,448,128,512);
        }
        if (count2/2%2>=2) {
            SetGraphicRect(128,448,192,512);
        }
        if (count2/2%2>=3) {
            SetGraphicRect(192,448,256,512);
        }
    }

    DrawGraphic(GetX(),GetY());

}
}