Jump to content
  • Advertisement
Sign in to follow this  
  • entries
  • comments
  • views

The MapManager

Sign in to follow this  


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:


I hope you had an interesting read smile.png
Sign in to follow this  


Recommended Comments

There are no comments to display.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!