Grid based map creation

I’m looking to create a grid based map. Ill use each grid space as a spot to place certain objects, but the character will be able to move freely. I was thinking I could just create an area 64x64 and use a 1x1 mesh in order to accomplish this? Or is there a faster way?

maybe this can help Draw Grid on Terrain - #12 by nehon

I’m more interested in the theory behind making that Terrain but that does help. My terrain will be completely flat as well

Do you need something like this?

The terrain and the grid don’t need to have any connection. The grid is a logical construct based on location on the terrain. So you don’t need a 1:1 equivalence of triangles on the terrain and grid tiles, a simple algorithm saying what position on the terrain would be what tile is enough.

Yeah something like what frozenshade has but I’m using jme because I want it to be 3d like harvest moon where you have the top down view but still 3d models

This is 3D, it was made in JME, but because it was my first experience with 3D graphics at all, the quality is poor.
The idea is to add an terrain grid model for every map grid except for the flat surface, which is generated as a custom geometry. Things like trees, buildings etc are placed using data from the map too.

seen a lot worse, don’t be hard on yourself

I made ground models on my own, it was my first (and last) experience with Blender. And it wasn’t made to be nice, the priority was to get familiar with 3D and JME. Reworking existing game with pure 2D map was imo the best way.

Anyway, back to the topic. The same technique I’m using on my current project.
Look at the screens (ignore the red marking):

Here we have pure grid approach. The scene is generated dynamically at the loading stage. I just check every map square, load necessary models, rotate them and place on the scene graph (the simplified version). In my solution, where every map square is just an element of the corridor, I have ‘on-wall-objects’. Each grid contains four of them (for N, S, W and E directions). The approach is similar to the rest: check what I have on the ‘direction’, load a model, place it on the graph.

3 Likes

Did you use some kind of map editor for this? I think the approach you’re taking is what I’m going to try. I could make a grid of empty spaces, give the spaces an index like 1 for tree 2 for water, and then load and change the spaces as needed.

In PGR Online (the game with green map) I used mspaint (!!!) as map editor. Yes the map is loaded from a 256 color bitmap with fixed dimensions where water, land, trees and others are distinguished by colors. All other things like buildings, farmlands etc are taken from database (empty game server does not have any buildings).

Because the Dungeon Game map is much more complex than in PGR, I made an editor.
In the DG you can see an standard Java window with editor. The editor is integrated with main game code and most of it’s code can be removed by conditional compilation, like this:

``````public static final boolean EDITOR_MODE = true;

....

if (EDITOR_MODE)
{
//the code for design mode
}
else
{
//Do nothing or throw some nice Exception.
}``````

…made me feel stupid for all of the 2D map editors I’ve custom-rolled in my lifetime that could have easily been replaced by this method in 30 seconds.

1 Like

I was using text editor to create levels about 20 years ago, when I was writing on Atari 800XL. Every level for some 2D tile-based games I did this way. Even now you can do the same on … strings.
But mspaint beats all these solutions

I’ve used text editors and especially ‘strings in code’ as well as ‘2D arrays of char’ in code, etc… I have also used photoshop before… and various other 2D sprite editors (For level editing) and so back in the day before I knew what a Photoshop was.

…but there is a certain elegance to the spreadsheet approach that I find appealing. Not the least of which is being able to store a lot more information in a cell. When a paint app gets unwieldy, a spreadsheet can keep going for a while longer.

Not sure exactly what you’re trying to accomplish here, but I just use a matrix of objects to define my grid based map.

the object might be something like:

``````class GridSpace {
public final int x;
public final int y;

public GridSpace(final int x, final int y) {
this.x = x;
this.y = y;
}
}
``````

then the matrix:

``````GridSpace[][] nodes = new GridSpace[64][64];

for (int x = 0; x < nodes.length; x++) {
for (int y = 0; y < nodes[0].length; y++) {
nodes[x][y] = new GridSpace(x, y);
}
}
``````

Of course you’d want to store whatever information in your grid object that you need for your node. The type of terrain, if and what unit(s) are in the node, etcetera…

In addition to that you could treat your matrix like an image. For instance you could use a perlin noise algorithm to populate terrain types for your grid.

Right, matrices of objects are good to keep the map in memory, after loading. They are able to keep the map and temporary game state informations as well. It’s an natural solution for 2D games. But we are talking about an input, something you need to create and load into your game. According to complexity of the data you need to load, you can use various tools to create that input data. Text/image editors, spreadsheets or custom editors - it is up to you to choose the best solution.
My advice is to start with the simplest one, just to have something you can use fast at the beginning.

Right on, wasn’t entirely clear on what was being discussed here. Interesting to hear that you had worked with the Atari 800XL, always liked Atari’s stuff myself, had both an Atari Jaguar and Lynx growing up.

For p0cm0n I used a spreadsheet to quickly create grid (you can fill it manually, use function to fill the grid you can use layer,…). But to I didn’t have time to create a loader (I know reading csv, … it’s easy, but I’d got 48H to make a game), so I copied /pasted grib into a java source file. The source of game is available on github.

Well, that’s also the nice thing about csv from a spreadsheet… even without a loader it’s a one minute job with an editor macro to covert it to code.

I really like the idea of loading the map from a spreadsheet. For now I’ll just use colors to represent what I want but when I get the models built I’ll switch to them. I now need to try to create an algorithm as suggested above to set my grid to the location of my platform