
#include "mob_effect.hh"

#include "itty/paths.hh"

#include "strings.hh"

//////////////////////////////////////////////////////////////////////////////
/// Dust plume
//////////////////////////////////////////////////////////////////////////////

Mob_dust::Mob_dust(Mobs& mobs, const itty::Box& box, Place*) : Mob{box, 0}
{
        brush = mobs.load_frames("dust.png", 4, 1);
}

bool Mob_dust::update(Scene& sc)
{
        frame += 12.f / itty::conf.fps;
        return frame >= 4.f;
}

void Mob_dust::render(Mobs& mobs)
{
        auto mat = itty::Mat::translate(p.floor());
        if (is(FLIP))
                mat *= itty::Mat::scale(-1, 1);
        mobs.quads.push(brush + std::floor(frame), mat);
}

void Mob_dust::make_from(Mobs& mobs, Mob *p)
{
        static const itty::Vec size{4, 4};
        Mob *m;

        if (fabsf(p->v.x) > 1) {
                auto c = p->p;
                c.y += p->r.y - size.y;
                m = mobs.construct("dust", c, size);
                if (p->is(FLIP))
                        m->set(FLIP);
        } else {
                auto c = p->p;
                c.x -= p->r.x * 0.5f;
                c.y += p->r.y - size.y;
                m = mobs.construct("dust", c, size);
                c.x += p->r.x;
                m = mobs.construct("dust", c, size);
                m->set(FLIP);
        }
}

//////////////////////////////////////////////////////////////////////////////
/// Splat
//////////////////////////////////////////////////////////////////////////////

Mob_splat::Mob_splat(Mobs& mobs, const itty::Box& box, Place*) : Mob{box, 0}
{
        brush = mobs.load_frames("splat.png", 5, 1);
}

bool Mob_splat::update(Scene& sc)
{
        frame += 12.f / itty::conf.fps;
        return frame >= 5.f;
}

void Mob_splat::render(Mobs& mobs)
{
        auto mat = itty::Mat::translate(p.floor());
        mobs.quads.push(brush + std::floor(frame), mat);
}

//////////////////////////////////////////////////////////////////////////////
/// Poof
//////////////////////////////////////////////////////////////////////////////

Mob_poof::Mob_poof(Mobs& mobs, const itty::Box& box, Place*) : Mob{box, 0}
{
        brush = mobs.load_frames("poof.png", 7, 1);
}

bool Mob_poof::update(Scene& sc)
{
        frame += 12.f / itty::conf.fps;
        return frame >= 7.f;
}

void Mob_poof::render(Mobs& mobs)
{
        auto mat = itty::Mat::translate(p.floor());
        mobs.quads.push(brush + std::floor(frame), mat);
}

