
script_enemy_main
{
    let count=0;
    let count2=0;
    let count3=0;
    let get;
    let try;
    let ten=0;
    let life=0;

    let move=0;

    let pass=GetCurrentScriptDirectory~"Spell.dat";

    let cx=GetCenterX();
    let img=GetCurrentScriptDirectory~"img\dot_remilia.png";
    let bg=GetCurrentScriptDirectory~"img\st00.png";
    let bg2=GetCurrentScriptDirectory~"img\moon3-1.png";
    let bg3=GetCurrentScriptDirectory~"img\cloud.png";

    let WALL_TOP = 8;
    let WALL_LEFT = 4;
    let WALL_RIGHT = 2;
    let WALL_BOTTOM = 1;

    let mm=0;
    let shot=0;
    let tame=0;
    let tame2=0;
    let d=70;
    let ang=0;

#include_function ".\BGfx.txt"

    @Initialize()
    {
        MagicCircle(false);
        SetEnemyMarker(true);
        SetLife(4000);
        SetDamageRate(225,64);
        SetTimer(39);
        SetNormPoint(-1);
        LoadGraphic(img);
        SetShotAutoDeleteClip(32,32,32,32);
        SetMovePositionRandom01(0,200,3,cx,128,cx,128);
        LoadGraphic(bg);
        LoadGraphic(bg2);
        LoadGraphic(bg3);
        LoadGraphic(GetCurrentScriptDirectory~"\img\circle_l.png");
        LoadUserShotData(GetCurrentScriptDirectory~".\shot_All.txt");

    }

    @MainLoop()
    {
        if (count2%4==0) {
            life=GetLife();
        }if (ten==1&&count2%4==1) {
            ten=0;
        }
        if (count2%4==3&&GetLife()<life&&GetLife()>0) {
            ten=1;
        }
        SetCollisionA(GetX(),GetY()-16,33);
        SetCollisionB(GetX(),GetY(),14);

        SetCommonData("Black",242);

        if (count>=2&&count2%50==0) {
            CreateEnemyFromFile(GetCurrentScriptDirectory~"Enemy02.txt",GetX()+rand(-20,-120),136+rand(0,85),0,0,0);
        }

        if (count>=2&&count2%50==25) {
            CreateEnemyFromFile(GetCurrentScriptDirectory~"Enemy02.txt",GetX()+rand(20,120),136+rand(0,95),0,0,0);
        }

        if (count2==0) {
            SetMovePositionRandom01(rand(30,40),20,12,GetX(),GetY()-22,GetX(),GetY()-22);
            move=80;
        }

        if (count>=142&&count%(35+80*(GetCommonDataDefault("ii1",0)<3000))==0&&count%440<400) {
            SetMovePositionRandom01(rand(30,50),20,12,GetClipMinX()+170,166,GetClipMaxX()-170,180);
            move=60;
        }

        if (count>=142&&count%(35+80*(GetCommonDataDefault("ii1",0)<3000))==0&&count%440<200) {
            SetMovePositionRandom01(rand(30,60),20,12,GetClipMinX()+120,166,GetClipMaxX()-120,180);
            move=60;
        }

        if (count2%500==25) {
            SetColor(255,0,0);
            Concentration01(138);
            PlaySE(GetCurrentScriptDirectory~"\se\puu81.wav");
        }

        if (count2>=130) {
            count++;
        }count2++;
        if (count>=10) {
            count3++;
        }move--;

        yield;
    }

    @Finalize()
    {
        DeleteAllEnemyWithoutBoss();
    }

    @DrawLoop()
    {
        SetTexture(img);
        SetAlpha(255);
        SetGraphicAngle(0,0,0);
        SetColor(255,255,255);
        SetRenderState(ALPHA);
        SetGraphicScale(1,1);
        SetGraphicRect(0,0,128,128);
        if (int(GetSpeedX())==0&&count2/12%4>=0) {
            SetGraphicRect(0,0,128,128);
        }
        if (int(GetSpeedX())==0&&count2/12%4>=1) {
            SetGraphicRect(0,128,128,256);
        }
        if (int(GetSpeedX())==0&&count2/12%4>=2) {
            SetGraphicRect(0,256,128,384);
        }
        if (int(GetSpeedX())==0&&count2/12%4>=3) {
            SetGraphicRect(0,384,128,512);
        }
        if (GetSpeedX()<0&&count2<=d) {
            SetGraphicRect(256,0,384,128);
        }
        if (GetSpeedX()<0&&count2<=d-8) {
            SetGraphicRect(256,128,384,256);
        }
        if (GetSpeedX()>=0&&count2<=d) {
            SetGraphicRect(256,256,384,384);
        }
        if (GetSpeedX()>=0&&count2<=d-8) {
            SetGraphicRect(256,384,384,512);
        }
        if (GetSpeedX()<0&&move>0) {
            SetGraphicRect(256,0,384,128);
        }
        if (GetSpeedX()<0&&move>8) {
            SetGraphicRect(256,128,384,256);
        }
        if (GetSpeedX()>=0&&move>0) {
            SetGraphicRect(256,256,384,384);
        }
        if (GetSpeedX()>=0&&move>8) {
            SetGraphicRect(256,384,384,512);
        }
        if (int(GetSpeedX())==0&&tame>0) {
            SetGraphicRect(128*4,0,128*5,128);
        }
        if (int(GetSpeedX())==0&&tame>0&&tame2<12) {
            SetGraphicRect(128*4,128,128*5,256);
        }
        if (ten==1&&OnBomb==false) {
            SetColor(160,160,180);
        }
        DrawGraphic(GetX(),GetY());

    }


}

