//g
script_enemy_main
{
    let count=0;
    let N17=0;
    function dead{
        SetDamageRate(0,0);

        if (N17==50) {
            AddScore(100000);
            PlaySE(GetCurrentScriptDirectory~"\se\bom27_b.wav");
            CreateEnemyFromFile(GetCurrentScriptDirectory~"Servant10.txt",GetX,GetY,0,0,1);
            if (GetLife<5400) {
                loop(3) {
                    CreateItem(ITEM_SCORE,GetX()+rand(-30,30),GetY()+rand(10,30));
                }
            }
        }

        if (N17<100) {
            N17+=50;
        }
        if (N17>=100) {
            VanishEnemy;
        }
    }

    @Initialize
    {
        SetLife(5430);
        SetDamageRate(100,2);
        SetColor(255-150*(OnEnemySpell==false),0,0);
        Concentration01(60);
    }
    @MainLoop
    {
        if (GetLife<5400) {
            dead;
        }
        else {
            if (count>60) {
                SetCollisionA(GetX(),GetY(),30);
            }
        }
        if (GetCommonDataDefault("ii1",0)>=2000&&OnEnemySpell==true) {
            if (count==60&&GetX<GetCenterX) {
                SetShotColor(0,0,0);
                PlaySE(GetCurrentScriptDirectory~"\se\Shot02.wav");
                ascent(let tt in 0..3) {
                    ascent(let t in 0..12) {
                        CreateShot01(GetX(),GetY(),1.6,GetX%10+GetAngleToPlayer()+t*7-25,105,10*tt+10*t);
                        CreateShot01(GetX(),GetY(),1.6,180+GetX%10+GetAngleToPlayer()+t*7-25,105,10*tt+10*t);
                    }
                }
            }
            if (count==60&&GetX>=GetCenterX) {
                SetShotColor(0,0,0);
                PlaySE(GetCurrentScriptDirectory~"\se\Shot02.wav");
                ascent(let tt in 0..3) {
                    ascent(let t in 0..12) {
                        CreateShot01(GetX(),GetY(),1.6,GetX%10+GetAngleToPlayer()-t*7+25,105,10*tt+10*t);
                        CreateShot01(GetX(),GetY(),1.6,180+GetX%10+GetAngleToPlayer()-t*7+25,105,10*tt+10*t);
                    }
                }
            }
        }

        if (GetCommonDataDefault("ii1",0)<2000&&count%120<=50&&count<180&&count%6==1) {
            PlaySE(GetCurrentScriptDirectory~"\se\Shot06.wav");
            CreateShot01(GetX(),GetY(),1.6+(count%60)*0.03,GetAngleToPlayer(),72,5);
        }
        if (GetCommonDataDefault("ii1",0)<2000&&count%45==1) {
            CreateShot01(GetX(),GetY(),1.3,GetAngleToPlayer()+rand(-35,35),196,5);
        }

        if (GetCommonDataDefault("ii1",0)>=2000&&count%120<=50&&count<180&&count%6==1&&OnEnemySpell==false) {
            PlaySE(GetCurrentScriptDirectory~"\se\Shot06.wav");
            CreateShot01(GetX(),GetY(),1.6+(count%60)*0.03,GetAngleToPlayer(),72,5);
        }
        if (GetCommonDataDefault("ii1",0)>=2000&&count%25==22&&count>50&&OnEnemySpell==false) {
            PlaySE(GetCurrentScriptDirectory~"\se\Shot06.wav");
            CreateShot01(GetX(),GetY(),4.2,rand(-22,22)+GetAngleToPlayer(),169,5);
        }
        if (count>130) {
            SetSpeed((count-130)/160);
            SetAngle(270);
        }
        if (GetY<=-16) {
            VanishEnemy;
        }

        count++;

    }
    @Finalize()
    {
        if (N17<=0) {
            CreateItem(ITEM_SCORE,GetX(),GetY());
            SetColor(155,0,0);
            Explosion01(GetX,GetY,5,0.02,180);
        }
    }

    @DrawLoop
    {
    SetTexture(GetCurrentScriptDirectory~"\img\familiar.png");
    if (count<=20) {
        SetColor(0,0,0);
    }
    if (count>=20&&count<41) {
        SetColor((count-20)*5,(count-20)*5,(count-20)*5);
    }
    if (count>=41) {
        SetColor(128,128,128);
    }
    SetGraphicAngle(0,0,0);
    SetGraphicScale(1,1);
    SetAlpha(255);
    SetRenderState(ADD);
    SetGraphicRect(144,48,192,96);
    DrawGraphic(GetX(),GetY());

        SetTexture(GetCurrentScriptDirectory~"img\dot_remilia.png");
        if (count>=0&&count<64) {
            SetAlpha(count*5);
        }
        if (count>=64) {
            SetAlpha(255);
        }
        SetRenderState(ALPHA);
        SetGraphicRect(128*7, 0, 128*8, 128);
        if (int(count/4%4)>=0) {
            SetGraphicRect(128*7,0,128*8,128);
        }
        if (int(count/4%4)>=1) {
            SetGraphicRect(128*7,128,128*8,256);
        }
        if (int(count/4%4)>=2) {
            SetGraphicRect(128*7,256,128*8,384);
        }
        if (int(count/4%4)>=3) {
            SetGraphicRect(128*7,384,128*8,512);
        }
        SetGraphicAngle(0,0,0);
        SetGraphicScale(1.0,1.0);
        DrawGraphic(GetX(),GetY());
    }
}

