script_enemy_main
{
    let count=0;
    let count2=0;
    let count3=93;
    let R=0;
    let R2=0;
    let R3=0;
    let R4=0;
    let o=0;
    let move=0;
    let Level=0;
    let get;
    let try;
        let N16=0;
        let tame=0;
        let tame2=0;
        let ten=0;
        let life=0;

        let pass=GetCurrentScriptDirectory~"Spell.dat";

        let bombalpha=255;

        let cx=GetCenterX();
        let img=GetCurrentScriptDirectory~"\img\dot_flandre.png";

        let mm=0;
        let shot=0;
        let tame=0;
        let tame2=0;
        let c=0;
        let d=60;
        let ang=0;

    function CreateWayShot02(Way,Gap,PosX,PosY,Dist,Speed,Angle,Accelerate,MaxSpeed,Graphic,Delay) {
    ascent(let i in 0..Way) {
        CreateShot02(PosX+Dist*cos(Angle+Gap*(i+0.5-(Way * 0.5))),PosY+Dist*sin(Angle+Gap*(i+0.5-(Way * 0.5))),Speed,Angle+Gap*(i+0.5-(Way*0.5)),Accelerate,MaxSpeed,Graphic,Delay);
    }
}

@Initialize
{
    SetLife(465);
    SetDamageRate(1,1);

    SetScore(20);
    Level+=GetPlayerLife();
}


@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;
    }
    if (GetLife<=400) {
        SetDamageRate(0,0);
        if (N16==4) {
            AddScore(3000000);
            CreateEnemyFromFile(GetCurrentScriptDirectory~"Servant10.txt",GetX,GetY,0,0,1);
            loop(20) {
                CreateItem(ITEM_SCORE,GetX()+rand(-52,52),GetY()+44+rand(-38,38));
            }
            Explosion01(GetX,GetY,16,0.2,40);
            PlaySE(GetCurrentScriptDirectory~"\se\Baaaan.wav");
        }
        if (N16<100) {
            N16+=4;
        }
        if (N16<60&&count%3<=0&&GetLife<=400) {
            Explosion01(GetX+rand(-50,50),GetY+rand(-50,50),24,0.15,20);
        }
        if (N16<60&&count%12<=0&&GetLife<=400) {
            PlaySE(GetCurrentScriptDirectory~"\se\Baaaan.wav");
        }
    }

    if (count>84&&OnBomb==false&&GetLife>400) {
        SetCollisionA(GetX(),GetY()-6,40-22*(GetCommonDataDefault("ii1",0)>=2000));
        SetCollisionB(GetX(),GetY(),6);
    }

    if (GetLife>400) {
        if (count>=160&&count%30==(GetArgument%5)*5&&count%420>160) {
            PlaySE(GetCurrentScriptDirectory~"\se\Shot02.wav");
            CreateWayShot02(6,14,GetX,GetY,0,3.9,count+(GetArgument%5)*22,0,8,169,5);
            CreateWayShot02(8,12,GetX,GetY,0,3.2,180+count+(GetArgument%5)*22,0,8,169,5);
        }

        if (count>=160&&count%50==15&&count%420<=160) {
            PlaySE(GetCurrentScriptDirectory~"\se\Shot02.wav");
            CreateWayShot02(3,26,GetX,GetY,0,4.4,GetAngleToPlayer,0,8,169,12);
            CreateWayShot02(4,24,GetX,GetY,0,3.1,GetAngleToPlayer,0,8,169,12);
        }
    }

    else {
        if (count>=160&&count%26==(GetArgument%5)*5&&count%420>160) {
            PlaySE(GetCurrentScriptDirectory~"\se\Shot02.wav");
            CreateWayShot02(6,7,GetX,GetY,0,2.8+0.4*(GetArgument%5),count+(GetArgument%5)*24+4,0,8,72,5);
            CreateWayShot02(2+(GetArgument%5),6,GetX,GetY,0,2.6+0.6*(GetArgument%5),180+count+(GetArgument%5)*24,0,8,72,5);
        }

        if (count>=160&&count%12==5&&count%420<=150&&count%420>40) {
            PlaySE(GetCurrentScriptDirectory~"\se\Shot02.wav");
            CreateWayShot02(5,33,GetX,GetY,0,5.0,GetAngleToPlayer,0,8,169,15);
        }

        if (count>=160&&count%20==15&&count%420<=160) {
            CreateWayShot02(1,0,GetX,GetY,0,2.4,GetAngleToPlayer+rand(-44,44),0,8,196,5);
        }
    }

    SetX(GetCommonDataDefault("x",0)+count3*5*cos(count*2+(GetArgument%5)*72));
    SetY(GetCommonDataDefault("y",0)+count3*5*sin(count*2+(GetArgument%5)*72));

    if (count<=80) {
        count3--;
    }

    if (count>=550) {
        SetDamageRate(60,0);
    }

    count++;
    count2++;
    tame++;
    move--;

}

@Finalize
{
    loop(10) {
        CreateItem(ITEM_SCORE,GetX()+rand(-30,30),GetY()+rand(-20,40));
    }
}

@DrawLoop
{
    if (OnEnemySpell==true&&OnBomb==true&&bombalpha>0) {
        bombalpha-=5;
    }
    if (OnEnemySpell==true&&OnBomb==false&&bombalpha<255) {
        bombalpha+=5;
    }

    if (GetArgument>=5&&bombalpha<255) {
        bombalpha+=25.5;
    }

    SetTexture(GetCurrentScriptDirectory~"\img\circle_l.png");
    SetGraphicRect(0,0,256,256);
    SetGraphicAngle(0,0,0);
    SetAlpha(255);
    SetRenderState(ADD);
    SetColor(170+20*sin(count),20+20*sin(count),170+20*sin(count));
    if (count<=1) {
        SetGraphicScale(0,0);
    }
    if (count>1) {
        SetGraphicScale(0.1+0.005*count*(GetLife()/350),0.1+0.005*count*(GetLife()/350));
    }
    if (count>=80) {
        SetGraphicScale(0.1+0.4*(GetLife()/350),0.1+0.4*(GetLife()/350));
    }
    DrawGraphic(GetX(),GetY());

    SetTexture(img);
    SetAlpha(255);
    SetGraphicAngle(0,0,0);
    SetColor(bombalpha*((100-N16)/100),bombalpha*((100-N16)/100),bombalpha*((100-N16)/100));
    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&&move>0) {
        SetGraphicRect(256,0,384,128);
    }
    if (GetSpeedX()<0&&move>9) {
        SetGraphicRect(256,128,384,256);
    }
    if (GetSpeedX()>=0&&move>0) {
        SetGraphicRect(256,256,384,384);
    }
    if (GetSpeedX()>=0&&move>9) {
        SetGraphicRect(256,384,384,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 (tame>0&&tame2<=0) {
        SetGraphicRect(128*4,0,128*5,128);
    }
    if (tame>32&&tame2<=0) {
        SetGraphicRect(128*4,128,128*5,256);
    }
    if (tame>42&&tame2<=0) {
        SetGraphicRect(128*4,256,128*5,384);
    }
    if (ten==1&&OnBomb==false) {
        SetColor(100,100,180);
    }
    DrawGraphic(GetX(),GetY());

    if (bombalpha<255) {
        SetTexture(img);
        SetAlpha(255-bombalpha);
        SetGraphicRect(128*6,0,128*7,128);
        SetColor(255,200,200);
        SetGraphicScale(1.1,1.1);
        SetRenderState(ALPHA);
        if (count2/4%4>=0) {
            SetGraphicRect(128*6,0,128*7,128);
        }
        if (count2/4%4>=1) {
            SetGraphicRect(128*6,128,128*7,256);
        }
        if (count2/4%4>=2) {
            SetGraphicRect(128*6,256,128*7,384);
        }
        if (count2/4%4>=3) {
            SetGraphicRect(128*6,384,128*7,512);
        }
        DrawGraphic(GetX(),GetY()+12);
    }
}
}
