Results 1 to 4 of 4

Thread: Simple Map Import

  1. #1
    Knight
    Join Date
    Nov 2006
    Location
    Oregon
    Posts
    99

    Default Simple Map Import

    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!

  2. #2
    Administrator Seth's Avatar
    Join Date
    Jul 2002
    Location
    Japan
    Posts
    5,377

    Default

    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:

    Code:
    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!
    Seth A. Robinson
    Robinson Technologies

  3. #3
    Knight
    Join Date
    Nov 2006
    Location
    Oregon
    Posts
    99

    Default

    Okay what about setting what layer it's in? (Or maybe that's tilepic priority or something, can't remember)

  4. #4
    Administrator Seth's Avatar
    Join Date
    Jul 2002
    Location
    Japan
    Posts
    5,377

    Default

    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:

    Code:
    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);
    Seth A. Robinson
    Robinson Technologies

Similar Threads

  1. Simple question about CL_Texture and CL_TextureGroup
    By Flav in forum Official ClanLib SDK Forums
    Replies: 6
    Last Post: 08-07-2009, 09:51 AM
  2. Simple Path Movement
    By Pleng in forum Novashell Game Creation System
    Replies: 11
    Last Post: 03-22-2008, 11:30 AM
  3. Simple Animation
    By ares in forum Official ClanLib SDK Forums
    Replies: 1
    Last Post: 02-27-2008, 05:20 AM
  4. simple ClanLib example problem - segfault
    By phx_one in forum Official ClanLib SDK Forums
    Replies: 3
    Last Post: 02-17-2008, 12:54 AM
  5. Simple app won't compile when linked with clanlib
    By mmiikkee12 in forum Official ClanLib SDK Forums
    Replies: 4
    Last Post: 07-17-2007, 02:41 PM

Bookmarks

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •