Game Levels

Community Forums/General Help/Game Levels

En929(Posted 2012) [#1]
I was curious, how do some of you do your levels when you're making a 2D game? Do you simply change your player's coordinates to a coordinate high (or lower) than the coordinate that the player is on, and their next level would be there? Do you delete everything and start fresh? or shift the level that your player is on to a very very very far away coordinate (which is impossible to reach) and move in the next level to the player's coordinate at the time?

Thanks


ima747(Posted 2012) [#2]
Generally level data is stored per level, so I would just load the level data for the level the player is on if I understand what you're asking... If you want to press multiple levels into a single load then I would still truncate the data into blocks for each level and then re-load the block appropriate for the level. Putting all the data into the system at once raises a lot of problems, location being the least of them. Assets typically change between levels so if it's all loaded at once you either need to load ALL your art assets at once, or find a way to stream them, both of which have issues (memory usage and complexity being the obvious ones respectively). Additionally most drawing systems are going to have to loop through all your data and determine what needs drawing, what is clipped, etc. and that adds tons of overhead if there's lots of extra stuff it has to look through that the user can't access yet...


D4NM4N(Posted 2012) [#3]
I use a "camera" system, which is basically a viewport that renders what in in it. This viewport moves over the level. The character is in the center of the viewport. (or more correctly the viewport is positioned to the character via a movement smoothing translation.) In this system the world stays at the -real coordinates, it is just the character and camera that move.

The other thing i do sometimes i create an offset position of everything in the world and "move" that instead, hence moving everything in the world around the character. The world object coordinates are still the same as above, but use virtual coordinates, with what constitutes as 0,0 or them being set by the "world position"



For data storage i agree with ima747 load per level. How you want to store it in RAM however you have LOTS of choice....
eg (some of my usuals, i sometimes use a mixture):

- A matrix array (or "multdimensional array") easy option, but inefficient on ram, suitable for tile-type levels),

- A "list" (or other array type) of "world objects" which are usually more efficient on ram because each block has it's own coords/data and only "exists" where needed, unlike the "wastage" you get with an array. (Slightly more complex as you need some object management code, but generally better and suitable for a tiled or non-tiled and more dynamic/complex and very large levels.).

-A combination of both, Eg. matrix for "normal tiles" with a list to store object for special tiles that do something Eg. a respawn point, tile animation data, tile sound effects, a monster etc.. (you can use the matrix coords to look up the objects that match them in the list)

- Databases & Files as RAM (v.slow, but good for some stuff like inventory, character stats, scores, savegames etc.. also, can be cached using above methods for speed / dynamic level load-in).

There are loads of options :/
Choosing one really depends on what kind of game you want to make and how complex the level data is. Best idea is stick a rough design down on paper (no need to be too detailed other than what the mechanics of the level are) and then post it in the programming forums and ask what the best data structures would be for that sort of level.

Last edited 2012


Hotshot2005(Posted 2012) [#4]
if you using for 2D Game level....why dont you used Mapping tools like this

http://tilemap.co.uk/mappy.php

?

Last edited 2012


Matty(Posted 2012) [#5]
Regardless of 2d or 3d I do much the same thing....


game flow:

initialise game stuff()

do the menu until the game is started

repeat these steps until game over:
load the next game level (first if new game)
do game loop
unload game environment

then go back to the menu....


Adam Novagen(Posted 2012) [#6]
Always always always start fresh. Keep your "building block" data - e.g. tiles, enemy/NPC sprites, etc - loaded in memory, but don't ever put every level of a game into memory from the start. General rule of programming is: if it's not doing anything, it shouldn't exist. If a player isn't in a particular level, then that level should - at most - exist purely as tile-map data or whatever method you use, but the actual level should not be built.


D4NM4N(Posted 2012) [#7]
Using a level editor you still need storage structures. Although a lot of editors come with example loaders as well as file format info, so i agree with hotshot, if it has such code available then it could be an excellent way to learn.


En929(Posted 2012) [#8]
I'd like to thank everyone here for the insight (and links). I was trying to figure out a more faster and effecient way of loading levels to save a bit of programming time. Thus, thanks for the advice and I'll take note of the things said here.


D4NM4N(Posted 2012) [#9]
One more thing if you find an editor you like with export code or file specs but it does not have anything fot blitz don't get put off, post them here i am sure we can help you convert the code easy enough.
It will be one more for the archives :)

Last edited 2012


En929(Posted 2012) [#10]
Ok, thanks D4NM4N.