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

    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;
    let rank=0;

#include_function ".\BGfx.txt"

    @Initialize()
    {
        MagicCircle(false);
        SetEnemyMarker(true);
        SetLife(4650);
        rank=1*(GetCommonDataDefault("ii1",0)<2000);
        SetDamageRate(130,35);
        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,36);
        SetCollisionB(GetX(),GetY(),14);

        SetCommonData("Black",242);

        if (count<=205&&count%103<=80&&count%6==0) {
            if (count>=35) {
                PlaySE(GetCurrentScriptDirectory~"\se\Shot04.wav");
                ascent( let t in 0..4 ) {
                    CreateShot01(GetX(),GetY()+2,rand(5.2,5.5),GetAngleToPlayer()+240-count*4+rand(-8,8),33,20);
                }
                ascent( let t in 0..8 ) {
                    CreateShot01(GetX(),GetY()+2,rand(2.2,5.5),GetAngleToPlayer()+240-count*4+rand(-13+4*rank,13-4*rank),196,20);
                }
                CreateShot02(GetX(),GetY()+2,7,GetAngleToPlayer()+240-count*4,-0.2,5.6,49,20);
            }
        }

        if (count>=242&&count%6==0) {
            PlaySE(GetCurrentScriptDirectory~"\se\Shot04.wav");
            if (count>=35) {
                CreateShot02(GetX(),GetY()+2,6,90+140*sin(count*2),-0.2,4.6,49,20);
                ascent( let t in 0..3 ) {
                    CreateShot02(GetX(),GetY()+2,6,90+140*sin(count*2)+rand(-4,4),-0.2,rand(3.5,4.2),33,20);
                }
                ascent( let t in 0..6 ) {
                    CreateShot02(GetX(),GetY()+2,6,90+140*sin(count*2)+rand(-20+12*rank,20-12*rank),-0.2,rand(2.7,4),196,20);
                }
            }
        }

        if (count>=242&&count%6==0) {
            PlaySE(GetCurrentScriptDirectory~"\se\Shot04.wav");
            if (count>=35) {
                CreateShot02(GetX(),GetY()+2,6,90-120*cos(count*2),-0.2,4.6,49,20);
                ascent( let t in 0..3 ) {
                    CreateShot02(GetX(),GetY()+2,6,90-120*cos(count*2)+rand(-4,4),-0.2,rand(3.5,4.2),33,20);
                }
                ascent( let t in 0..6 ) {
                    CreateShot02(GetX(),GetY()+2,6,90-120*cos(count*2)+rand(-20+12*rank,20-12*rank),-0.2,rand(2.7,4),196,20);
                }
            }
        }



        if (count2>=100) {
            count++;
        }if (count==200) {
            count+=15;
        }count2++;
        if (count>=10) {
            count3++;
        }move--;

        if (count2==40) {
            SetColor(255,0,0);
            Concentration01(125);
            PlaySE(GetCurrentScriptDirectory~"\se\puu811.wav");
        }

        if (count>=480) {
            count=0;
        }

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

        if (GetLife<500&&OnBomb==true) {
            SetDamageRate(20,8);
        }else {
            SetDamageRate(200,44);
        }

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

    }


}

