Ejemplo n.º 1
0
Tileset::Tileset(Subsystem& subsystem, const std::string& filename, ZipReader *zip)
    throw (KeyValueException, TilesetException)
    : Properties(filename + ".tileset", zip), subsystem(subsystem)
{
    try {
        tile_width = atoi(get_value("width").c_str());
        tile_height = atoi(get_value("height").c_str());
        if (tile_width != tile_height || tile_width < 16 || tile_width > static_cast<int>(sizeof(mask_t) * 8)) {
            throw TilesetException("Malformed tile size: " + filename);
        }
        create_tile(filename + ".png", zip);
    } catch (const TilesetException&) {
        throw;
    } catch (const Exception& e) {
        throw TilesetException(e.what());
    }
}
Ejemplo n.º 2
0
Tileset::Tileset(const std::string& fname, Video::Driver* v)
    : video(v)
    , animTimer(0)
{
    CDEBUG("ctileset::loadvsp");
    vsp = new VSP;
    
    if (!vsp->Load(IkaPath::_game + fname)) {
        throw std::runtime_error("Unable to load VSP file " + fname + "\n");
    }
    
    frameCount = vsp->NumTiles();
    frameWidth = vsp->Width();
    frameHeight = vsp->Height();
    
    try {
        hFrame.resize(frameCount);
        for (uint i = 0; i < frameCount; i++) {
            hFrame[i] = video->CreateImage(vsp->GetTile(i));
        }
    } catch(...) {
        throw TilesetException();
    }
    
    // Next up, set up the tile animation stuff.
    tileIndex.resize(frameCount);  // Make the vectors fit.
    flipFlag.resize(frameCount);
    for (uint i = 0; i < frameCount; i++) {
        tileIndex[i] = i;  // Set initial values for the vectors.
        flipFlag[i] = false;
    }

    animstate = vsp->vspAnim;
    for (uint j = 0; j < vsp->vspAnim.size(); j++) {
        animstate[j].count = animstate[j].delay;  // Init the counter.
    }
}