Terrain/Tileset representation
I've been thinking about how to represent the terrain in my maps. So far I just have each tile store a pointer to its terrain type, which keeps track of whether movement is allowed on it and is used to map to a sprite. I'm thinking I might want something more robust, especially for saving and reloading maps without reloading the entire tile set.
From what I can tell, most people represent their tile sets with an array and have each map tile store an index instead of a pointer. Where exactly is this vector stored? Is it just global? Also, are there ways to decide what index a terrain gets beyond what order it got loaded in from whatever data file I'm using? That is, what if I change the order the terrain types are defined in my data files, then load a previously saved game?
The answer depends on what programming language and the specific representation you are using. What I have done is to use a numeric coding system instead of a raw index. For example, 0=water, 10=normal, 20=rough, 30=ice, then I use the units digit (0-9) to represent the depth or roughness, which also helps to select the icon.
You'll want to finalize your terrain representation early in the project, so I wouldn't worry about "old" game saves. Though you could store the version number in your save file, and run a convert routine if you find an out-dated version and format.
You'll want to finalize your terrain representation early in the project, so I wouldn't worry about "old" game saves. Though you could store the version number in your save file, and run a convert routine if you find an out-dated version and format.
Well, I'm using C++, and I plan to have my terrain defined in a text file that the game reads when starting up (actually, a table in a Lua file). I want it to be relatively easy for myself and others to add new terrain types to the game. I'm going to also have scripts that will generate my maps (the game is basically a roguelike) so I'll also want some way of referring to terrain by name as well as the indices/pointers/whatever my actual maps will use.
Each kind of terrain so far is represented by a Terrain object. Right now a Terrain defines if a tile blocks movement, sight, or projectiles. I also have a map between Terrain pointers and sprites for my graphics engine; I'm trying to separate my game and graphics logic to possibly make it easier to switch graphics/GUI engines.
I also want my terrain types to eventually be linked with scripts that run when something affects a tile with that terrain, which would usually be a character walking onto that tile or "using" it. This would be for things like lava that burns characters and doors that open and close. It would also be neat if a tile with a certain terrain type could affect adjacent tiles, like a "burning grass" tile turning all adjacent "grass" tiles into more burning tiles. I still haven't figured out how this would work exactly, especially for terrain types that would need some kind of state (like the aforementioned doors).
Each kind of terrain so far is represented by a Terrain object. Right now a Terrain defines if a tile blocks movement, sight, or projectiles. I also have a map between Terrain pointers and sprites for my graphics engine; I'm trying to separate my game and graphics logic to possibly make it easier to switch graphics/GUI engines.
I also want my terrain types to eventually be linked with scripts that run when something affects a tile with that terrain, which would usually be a character walking onto that tile or "using" it. This would be for things like lava that burns characters and doors that open and close. It would also be neat if a tile with a certain terrain type could affect adjacent tiles, like a "burning grass" tile turning all adjacent "grass" tiles into more burning tiles. I still haven't figured out how this would work exactly, especially for terrain types that would need some kind of state (like the aforementioned doors).
Quote:Original post by Guy Meh
Well, I'm using C++, and I plan to have my terrain defined in a text file that the game reads when starting up (actually, a table in a Lua file). I want it to be relatively easy for myself and others to add new terrain types to the game. I'm going to also have scripts that will generate my maps (the game is basically a roguelike) so I'll also want some way of referring to terrain by name as well as the indices/pointers/whatever my actual maps will use.
Each kind of terrain so far is represented by a Terrain object. Right now a Terrain defines if a tile blocks movement, sight, or projectiles. I also have a map between Terrain pointers and sprites for my graphics engine; I'm trying to separate my game and graphics logic to possibly make it easier to switch graphics/GUI engines.
I also want my terrain types to eventually be linked with scripts that run when something affects a tile with that terrain, which would usually be a character walking onto that tile or "using" it. This would be for things like lava that burns characters and doors that open and close. It would also be neat if a tile with a certain terrain type could affect adjacent tiles, like a "burning grass" tile turning all adjacent "grass" tiles into more burning tiles. I still haven't figured out how this would work exactly, especially for terrain types that would need some kind of state (like the aforementioned doors).
You would need some kind of behavior scripting to do the transitions between different tiles (scripts linked to a particular tile type and an effect type on that tile which has the power to spread effects and chgange its tiletype and those of surrounding tiles. You need logic to do the 'expected' transitions like fire spreading thru dry grass and making adjacent trees catch fire (which then burn down to stups...) but fire doesnt spread into water.
So the 'fire entity' is independant of the terrain type but each tile could contain a list of one or more effect entities in its location (and the combinations of different ones ontop of the tile flavors might greatly expand the scenic situations.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement