Grid-based Game Design

Started by
4 comments, last by MSW 15 years, 5 months ago
I've had an idea of a grid-based strategy game running around in my head, but I've run across a few problems concerning the structure. Keep in mind that I'm using Blitzmax: Types = Classes, Extends = Inheritance, etc... The types (or classes, in c++ etc) that I currently have are TGrid -- The type to hold the array that represents the grid TGridEntity -- A base type for anything that'll go into the grid TUnit extends TGridEntity -- The basic unit type Should I have a global instance of TGrid, and then reference that in the TGridEntity functions? Should the array in TGrid hold all of the units, or should the Units know their respective positions in the grid, or both? Should I update the GridEntity's by adding them to a list and then looping through it, or by adding them to the TGrid array and looping through that? Also, since this will be a two-player game, should I add a player type that contains references to all of the player's units, or should the units contain a reference to the player? I'm really terrible at design and structure, I've discovered -- I always get stuck early on, and then get too discouraged to finish. I'll probably have some more questions later. Any help would be appreciated, thanks! If anything doesn't make sense, I'll be happy to clarify.
Advertisement
This forum (Game Design) concerns the type of design that enhances the player's experience in a game. Adding, removing, and balancing game features. That sort of thing. I think your concerns (program/data-structure design) would get better answers in the game programming forum.

I don't have any good advice to give you concerning your questions. I'm the type of programmer who only cares about the end result, and couldn't care less how many globals I have or how well structured my data is. I just get it done the easiest way it can be gotten done without hindering my future progress, then forget about it and move on to the next problem. Probably not the best advice to someone who actually does care about these things.
Ah, well if a moderator could move the topic, it'd be appreciated.

The problem with my bad structure is that it does keep me from progressing -- I end up having to hack on code to add features, which surely isn't how everyone does it. If I were to have a simple and functional structure, I feel that it'd be much easier to expand on the program from there.
The "correct" path is to design your game before you program it, so you won't need to hack new features into it.

But I'm also very guilty of building my game as I design it, and I've had to change some things around more than I care to admit. I don't think there's much people like us can do except build with the intention of expansion.

In other words, don't wall yourself in. Always leave room to grow. That sort of thing isn't usually a problem, unless you're saving stuff to files (ie, the size of a grid tile will change, invalidating all of your saved maps). If that's the case, the best solution I've found is to save a format version in your map, then skip over data that's missing. For example:
file.open("savefile.map");file.saveInt( 5 ); // save map versionfile.save( tile[x].A ); // A & B were always aroundfile.save( tile[x].B );file.save( tile[x].C ); // C is new in version 5file.close();.....file.open("loadfile.map");version = file.loadInt();if( version >= 0 ) file.load( tile[x].A );if( version >= 0 ) file.load( tile[x].B );if( version >= 5 ) file.load( tile[x].C ); // C will not be loaded in <=4 mapsfile.close();

This way, the tiles keep default data values for stuff that was later added. This system worked well enough for me that I coded it into my file class to happen automatically.
I'm not sure how useful this is to you, but it's always worth a read:

http://en.wikipedia.org/wiki/Design_Patterns
http://en.wikipedia.org/wiki/Design_pattern_(computer_science)
http://en.wikipedia.org/wiki/Architectural_pattern_(computer_science)


[Insert Witty Quote Here]
Some things will depend upon the type of game it is. The core structure of Sim City can be different than Diablo, which can be different than a 2D Metroid game.

Something like Sim City would prolly work better with every grid cell haveing a refrence to the structure within it...rather than haveing a linked list of structures pointing to grid locations.

While Diablo and Metroid would be better served with grid cells that only contain basic graphic and/or collision information; while the entities interact with each other through other processes.

In an fast action type game for example, haveing each grid hold a refrecne to a object as well as have each object holding a refrence to grid location introduces a lot of extra overhead. Just moveing across grid line means the objects grid refrence must be updated as well as the grid object refrence in both grid cells. Might not seem much for one object, but a dozen or so and it can start to take its toll.

But on a slower paced stratigy game like Sim City, when its time to update that commercial building zone it can drag things down if you need to search through several linked lists each populated with dozens of buildings just to find the structures that sit next to it on the grid.

This topic is closed to new replies.

Advertisement