Handmade Hero»Forums»Code
Tilemap Exit Pointer List
Since we are using four sided Tilemaps where each sides may or may not have exits, can we use a struct that has a Pointer to the next tile? We would have a struct ExitTilemap:

1
2
3
4
5
struct ExitTilemap
{
    Tilemap* PointerToTilemap; //The new PlayerTileX and PlayerTileY can be computed easily using current player location.
    int32 Position; //Where on the row or coloumn the exit is. Won't be necessary if we assign a unique ID to these tiles.
}


Four of these will sit inside each tile_map struct, one for each direction.
Andrew Chronister
194 posts / 2 projects
Developer, administrator, and style wrangler
Tilemap Exit Pointer List
I'm not sure how Casey plans to handle "Sparseness" with Tilemaps, but this seems like one way you could potentially do that. In fact, it seems rather inevitable that the final solution will have pointers to tilemaps involved somewhere.
Tilemap Exit Pointer List
  1. create an enum for the tilevalues and one for tiledirection
    1
    2
    enum class TileName {OPEN, WALL, EXIT};
    enum class TileDirection{ NORTH, EAST, WEST, SOUTH };
    

    Here EXIT would be 2. So whereever on the edges you want an exit, place it there.
    example row: {1, 1, 1, 1, 1, 1, 1, 1, 2/*exit*/, 1, 1, 1, 1, 1, 1, 1, 1},
  2. add 4 of the struct exit_tiles:
    1
    2
    3
    4
    5
     struct exit_tile
    {
    	tile_map *PointerToConnectedTileMap;
    	TileDirection EntryDirection; //entry direction for new tilemap
    };
    

    in tile_map struct.

  3. Enter where the exit tiles are:
    1
    2
    TileMaps[0][0].ExitTiles[(uint32)TileDirection::EAST] = { &TileMaps[1][0], TileDirection::WEST };
    //The EAST wall of tile at TileMaps[0][0]has an exit. It points to TileMaps[1][0] and will put the player in the WEST wall of the new tilemap
    


  4. When checking if the tilemappointisempty(for collision detection), if the value of tilemap that the player is standing on is TileName::EXIT, it means that the player is standing on an exit and therefore must.
    Compute the new PlayerX and PlayerY using the EntryDirection member of the exit_tiles struct and point the CurrentTile to PointerToConnectedTileMap

  5. Note: Remember to store the CurrentTileMap in game_memory(Memory) so that it is not reset every tick.