PDA

View Full Version : Simple Map Import



Uhfgood
09-29-2009, 10:45 PM
I'm wondering if you could add a simple map import. I'm thinking a Tile-based map that has, width and height, tile indexes into a tile set (where the tile ids are the location in the tile set based on this y * width_of_map_in_tiles + x), and would also include the file name to the image so that you could bring the map and the tiles into a layer in Novashell. The map file to import would be a single text file, and the indexes (tile ids) would be comma delimited.

For example.

Map="simple map";
TileWidth="16";
TileHeight="16";
MapWidthInTiles="400";
MapHeightInTiles="225";
Tileset="c:\mapfolder\MyTileset.png";
Layer="1,3,213,4";

Obviously the Layer parameter would be a lot larger... You could sort of dictate the exact text format for the map so I could save maps this way (my maps at the moment are only 1 layer, so it only needs to do one layer at a time). So let's say that there were 20 tiles across in the tile set image. That 213 would translate into getting the location backwards... ie X = 213 % 20 = 13, Y = 213 / 20 = 10, so the position in the tile set image would be 13, 10. (And you can of course check this backwards... x = 13, y = 10, y * 20 + x or 10 * 20 + 13 = 200 + 13 or 213).

So you would know where in the tile set image to grab the image from... if tiles were 16x16, and 20 tiles wide that's 20 * 16 which is 320 pixels wide. So to get a tile at position 13,10 you would multiply by 16, so tile 13 is actually an x position of 208, and tile 10, would be position 160...

Anyways, like I said, you could pretty much come up with the exact format I would have to write out, then I could output a simple text version of a particular layer, and it would help me when porting my game over.

You probably won't do that, but maybe you could if I ask real nice, like Please and all... Please write a simple map layer import in novashell!

Seth
09-30-2009, 12:54 AM
Hey Uhf.

Hmm... sorry but you're stuck coding your own importer at the moment.. ;)

I think the best thing would be to get Novashell compiling on your computer (from the svn source) and then checking out the Dink map importer and modifying it or copying it to make your own importer. It's really pretty straightforward.

If you modify "GeneratorDink.cpp" or add your own generator, this is all it takes to add a tile:



TilePic *pTile = new TilePic;
CL_Vector2 vDestPosition = CL_Vector2(x*tileSize, y*tileSize); //or wheverer this tile should go on the map...

pTile->SetPos(vDestPosition);

pTile->m_resourceID = FileNameToID("theTile.bmp"); //the tile image that should be used for this tile
pTile->m_rectSrc = CL_Rect(0,0,64,64); //what part of the source tilebitmap should be used for the tile?

if (!GetHashedResourceManager->GetResourceByHashedID(pTile->m_resourceID))
{
throw CL_Error("Unable to locate tile filename");
}

//Actually add it to the active map
g_pMapManager->GetActiveMap()->AddTile(pTile);


So basically you just do that for each tile you want to add, and voilą, your map is imported!

Uhfgood
09-30-2009, 04:32 AM
Okay what about setting what layer it's in? (Or maybe that's tilepic priority or something, can't remember)

Seth
09-30-2009, 04:43 AM
Okay what about setting what layer it's in? (Or maybe that's tilepic priority or something, can't remember)

You should be looking at Tile.h for everything it offers (SetScale(), SetColor(), SetAlignment() etc). Here is how to set the layer:


int layerNum = 3;

//if you don't know the # id of a layer, do this to get it from a layer text name:
//int layerNum = g_pMapManager->GetActiveMap()->GetLayerManager().GetLayerIDByName("Entity");

//then set the layer like this:
pTilePic->SetLayer(layerNum);