• entries
33
37
• views
38381

[Development] Hooded Development #2

Followers 0

589 views

Hello all! Since my last hooded development post I have succeeded in loading a map from a file! Here's how I did it:
Map.h:
#pragma onceclass Map{public:Map(std::string MapFileName);~Map(void);const TileType& GetTile(int PosX, int PosY);const std::vector>& GetWholeMap();private:int MapSizeX;int MapSizeY;std::vector> MapVector;std::ifstream MapFile;};
Map.cpp:
#include "StdAfx.h"#include "Map.h"Map::Map(std::string MapFileName){MapFile.open(MapFileName);if (MapFile.is_open()){ MapFile >> MapSizeX >> MapSizeY; MapVector.resize(MapSizeX); for (int index = 0; index < MapSizeX; ++index) { MapVector[index].resize(MapSizeY); } int LoadPositionX = 0; int LoadPositionY = 0; while (!MapFile.eof()) { MapFile >> MapVector[LoadPositionX][LoadPositionY]; ++LoadPositionX; if (LoadPositionX >= MapSizeX) { LoadPositionX = 0; ++LoadPositionY; } }}else{ std::cout << "Could Not Load Map File:" << MapFileName << std::endl;}}Map::~Map(void){}const TileType& Map::GetTile(int PosX, int PosY){return (TileType)MapVector[PosX][PosY];}const std::vector>& Map::GetWholeMap(){return MapVector;}

So essentially, I have my map.txt files structured as such:
8 41 1 1 1 1 1 1 14 5 2 3 5 5 7 38 5 6 1 5 7 2 91 1 1 1 1 1 1 1
The top two numbers are the X size of the file (Number of Columns) and the Y size of the file (Number of rows). Then, the numbers under it specify certain block types! Currently you can request a certain tile in my std::vector of tiles, or you can get the whole map! What do you think of this, seasoned developers? Is it smart, or is there anything I'm forgetting / not planning for?

0
Followers 0

There are no comments to display.

Create an account

Register a new account