
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(4600);
        SetDamageRate(165,64);
        SetTimer(39);
        SetNormPoint(-1);
        LoadGraphic(img);
        SetShotAutoDeleteClip(32,32,32,32);
        SetMovePositionRandom01(0,200,3,cx,118,cx,118);
        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,35);
        SetCollisionB(GetX(),GetY(),14);

        SetCommonData("Black",222);

        if (count%500<=220&&count%105<=95&&count%9==0) {
            if (count%500>=45) {
                PlaySE(GetCurrentScriptDirectory~"\se\Shot04.wav");
                ascent( let t in 0..4 ) {
                    CreateShot01(GetX(),GetY()+2,rand(4.2,4.5),GetAngleToPlayer()+80*sin(count2*2)+rand(-8,8),33,20+t);
                }
                ascent( let t in 0..12 ) {
                    CreateShot01(GetX(),GetY()+2,rand(1.2,3.8),GetAngleToPlayer()+80*sin(count2*2)+rand(-16,16),196,20);
                }
                CreateShot02(GetX(),GetY()+2,7,GetAngleToPlayer()+80*sin(count2*2),-0.2,4.6,49,20);
            }
        }

        if (count%500<=435&&count%500>=235&&count%6==0) {
            PlaySE(GetCurrentScriptDirectory~"\se\Shot04.wav");
            if (count>=35) {
                CreateShot02(GetX(),GetY()+2,6,90+110*sin(count2*2),-0.2,3.4,49,20);
                ascent( let t in 0..4 ) {
                    CreateShot02(GetX(),GetY()+2,6,90+110*sin(count2*2)+rand(-20,20),-0.2,rand(2.5,3.2),33,20+t);
                }
                ascent( let t in 0..8 ) {
                    CreateShot02(GetX(),GetY()+2,6,90+110*sin(count2*2)+rand(-40,40),-0.2,rand(1.7,3),196,20);
                }
            }
        }

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

        if (count%500==5) {
            SetColor(255,0,0);
            Concentration01(125);
            PlaySE(GetCurrentScriptDirectory~"\se\puu81.wav");
        }

        if (count%160==69) {
            SetMovePositionRandom01(rand(50,80),20,5,GetClipMinX()+100,110,GetClipMaxX()-100,150);
            move=80;
        }

        yield;
    }

    @Finalize()
    {}

    @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());

    }


}

