It is currently Wed Jun 19, 2013 5:44 am

All times are UTC + 1 hour




Post new topic Reply to topic  [ 9 posts ] 
Author Message
 Post subject: Game & Map Data
PostPosted: Wed Aug 03, 2011 8:44 pm 
Offline
New User
New User

Joined: Wed Apr 20, 2011 11:33 pm
Posts: 9
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.


Top
 Profile  
 
 Post subject: Re: Game & Map Data
PostPosted: Wed Aug 03, 2011 8:59 pm 
Offline
User
User
User avatar

Joined: Sat Jul 23, 2011 1:13 am
Posts: 61
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:
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:
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.

_________________
PB 4.6b3 - Win7 32


Top
 Profile  
 
 Post subject: Re: Game & Map Data
PostPosted: Wed Aug 03, 2011 9:16 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Thu Jan 10, 2008 1:30 pm
Posts: 720
Location: Germany, Glienicke
I would save the map binary.
Some like:
Save:
Code:
For Y = 0 To Height
  For X = 0 To Width
    WriteData(File, @Map(X,Y), SizeOf(MapFieldStructure))
  Next
Next

Load:
Code:
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.

_________________
Image


Top
 Profile  
 
 Post subject: Re: Game & Map Data
PostPosted: Wed Aug 03, 2011 9:21 pm 
Offline
New User
New User

Joined: Wed Apr 20, 2011 11:33 pm
Posts: 9
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.


Top
 Profile  
 
 Post subject: Re: Game & Map Data
PostPosted: Thu Aug 04, 2011 12:09 am 
Offline
User
User
User avatar

Joined: Sat Jul 23, 2011 1:13 am
Posts: 61
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.

_________________
PB 4.6b3 - Win7 32


Top
 Profile  
 
 Post subject: Re: Game & Map Data
PostPosted: Thu Aug 04, 2011 12:18 am 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Sun Feb 12, 2006 10:06 pm
Posts: 526
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)

_________________
there is no sig, only zuul (and the following disclaimer)

WARNING: may be talking out of his hat


Top
 Profile  
 
 Post subject: Re: Game & Map Data
PostPosted: Thu Aug 04, 2011 12:49 am 
Offline
Addict
Addict
User avatar

Joined: Sun Apr 27, 2003 8:12 am
Posts: 1624
Location: USA
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:
  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. ;)

_________________
AMD 64 4000+ / 1GB PC2700 / WIN XP Home SP3 / Nvidia GT220 x16 512MB / M-Audio Revolution 5.1
Macbook Air 11.6" - 2010 / OS X 10.8

http://www.posemotion.com
http://www.flashpulse.com


Top
 Profile  
 
 Post subject: Re: Game & Map Data
PostPosted: Thu Aug 04, 2011 3:16 am 
Offline
Addict
Addict
User avatar

Joined: Tue Dec 23, 2003 3:54 am
Posts: 937
Location: New York
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.


Top
 Profile  
 
 Post subject: Re: Game & Map Data
PostPosted: Fri Sep 02, 2011 5:36 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Tue Aug 30, 2011 1:31 pm
Posts: 143
Location: Athens - Greece
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.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 9 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye