
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 sh00=GetCurrentScriptDirectory~"\se\Shot00.wav";
    let sh01=GetCurrentScriptDirectory~"\se\Shot02.wav";
    let Beem=GetCurrentScriptDirectory~"\se\Laser.wav";

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

#include_function ".\BGfx.txt"

    @Initialize()
    {
        MagicCircle(false);
        SetEnemyMarker(true);
        SetLife(3300);
        SetTimer(39);
        SetNormPoint(-1);
        LoadGraphic(img);
        SetShotAutoDeleteClip(32,32,32,32);
        SetMovePositionRandom01(0,200,5,cx,100,cx,100);
        LoadGraphic(bg);
        LoadGraphic(bg2);
        LoadGraphic(bg3);
        if (OnBomb==true) {
            sy=1;
        }
        LoadGraphic(GetCurrentScriptDirectory~"\img\circle_l.png");
        LoadUserShotData(GetCurrentScriptDirectory~".\shot_All.txt");

    }

    @MainLoop()
    {
        SetCommonData("Black",232);
        if (count2%4==0) {
            life=GetLife();
        }if (ten==1&&count2%4==1) {
            ten=0;
        }
        if (count2%4==3&&GetLife()<life&&GetLife()>0) {
            ten=1;
        }

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

        if (OnBomb==false) {
            sy=0;
        }
        if (sy==0) {
            SetDamageRate(138,54);
        }else {
            SetDamageRate(12,4);
        }

        if (count%160==0) {
            a=1;
        }a+=0.012;
        if (count2>200&&count%160>5&&count%160<70&&count%12==0)
        {
            let ang=GetAngleToPlayer();
            PlaySE(GetCurrentScriptDirectory~"\se\Shot04.wav");
            ascent( let t in 0..4 ) {
                CreateShot01(GetX(),GetY()+2,rand(3.5,5.2),GetAngleToPlayer()+rand(-2,2),33,0);
            }
            ascent( let t in 0..8 ) {
                CreateShot01(GetX(),GetY()+2,rand(1.0+1*(GetCommonDataDefault("ii1",0)<2000),4.7),GetAngleToPlayer()+rand(-8+2*(GetCommonDataDefault("ii1",0)<2000),8-2*(GetCommonDataDefault("ii1",0)<2000)),196,0);
            }
            CreateShot02(GetX(),GetY()+2,8,GetAngleToPlayer(),-0.2,5.8,49,0);

            if (GetCommonDataDefault("ii1",0)>=2000) {
                ascent( let t in 0..4 ) {
                    CreateShot01(GetX(),GetY()+2,rand(3.2,6.2),GetAngleToPlayer()+rand(-4,4)-40,33,0);
                }
                ascent( let t in 0..8 ) {
                    CreateShot01(GetX(),GetY()+2,rand(1.2+1*(GetCommonDataDefault("ii1",0)<2000),6.2),GetAngleToPlayer()+rand(-8,8)-40,196,0);
                }
                CreateShot02(GetX(),GetY()+2,8,GetAngleToPlayer()-40,-0.2,6.6,49,0);
                ascent( let t in 0..4 ) {
                    CreateShot01(GetX(),GetY()+2,rand(3.2,6.2),GetAngleToPlayer()+rand(-4,4)+40,33,0);
                }
                ascent( let t in 0..8 ) {
                    CreateShot01(GetX(),GetY()+2,rand(1.2+1*(GetCommonDataDefault("ii1",0)<2000),6.2),GetAngleToPlayer()+rand(-8,8)+40,196,0);
                }
                CreateShot02(GetX(),GetY()+2,8,GetAngleToPlayer()+40,-0.2,6.6,49,0);
            }
            else {
                ascent( let t in 0..4 ) {
                    CreateShot01(GetX(),GetY()+2,rand(3.2,6.2),GetAngleToPlayer()+rand(-4,4)-50,33,0);
                }
                ascent( let t in 0..8 ) {
                    CreateShot01(GetX(),GetY()+2,rand(1.2+0.5*(GetCommonDataDefault("ii1",0)<2000),6.2),GetAngleToPlayer()+rand(-7,7)-50,196,0);
                }
                CreateShot02(GetX(),GetY()+2,8,GetAngleToPlayer()-50,-0.2,6.6,49,0);
                ascent( let t in 0..4 ) {
                    CreateShot01(GetX(),GetY()+2,rand(3.2,6.2),GetAngleToPlayer()+rand(-4,4)+50,33,0);
                }
                ascent( let t in 0..8 ) {
                    CreateShot01(GetX(),GetY()+2,rand(1.2+0.5*(GetCommonDataDefault("ii1",0)<2000),6.2),GetAngleToPlayer()+rand(-7,7)+50,196,0);
                }
                CreateShot02(GetX(),GetY()+2,8,GetAngleToPlayer()+50,-0.2,6.6,49,0);
            }
        }

        if (count%160>60&&count%160<100&&count%4==0)
        {
            let ang=GetAngleToPlayer();
            let i=0;
            CreateLaser01(GetX(),GetY(),6,ang+65,188,6,203,25);
            CreateLaser01(GetX(),GetY(),6,ang-65,188,6,203,25);
            CreateLaser01(GetX(),GetY(),6,ang+115,188,6,203,25);
            CreateLaser01(GetX(),GetY(),6,ang-115,188,6,203,25);

            //if(count2>200){CreateShot02(GetX(),GetY(),12-count/20,GetAngleToPlayer()+rand(-8,8),-0.4,3.6,196,0);}
            PlaySE(sh00);
        }
        if (count%320>90&&count%320<150&&count%4==0)
        {
            let ang=GetAngleToPlayer();
            let i=0;
            CreateLaser01(GetX(),GetY(),6,ang+65,188,6,203,25);
            CreateLaser01(GetX(),GetY(),6,ang-65,188,6,203,25);
            CreateLaser01(GetX(),GetY(),6,ang+115,188,6,203,25);
            CreateLaser01(GetX(),GetY(),6,ang-115,188,6,203,25);

            while (i<360) {
                CreateShot02(GetX(),GetY(),12-count/20,i-count3,-0.4,3.2,169,0);
                i+=40;
                PlaySE(sh01);
            }
        }
        if (count%320>250&&count%320<310&&count%4==0)
        {
            let ang=GetAngleToPlayer();
            let i=0;
            CreateLaser01(GetX(),GetY(),6,ang+65,188,6,203,25);
            CreateLaser01(GetX(),GetY(),6,ang-65,188,6,203,25);
            CreateLaser01(GetX(),GetY(),6,ang+115,188,6,203,25);
            CreateLaser01(GetX(),GetY(),6,ang-115,188,6,203,25);

            while (i>-360) {
                CreateShot02(GetX(),GetY(),12-count/20,i+count3,-0.4,3.2,169,0);
                i-=40;
                PlaySE(sh01);
            }
        }
        if (count%320==150||count%320==310)
        {
            SetMovePositionRandom01(70,80,5,GetClipMinX()+100,120,GetClipMaxX()-100,100);
            move=70;
        }

        SetCollisionA(GetX(),GetY(),34);
        SetCollisionB(GetX(),GetY(),14);

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


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

    }


}

