Page 1 of 1

Game & Map Data

Posted: Wed Aug 03, 2011 8:44 pm
by OneHitWonder
Hi Everyone,

I am quite new to game programming so my questions may seem obvious to some.

I am currently making my own 2d tile based editor, what is the best way to store the map/level data would you simply keep it in a text file? Include it in the game source? Or some kind of separate file encryption?

Thanks in advance.

Re: Game & Map Data

Posted: Wed Aug 03, 2011 8:59 pm
by Derren
That depends.
I store my stuff in an external file, simply because I want to be able to edit everything with a text-editor or a special map editor. I also want to allow others to write their own map editors, if they wish.
An encryption is always addtional. First you need to decide how to store the data. Thus having said, I don't think an encryption is necessary. But that's just my opinion.

There are many ways to store your actual data in a file and it depends on the kinds of map you're intending to use.
If it's a static map with static objects a normal textfile with bytes or words is enough.
It looks kinda like this (you can actually see the map when you view it with a text-editor)

Code: Select all

XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
X    X             XXXXX     X
X                   XXX      X
X                    X       X
X                            X
X              ___           X
X    ______    XXX___  __O   X
X P  XXXXXX    XXXXXX  XXX   X
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
You see the X's are walls, ___ is kind of a plattform, P is the player and O is maybe the exit.

If the objects are not so static, you may need to use several bytes or words per object.
X0X0X5X0X0
X is again a wall and the number behind it indicates the damage (if you can destroy objects in the game for example). In the middle there's a block that's pretty damaged. One or two more shots/kicks/whatever and it may break.

Then you may have layers.
Like snow on a block or water.

You can do it like this.
X00X00X0SX0SX4SX00X00

Now you see there are normal walls (X00) and snow covered walls (X0S) and damaged snow covered walls (X4S).
The problem with this is, when you want to add a new layer later, you'll have to rewrite the loading and saving functions.

Or you can do it like this. A new block for each layer.

Code: Select all

XXXXXXX
000SSS0
00000040
Or you can use a Database.
Or you can use XML.

It really depends on the type of game and the type of map.

Re: Game & Map Data

Posted: Wed Aug 03, 2011 9:16 pm
by STARGĂ…TE
I would save the map binary.
Some like:
Save:

Code: Select all

For Y = 0 To Height
  For X = 0 To Width
    WriteData(File, @Map(X,Y), SizeOf(MapFieldStructure))
  Next
Next
Load:

Code: Select all

For Y = 0 To Height
  For X = 0 To Width
    ReadData(File, @Map(X,Y), SizeOf(MapFieldStructure))
  Next
Next
This is simple and requires no parsing of the file.

Re: Game & Map Data

Posted: Wed Aug 03, 2011 9:21 pm
by OneHitWonder
I appreciate your quick reply and detailed answer. I am not looking for people to be able to edit these maps as this will eventually be a multi player game. So ideally I want to keep this information hidden from the player.

My map edtior uses 32*32 tiles so my tiles are numbered 0,0 would be top left while 24,32 being bottom right. It loads the tileset giving each 32*32 tile a unique number from 1 to how many tiles are in the tileset.

Hopefully you get the picture of how it works and what the data output from the editor is, I just need a good way to keep this from the player.

Thanks.

Re: Game & Map Data

Posted: Thu Aug 04, 2011 12:09 am
by Derren
Cool, Stargate.
That's the easiest way.

@OneHitWonder: You can adapt Stargate's code that it writes the data in a allocated buffer first and then use XOr or any other encryption method, before saving the data to a file.

Re: Game & Map Data

Posted: Thu Aug 04, 2011 12:18 am
by citystate
IncludeBinary might be what you're looking for - it will keep your data (however you decide to encode it) as part of the compiled exe.
The main drawbacks to this method are:
  • it increases the size of your file
  • any changes/updates will require a recompilation of the source
  • by including it with the exe, enterprizing hackers can access your gamedata (more difficult than an external file, but still could be an issue)

Re: Game & Map Data

Posted: Thu Aug 04, 2011 12:49 am
by J. Baker
citystate wrote:IncludeBinary might be what you're looking for - it will keep your data (however you decide to encode it) as part of the compiled exe.
The main drawbacks to this method are:
  • it increases the size of your file
  • any changes/updates will require a recompilation of the source
  • by including it with the exe, enterprizing hackers can access your gamedata (more difficult than an external file, but still could be an issue)

Code: Select all

  Hack = 0
  AnyThingIsPossible = 1
  Intelligence = 0
  Time = 0
  
   Debug Hack
  
 Repeat
  
   Intelligence +1
   Time +1
  
  If Intelligence +1 And Time +1
    Hack = AnyThingIsPossible
  EndIf
  
   Debug Hack
  
 ForEver
I would include it in the executable as citystate mentioned as the download size is the same anyway. ;)

Re: Game & Map Data

Posted: Thu Aug 04, 2011 3:16 am
by kenmo
There are many, many ways to store game data. If you are just starting to make tile-based games, you should try a text-based format like Derren suggested. That's what I first used, and many other people. It's probably the quickest to get going, and the easiest to visually edit.

But as your games get bigger you will find that text files are much bigger and more bloated than they need to be, and you'll probably want to try out binary data formats like Stargate said. The catch is, you can't edit the files in a text editor, you will probably need to write your own level editor (which can be fun actually).

Encryption, compression, and inclusion in your executable are all valid points to consider down the line too.

For example, I am working on a game now, and the game data is stored in a big XML file. It is read from as an external file at run-time so I don't need to recompile for every game change. But when I want to release a version, I change a code constant, which will include a compressed (~10% size) copy of the XML file in the executable, and load from there.

I'm not worried about the user getting the data, I just want to keep the game package compact and neat.

Re: Game & Map Data

Posted: Fri Sep 02, 2011 5:36 pm
by takis76
Hello my friends I am new here,

I have one idea about this , I am creating and one game and I have my levels be hidden or not easy editable with anyone.
My idea is , to write the data as text , to able to see it easy with the eye , but you can put it in one zip file and lock the zip file with password.

I don't know if this language support load data or other files from zipped files or able to put some file in the datafile or packet .zip file and add password.

So everytime you want to make change with your level editor and is not accessible by cheaters , for example there is a locked door in your rpg and player is very lazy to find the key or solve some puzzle , just deletes the door from the square in the map and pass the door.
But you cant have access to the level , because is in the locked zip file and the level file don't have name as level at all so the cheater don't know what to search and can't unzip the file even with password unlocker , because with brute force hacking needs 20 years to unlock the loooooooooooong password from your zip file :P

I don't know if this language have packet or zip commands to do this.