Jump to content
  • Advertisement
  • entries
  • comments
  • views

[Development] Hooded Development #2

Sign in to follow this  


Hello all! Since my last hooded development post I have succeeded in loading a map from a file! Here's how I did it:

#pragma once
class Map
Map(std::string MapFileName);
const TileType& GetTile(int PosX, int PosY);
const std::vector>& GetWholeMap();
int MapSizeX;
int MapSizeY;
std::vector> MapVector;
std::ifstream MapFile;


#include "StdAfx.h"
#include "Map.h"

Map::Map(std::string MapFileName)
if (MapFile.is_open())
MapFile >> MapSizeX >> MapSizeY;
for (int index = 0; index < MapSizeX; ++index)
int LoadPositionX = 0;
int LoadPositionY = 0;
while (!MapFile.eof())
MapFile >> MapVector[LoadPositionX][LoadPositionY];
if (LoadPositionX >= MapSizeX)
LoadPositionX = 0;
std::cout << "Could Not Load Map File:" << MapFileName << std::endl;


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 4
1 1 1 1 1 1 1 1
4 5 2 3 5 5 7 3
8 5 6 1 5 7 2 9
1 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?
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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!