Ejemplo n.º 1
0
Archivo: Chunk.cpp Proyecto: Cmdu76/Map
void Chunk::loadFromPacket(sf::Packet& packet)
{
    // packet >> mCoords.x >> mCoords.y;   has already been read by the manager

    std::size_t layerCount;
    packet >> layerCount;
    for (std::size_t i = 0; i < layerCount; i++)
    {
        addLayer();
    }

    sf::Vector2i p;
    for (p.x = 0; p.x < Properties::getChunkSize().x; p.x++)
    {
        for (p.y = 0; p.y < Properties::getChunkSize().y; p.y++)
        {
            for (int z = 0; z < (int)getLayerCount(); z++)
            {
                int id;
                packet >> id;
                setTileId(p,z,id);
            }
        }
    }
}
Ejemplo n.º 2
0
void TilemapComponent::init()
{
    VisualComponent::init();

    auto tileset = newObject<Tileset>();
    auto layer = newObject<TilemapLayer>();
    layer->resize(5, 5);
    layer->setTileSize(Size(1, 1));
    layer->setOrientation(TilemapOrientation::UpFlow);
    layer->setTileId(0, 0, 1);
    layer->setTileId(1, 1, 1);
    layer->setTileId(0, 4, 1);
    layer->setTileId(1, 4, 1);
    layer->setTileId(2, 4, 1);
    layer->setTileId(3, 4, 1);
    layer->setTileId(4, 4, 1);
    m_tilemap = newObject<TilemapModel>();
    m_tilemap->addTileset(tileset);
    m_tilemap->addLayer(layer);
}
Ejemplo n.º 3
0
Archivo: Chunk.cpp Proyecto: Cmdu76/Map
bool Chunk::load()
{
    std::ifstream file(getPathFromCoords(mCoords));
    if (!file)
    {
        return false;
    }

    std::string line;
    std::size_t layerCount;
    std::getline(file,line);
    {
        std::istringstream iss(line);
        iss >> layerCount;
    }
    for (std::size_t i = 0; i < layerCount; i++)
    {
        addLayer();
    }

    sf::Vector2i coords = sf::Vector2i();
    int z = 0;
    while (std::getline(file,line))
    {
        std::stringstream ss1(line);
        std::string temp1;
        coords.x = 0;
        while (std::getline(ss1,temp1,';'))
        {
            std::stringstream ss2(temp1);
            std::string temp2;
            z = 0;
            while (std::getline(ss2,temp2,'-'))
            {
                int id;
                {
                    std::istringstream iss(temp2);
                    iss >> id;
                }
                setTileId(coords,z,id);
                z++;
            }
            coords.x++;
        }
        coords.y++;
    }
    file.close();
    mNeedSave = false;
    return true;
}
Ejemplo n.º 4
0
 void setTileId(sf::Vector2i const& coords, int id)
 {
     sf::Vector2i chunkCoords = NOrthogonal::coordsToChunk(coords);
     sf::Vector2i tileCoords = NOrthogonal::coordsToRelative(coords);
     setTileId(chunkCoords, tileCoords, id);
 }
Ejemplo n.º 5
0
void GraphicsTileItem::clearTile() {
    QImage voidImage(m_tileWidth, m_tileHeight, QImage::Format_RGB32);
    voidImage.fill(0xFF6DACF8);
    setPixmap(QPixmap::fromImage(voidImage));
    setTileId(-1);
}