0
\$\begingroup\$

I'm thinking of a way to implement a large 2d map which can be easy to handle a certain area of the map to update. I've seen many 2d map using double array like int[][] gameMap = { {#,#,#,#,#}, {#,o,o,o,#}, {#,o,o,o,#}, {#,#,#,#,#} };

However editing (fixing) the map by hand would be troublesome when it gets for example 1000*1000.

so what would be a good way to do so? I heard FF14 has a map uses grid to organize each small area.

\$\endgroup\$
0

3 Answers 3

2
\$\begingroup\$

height map can be the solution? A big b/w image to manipulate the map heights easly wilth an image editor (gimp?). A (selfmade) tool that transform a B/W image (i've done one in c#) into a matrix of floats and save/load it to file concerning your needs.

If you need a memory buffer to keep a small part of your big file map , you can consider an aproach like this :

Paginig file map

It's a sequenzial file that rappresent your (virtual) space. From the x,y you are interested in , you calculate the page number that rappresent a portion of your map that you load in memory. You can implement also a cache , keeping the last pages accessed in memory.

\$\endgroup\$
1
  • \$\begingroup\$ This seems interesting. One thing came up to mind now is that it would be easy to have gameMap which holds small game maps. Something like bigMap = { {A}, {B}, {C}, {D} }where each holds data like "gameMap". so it would be a double array of int[][]. \$\endgroup\$
    – neko
    Mar 6, 2015 at 16:09
1
\$\begingroup\$

You can use an image.

Each pixel will be a tile and each 32bit color will encode several values like alpha=0 means impassible. Then you can use any image editor that allows you to save in a lossless format and choose the exact color values.

\$\endgroup\$
1
\$\begingroup\$

Use tile editor to create the map. Normally those allow you to export the map in some format. Then create map loader for that map, that reads the exported file and create object from it, to your game.

If you have to use ascii, split those to sections so that "first town" would be saved to txt file "firstTown.txt" and that would contain the number-to-tile thingie. Then just load whatever file you need and consume it.

Examplefile.txt

1,1,1,1,1
1,2,2,2,1
1,2,3,2,1
1,2,3,2,1
1,2,3,2,1

This is example structure, that could be loaded from file. Layer1 is the base tile and layer2 would be trees, rocks and other stuff that should be drawn on top.

int[,] layer1 = new int[5,5]{
    {1,1,1,1,1},
    {1,2,2,2,1},
    {1,2,3,2,1},
    {1,2,3,2,1},
    {1,2,3,2,1}
}
int[,] layer2 = new int[5,5]{
    {0,0,0,0,0},
    {0,0,4,0,0},
    {0,4,0,0,0},
    {0,0,0,0,0},
    {0,4,0,0,0}
}

So, don't hardcode that map to your source files, edit map with editor, load it, make runtime changes if necessary. Actual tiles could be saved to "two dimensional array" that is int[,] and it could contain number that is mapped to certain tile image. For example number 1 could be grass and 1337 could be tiny rock.


Tiled ( IMHO the best too for this job)

Community wiki answer - List of tools for mapping

\$\endgroup\$
2
  • \$\begingroup\$ This may be used when 2.5D is implemented. I'm not thinking of doing so but I appriciate it. \$\endgroup\$
    – neko
    Mar 6, 2015 at 16:13
  • \$\begingroup\$ What makes you think so? This is quite standard way to handling 2d maps. Just to clarify it, int[][] makes array of arrays, where as int[,] makes 2 dimensional array. 2D has two axis, so two dimensional array is definitely the way to go. When using that, you can just arrayName[x,y] to get the tile info. As for Tiled, thats perfect for anygame, that has tiles in some way. Projection of the world (2.5d vs 2d ) is just matter of camera rotation ( simplified). \$\endgroup\$
    – Katu
    Mar 6, 2015 at 17:04

Not the answer you're looking for? Browse other questions tagged .