The MapManager

posted in Arhim's Journal
Published July 19, 2013
Advertisement
Hello GameDev

Arhim here with the third entry for this journal. Today I will be writing about the work done on MapManager.

The MapManager is a class that is responsible for loading, saving and drawing the Maps. As an addition we will make a MapTile class that will store tile data (like type, sprites, defence strength...).

Let's start off with the MapTile:class MapTile{ public: MapTile(); ~MapTile(); void setType(std::string); std::string type; std::string preview; // will represent the tile in the editor std::vector sprites;};
This should be useful for now. Next we will define the MapManager: class MapManager { public: MapManager(); ~MapManager(); void loadMapFromFile(std::string FILE);// void writeMapToFile(std::string FILE); void setTextureForTiles(); void update(double k); void draw(); private: MapTile data[512][512]; std::string texData[512][512]; int n,m; int tileWidth, tileHeight; };
The setTextureForTiles function will, for each MapTile, read its type and assign a texture from the MapTiles sprite vector.void MapManager::loadMapFromFile(std::string FILE){ ConfigManager config; config.parseFile(FILE); tileWidth = config.getInt("SETTINGS","tileWidth"); tileHeight = config.getInt("SETTINGS","tileHeight"); n = config.getInt("SETTINGS","n"); m = config.getInt("SETTINGS","m"); for (int i=0; i[j].setType(config.getString(toString(i) + "," + toString(j),"type")); } } setTextureForTiles();}void MapManager::draw(){ glMatrixMode(GL_MODELVIEW); glEnable(GL_TEXTURE_2D); for (int i=0; imyAssetManager->useTexture(texData[j]); gl::drawTexQuad(0.0,0.0,tileWidth,tileHeight); glPopMatrix(); } }}void MapManager::setTextureForTiles(){ for (int i=0; i[j].type == "plains") { if (rand()%2==0) texData[j] = data[j].sprites[0]; } if (data[j].type == "water") { texData[j] = data[j].sprites[0]; } } } return;}
After adding everything to the main loop, this is what we come up with:

gallery_187477_664_64591.png


I hope you had an interesting read smile.png
0 likes 0 comments

Comments

Nobody has left a comment. You can be the first!
You must log in to join the conversation.
Don't have a GameDev.net account? Sign up!
Profile
Author
Advertisement
Advertisement