コード例 #1
0
ファイル: Animation.cpp プロジェクト: smaximov/falltergeist
Animation::Animation(std::string frmName, unsigned int direction) : ActiveUI()
{
    auto frm = ResourceManager::frmFileType(frmName);
    setTexture(ResourceManager::texture(frmName));


    int xOffset = frm->shiftX(direction);
    int yOffset = frm->shiftY(direction);


    // Смещение кадра в текстуре анимации
    unsigned int x = 0;
    unsigned int y = 0;

    for (unsigned int d = 0; d != direction; ++d)
    {
        y += frm->height(d); //? может i - 1
    }


    for (auto f = 0; f != frm->framesPerDirection(); ++f)
    {
        xOffset += frm->offsetX(direction, f);
        yOffset += frm->offsetY(direction, f);

        auto frame = new AnimationFrame();
        frame->setWidth(frm->width(direction, f));
        frame->setHeight(frm->height(direction, f));
        frame->setXOffset(xOffset);
        frame->setYOffset(yOffset);
        frame->setY(y);
        frame->setX(x);

        auto fps = frm->framesPerSecond();
        if (fps == 0)
        {
            frame->setDuration(1000);
        }
        else
        {
            frame->setDuration(std::round(1000.0/static_cast<double>(frm->framesPerSecond())));
        }

        x += frm->width(direction);
        frames()->push_back(frame);
    }

    if (frm->animatedPalette())
    {
        AnimatedPalette*  palette=Game::getInstance()->animatedPalette();
        auto masks = frm->animatedMasks();

        if ((*masks)[libfalltergeist::FrmFileType::MASK_MONITOR] != NULL)
        {
            for (auto i=0; i<5; i++)
            {
                unsigned int* mask = new unsigned int[frm->width() * frm->height()]();

                //modify
                for (unsigned int j = 0; j< frm->width() * frm->height(); j++)
                {
                    mask[j] = palette->color((*masks)[libfalltergeist::FrmFileType::MASK_MONITOR][j],i);
                }
                //set
                auto texture = new Texture(frm->width(), frm->height());
                texture->loadFromRGBA(mask);
                _monitorTextures.push_back(texture);
            }
        }

        if ((*masks)[libfalltergeist::FrmFileType::MASK_SLIME] != NULL)
        {
            for (auto i=0; i<4; i++)
            {
                unsigned int* mask = new unsigned int[frm->width() * frm->height()]();	

                //modify
                for (unsigned int j = 0; j< frm->width() * frm->height(); j++)
                {
                    mask[j] = palette->color(((*masks)[libfalltergeist::FrmFileType::MASK_SLIME][j]),i);
                }
                //set
                auto texture = new Texture(frm->width(), frm->height());
                texture->loadFromRGBA(mask);
                _slimeTextures.push_back(texture);
            }
        }

        if ((*masks)[libfalltergeist::FrmFileType::MASK_SHORE] != NULL)
        {
            for (auto i=0; i<6; i++)
            {
                unsigned int* mask = new unsigned int[frm->width() * frm->height()]();

                //modify
                for (unsigned int j = 0; j< frm->width() * frm->height(); j++)
                {
                    mask[j] = palette->color(((*masks)[libfalltergeist::FrmFileType::MASK_SHORE][j]),i);
                }
                //set
                auto texture = new Texture(frm->width(), frm->height());
                texture->loadFromRGBA(mask);
                _shoreTextures.push_back(texture);
            }
        }


        if ((*masks)[libfalltergeist::FrmFileType::MASK_FIRE_SLOW] != NULL)
        {
            for (auto i=0; i<5; i++)
            {
                unsigned int* mask = new unsigned int[frm->width() * frm->height()]();

                //modify
                for (unsigned int j = 0; j< frm->width() * frm->height(); j++)
                {
                    mask[j] = palette->color(((*masks)[libfalltergeist::FrmFileType::MASK_FIRE_SLOW][j]),i);
                }
                //set
                auto texture = new Texture(frm->width(), frm->height());
                texture->loadFromRGBA(mask);
                _fireSlowTextures.push_back(texture);
            }
        }


        if ((*masks)[libfalltergeist::FrmFileType::MASK_FIRE_FAST] != NULL)
        {
            for (auto i=0; i<5; i++)
            {
                unsigned int* mask = new unsigned int[frm->width() * frm->height()]();
                //modify
                for (unsigned int j = 0; j< frm->width() * frm->height(); j++)
                {
                    mask[j] = palette->color(((*masks)[libfalltergeist::FrmFileType::MASK_FIRE_FAST][j]),i);
                }
                //set
                auto texture = new Texture(frm->width(), frm->height());
                texture->loadFromRGBA(mask);
                _fireFastTextures.push_back(texture);
            }
        }

        if ((*masks)[libfalltergeist::FrmFileType::MASK_REDDOT] != NULL)
        {
            for (auto i=0; i<16; i++)
            {
                unsigned int* mask = new unsigned int[frm->width() * frm->height()]();
                //modify
                for (unsigned int j = 0; j< frm->width() * frm->height(); j++)
                {
                    mask[j] = palette->color(((*masks)[libfalltergeist::FrmFileType::MASK_REDDOT][j]),i);
                }
                //set
                auto texture = new Texture(frm->width(), frm->height());
                texture->loadFromRGBA(mask);
                _reddotTextures.push_back(texture);
            }
        }
    }
}
コード例 #2
0
ファイル: AnimatedImage.cpp プロジェクト: Legun/falltergeist
AnimatedImage::AnimatedImage(std::shared_ptr<libfalltergeist::FrmFileType> frm, unsigned int direction)
{

    setTexture(new Texture(frm->width(), frm->height()));
    _texture->loadFromRGBA(frm->rgba(ResourceManager::palFileType("color.pal")));
    setXOffset(frm->offsetX(direction) + frm->shiftX(direction));
    setYOffset(frm->offsetY(direction) + frm->shiftY(direction));

    AnimatedPalette*  palette=Game::getInstance()->animatedPalette();
    auto masks = frm->animatedMasks();

    if ((*masks)[libfalltergeist::FrmFileType::MASK_MONITOR] != NULL)
    {
        for (auto i=0; i<5; i++)
        {
            unsigned int* mask = new unsigned int[frm->width() * frm->height()]();

            //modify
            for (unsigned int j = 0; j< frm->width() * frm->height(); j++)
            {
                mask[j] = palette->color((*masks)[libfalltergeist::FrmFileType::MASK_MONITOR][j],i);
            }
            //set
            auto texture = new Texture(frm->width(), frm->height());
            texture->loadFromRGBA(mask);
            _monitorTextures.push_back(texture);
        }
    }

    if ((*masks)[libfalltergeist::FrmFileType::MASK_SLIME] != NULL)
    {
        for (auto i=0; i<4; i++)
        {
            unsigned int* mask = new unsigned int[frm->width() * frm->height()]();

            //modify
            for (unsigned int j = 0; j< frm->width() * frm->height(); j++)
            {
                mask[j] = palette->color(((*masks)[libfalltergeist::FrmFileType::MASK_SLIME][j]),i);
            }
            //set
            auto texture = new Texture(frm->width(), frm->height());
            texture->loadFromRGBA(mask);
            _slimeTextures.push_back(texture);
        }
    }

    if ((*masks)[libfalltergeist::FrmFileType::MASK_SHORE] != NULL)
    {
        for (auto i=0; i<6; i++)
        {
            unsigned int* mask = new unsigned int[frm->width() * frm->height()]();

            //modify
            for (unsigned int j = 0; j< frm->width() * frm->height(); j++)
            {
                mask[j] = palette->color(((*masks)[libfalltergeist::FrmFileType::MASK_SHORE][j]),i);
            }
            //set
            auto texture = new Texture(frm->width(), frm->height());
            texture->loadFromRGBA(mask);
            _shoreTextures.push_back(texture);
        }
    }


    if ((*masks)[libfalltergeist::FrmFileType::MASK_FIRE_SLOW] != NULL)
    {
        for (auto i=0; i<5; i++)
        {
            unsigned int* mask = new unsigned int[frm->width() * frm->height()]();

            //modify
            for (unsigned int j = 0; j< frm->width() * frm->height(); j++)
            {
                mask[j] = palette->color(((*masks)[libfalltergeist::FrmFileType::MASK_FIRE_SLOW][j]),i);
            }
            //set
            auto texture = new Texture(frm->width(), frm->height());
            texture->loadFromRGBA(mask);
            _fireSlowTextures.push_back(texture);
        }
    }


    if ((*masks)[libfalltergeist::FrmFileType::MASK_FIRE_FAST] != NULL)
    {
        for (auto i=0; i<5; i++)
        {
            unsigned int* mask = new unsigned int[frm->width() * frm->height()]();
            //modify
            for (unsigned int j = 0; j< frm->width() * frm->height(); j++)
            {
                mask[j] = palette->color(((*masks)[libfalltergeist::FrmFileType::MASK_FIRE_FAST][j]),i);
            }
            //set
            auto texture = new Texture(frm->width(), frm->height());
            texture->loadFromRGBA(mask);
            _fireFastTextures.push_back(texture);
        }
    }


    if ((*masks)[libfalltergeist::FrmFileType::MASK_REDDOT] != NULL)
    {
        for (auto i=0; i<16; i++)
        {
            unsigned int* mask = new unsigned int[frm->width() * frm->height()]();

            //modify
            for (unsigned int j = 0; j< frm->width() * frm->height(); j++)
            {
                mask[j] = palette->color(((*masks)[libfalltergeist::FrmFileType::MASK_REDDOT][j]),i);
            }
            //set
            auto texture = new Texture(frm->width(), frm->height());
            texture->loadFromRGBA(mask);
            _reddotTextures.push_back(texture);
        }
    }
}