//______________________________________________ void ShadowHelper::reset( void ) { #ifdef Q_WS_X11 // round pixmaps foreach( const Qt::HANDLE& value, _pixmaps ) XFreePixmap( QX11Info::display(), value ); foreach( const Qt::HANDLE& value, _dockPixmaps ) XFreePixmap( QX11Info::display(), value ); #endif _pixmaps.clear(); _dockPixmaps.clear(); _tiles = TileSet(); _dockTiles = TileSet(); // reset size _size = 0; }
bool Map::loadMap() { bool isArena = false; int first = 0; int row = 0; QString line; QString fileName = QFileDialog::getOpenFileName(); QFile file(fileName); QStringList mapTileSet; if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) return false; QTextStream in(&file); while (!in.atEnd()) { line = in.readLine(); mapTileSet = line.split(","); if (first == 0) { isArena = mapTileSet.takeFirst().toInt(); mWidth = mapTileSet.takeFirst().toInt(); mHeight = mapTileSet.takeFirst().toInt(); first = 1; } else { mMapGrid.append(QList<TileSet>() ); for (int column = 0; column < mHeight; column++) { mMapGrid[row].append(TileSet(row, column, true, mapTileSet.takeFirst())); if (mMapGrid[row][column].getGamePiece().compare("You") == 0) { setCharacterTileSet(mMapGrid[row][column]); setIsCharacterPlaced(true); } if (mMapGrid[row][column].getGamePiece().compare("Exit") == 0) { setExitTileSet(mMapGrid[row][column]); setIsExitPlaced(true); } if (mMapGrid[row][column].getGamePiece().compare("Monster") == 0) { addMonsterTileSet(mMapGrid[row][column]); } } row++; } } file.flush(); file.close(); displayMap(); return isArena; }
//_______________________________________________________ void ShadowHelper::reloadConfig( void ) { // shadow cache shadowCache().readConfig(); // reset reset(); // retrieve shadow pixmap _size = shadowCache().shadowSize(); QPixmap pixmap( shadowCache().pixmap( ShadowCache::Key() ) ); if( !pixmap.isNull() ) { QPainter painter( &pixmap ); // add transparency painter.setCompositionMode(QPainter::CompositionMode_DestinationIn); painter.fillRect( pixmap.rect(), QColor( 0, 0, 0, 150 ) ); } // recreate tileset _tiles = TileSet( pixmap, pixmap.width()/2, pixmap.height()/2, 1, 1 ); if( !pixmap.isNull() ) { QPainter painter( &pixmap ); // add round corners const QRect cornerRect( (pixmap.width()-10)/2, (pixmap.height()-10)/2, 10, 10 ); _helper.roundCorner( QPalette().color( QPalette::Window ) )->render( cornerRect, &painter ); } // recreate tileset _dockTiles = TileSet( pixmap, pixmap.width()/2, pixmap.height()/2, 1, 1 ); // update property for registered widgets for( QMap<QWidget*,WId>::const_iterator iter = _widgets.constBegin(); iter != _widgets.constEnd(); ++iter ) { installX11Shadows( iter.key() ); } }
void Map::createMapGrid() { for (int row = 0; row < mHeight; row++) { mMapGrid.append(QList<TileSet>() ); for (int column = 0; column < mWidth; column++) { mMapGrid[row].append(TileSet(row, column, true, QString(""))); } } }
bool TileMap::load(const std::string& tileset, sf::Vector2u tileSize, const int* tiles, unsigned int width, unsigned int height, const int* selected, int length) { this->levelWidth = width * 32; this->levelHeight = height * 32; this->tiles = TileSet(levelWidth, levelHeight, 150); // load the tileset texture if (!m_tileset.loadFromFile(tileset)) return false; // resize the vertex array to fit the level size m_vertices.setPrimitiveType(sf::Quads); m_vertices.resize(width * height * 4); int p = 0; // populate the vertex array, with one quad per tile for (unsigned int i = 0; i < width; ++i) for (unsigned int j = 0; j < height; ++j) { // get the current tile number int tileNumber = tiles[i + j * width]; // find its position in the tileset texture int tu = tileNumber % (m_tileset.getSize().x / tileSize.x); int tv = tileNumber / (m_tileset.getSize().x / tileSize.x); if(tu != 0){ // get a pointer to the current tile's quad sf::Vertex* quad = &m_vertices[(i + j * width) * 4]; // define its 4 corners quad[0].position = sf::Vector2f(i * tileSize.x, j * tileSize.y); quad[1].position = sf::Vector2f((i + 1) * tileSize.x, j * tileSize.y); quad[2].position = sf::Vector2f((i + 1) * tileSize.x, (j + 1) * tileSize.y); quad[3].position = sf::Vector2f(i * tileSize.x, (j + 1) * tileSize.y); for(int k = 0; k < length; k++){ if(tu == selected[k]){ this->tiles.addTile(Tile(quad[0].position, p++)); //break; } } // define its 4 texture coordinates quad[0].texCoords = sf::Vector2f(tu * tileSize.x, tv * tileSize.y); quad[1].texCoords = sf::Vector2f((tu + 1) * tileSize.x, tv * tileSize.y); quad[2].texCoords = sf::Vector2f((tu + 1) * tileSize.x, (tv + 1) * tileSize.y); quad[3].texCoords = sf::Vector2f(tu * tileSize.x, (tv + 1) * tileSize.y); } } return true; }
int Level::loadTileSets(XMLElement *tileSetNode, Graphics &gfx) { while (tileSetNode) { int firstGid; int columns, tileCount; int tileWidth, tileHeight; const char *src = tileSetNode->FirstChildElement("image")->Attribute("source"); std::stringstream ss; ss << "../data/maps/" << src; tileSetNode->QueryIntAttribute("firstgid", &firstGid); tileSetNode->QueryIntAttribute("columns", &columns); tileSetNode->QueryIntAttribute("tilecount", &tileCount); tileSetNode->QueryIntAttribute("tilewidth", &tileWidth); tileSetNode->QueryIntAttribute("tileheight", &tileHeight); SDL_Texture *tex = SDL_CreateTextureFromSurface(gfx.getRenderer(), gfx.loadImage(ss.str())); if (tex == NULL) { return 1; } _tileSets.push_back(TileSet(tex, firstGid, columns, tileCount / columns, tileWidth, tileHeight)); tileSetNode = tileSetNode->NextSiblingElement("tileset"); } return 0; }
void Game::newGame( unsigned int w, unsigned int h ) { if(m_tilemap) { delete m_tilemap; } m_tilemap = new TileMap(TileSet("data/tileset.ini"), sf::Vector2u(w, h)); m_tilemap->generate(); m_weather=new Weather(RAINY,"data/ani/rain.ani"); m_incidencePoint=0; m_home.load("data/buildings/home.bld"); m_home.setPosition(w/2, h/2); m_buildings.push_back(m_home); qtyWood = 10; qtyFood = 10; qtyStone = 10; m_daysCount = 0; m_tilemap->freePlace(m_home.getPosition()); this->addEntity( new Gatherer(ALLY_CITIZEN, this)); this->addEntity( new Hunter(HUNTER, this)); this->addEntity( new Lumberjack(ALLY_CITIZEN, this)); this->addEntity( new Pickman(ALLY_CITIZEN, this)); for(int i(0) ; i < 10 ; ++i) { this->addEntity( new EnemyCitizen(ENEMY_CITIZEN, this)); this->addEntity( new PeacefulAnimal(PEACEFUL_ANIMAL, this)); this->addEntity( new WildAnimal(WILD_ANIMAL, this)); } //(m_tilemap->getTileSet())->TEST(); }
//______________________________________________ void ShadowHelper::reset( void ) { #if OXYGEN_HAVE_X11 if( _helper.isX11() ) { // round pixmaps foreach( const quint32& value, _pixmaps ) xcb_free_pixmap( _helper.connection(), value ); foreach( const quint32& value, _dockPixmaps ) xcb_free_pixmap( _helper.connection(), value ); } #endif _pixmaps.clear(); _dockPixmaps.clear(); _tiles = TileSet(); _dockTiles = TileSet(); // reset size _size = 0; } //_______________________________________________________ bool ShadowHelper::registerWidget( QWidget* widget, bool force ) { // make sure widget is not already registered if( _widgets.contains( widget ) ) return false; // check if widget qualifies