Java-Gaming.org    
Featured games (91)
games approved by the League of Dukes
Games in Showcase (580)
games submitted by our members
Games in WIP (500)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Storing levels  (Read 1762 times)
0 Members and 1 Guest are viewing this topic.
Offline everbeard

Senior Newbie





« Posted 2013-03-20 21:25:47 »

Hi! I'm looking to make what's shaping up to be a rather complex Rogue-like game.

I was looking to see what the best way to store levels was. I don't feel like a txt file is the right way to go.

How do you fine folk store your levels for use in your games? (In case I'm missing something, I'm planning on using lwjgl.)

EDIT: For clarification, I just mean the best way to create and save a level to be read by the game while it's being played.
Offline opiop65

JGO Kernel


Medals: 124
Projects: 7
Exp: 3 years


Team Alluminum


« Reply #1 - Posted 2013-03-20 21:29:45 »

Honestly I just use .txt files, unless you're planning on actually releasing your game to the general public, I see no reason to do anything more complex. If you are going to release it, and are worried about modifying of the files, use a byte format maybe?

Offline everbeard

Senior Newbie





« Reply #2 - Posted 2013-03-20 21:36:35 »

Haha well the option of releasing this game would be nice, although it probably won't happen.

How is it done in games like VVVVVV or Super Meat Boy? That is one thing that's always plagued my thoughts.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline opiop65

JGO Kernel


Medals: 124
Projects: 7
Exp: 3 years


Team Alluminum


« Reply #3 - Posted 2013-03-20 21:44:01 »

Honestly, I have no idea. I have never actually played either game :/ I imagine they have their own file format though. I haven't dealt a lot with file systems besides .txt files, but I'd recommend googling about file formats that are compatible with Java!

Offline ctomni231

JGO Ninja


Medals: 71
Projects: 1
Exp: 7 years


Not a glitch. Just have a lil' pixelexia...


« Reply #4 - Posted 2013-03-20 23:37:12 »

There are 3 options, and really, there are only 3 options that cover how everyone deals with file storage.

1) Hard code it

Store all your level design and objects hardcoded within the game. It completely alienates a lot of users from modding your game and makes it a little more difficult to do a quick fix in your levels. But, hey... the people will have to crack your entire code base in order to crack the game.

Java has a special serialization method that allows you to save states of its classes. It is a compromise between this option and option 2.

2) Put the data in a text file

This method takes your game data and puts it into a text file. Keep in mind, the extension does not have to be .txt. You can name the extension whatever you want. Also, you do not have to store the data as UTF-8 characters. You can store the data as a mixture of bytes, chars, and longs. As long as you are able to read the data back into the game you are fine.

This covers a lot of ways to store data, and is by far the one used by most indie and development companies working on large games. It includes most scripting languages like Lua, JSON, and XML. It also includes just writing your data into a basic text files under .txt and picture files like jpeg and png. You can also use this method to store data into binary.

The most important aspect is that you are able to read the data in and out of any format you put in the text file.

3) Store it online

This is really an extension of Option 2. But there is a few tools like MySQL and data servers where you can store all your data online and have the clients read off the server data. Of course, your clients will be out of luck if your system goes down, but MMORPG's and other online gaming outlets all use this method of storing data.

Conclusion

Best way to handle it is possibly Option 2. It takes a little bit longer to write code that'll be able to allow for custom objects and level design in the game. In the end though, it makes it a lot easier to expand your game to make more levels and objects.

Offline iandioch

Senior Newbie


Medals: 1


Make bad games. Don't take life seriously. Turtles


« Reply #5 - Posted 2013-03-24 00:43:22 »

I've just always used txts when I didn't hard code my levels (now that i read this, perhaps I shouldn't be giving advice ^^)
Does it just not feel professional to use a text file? Or are you worried about security, and the user editing the level?

You approach the entrance to THE WILDS. A man wearing nothing but a hat greets you with an enthusiastic handshake.
Offline tyeeeee1
« Reply #6 - Posted 2013-03-24 01:10:32 »

I store my map as an image where each pixel corresponds to a tile. When I load the map I just load the pixel values into a 2D array and then render the map depending on the pixel values.
Offline TrinityGamer

Senior Newbie


Medals: 2



« Reply #7 - Posted 2013-07-08 08:51:20 »

There are 3 options, and really, there are only 3 options that cover how everyone deals with file storage.

1) Hard code it

Store all your level design and objects hardcoded within the game. It completely alienates a lot of users from modding your game and makes it a little more difficult to do a quick fix in your levels. But, hey... the people will have to crack your entire code base in order to crack the game.

Java has a special serialization method that allows you to save states of its classes. It is a compromise between this option and option 2.

2) Put the data in a text file

This method takes your game data and puts it into a text file. Keep in mind, the extension does not have to be .txt. You can name the extension whatever you want. Also, you do not have to store the data as UTF-8 characters. You can store the data as a mixture of bytes, chars, and longs. As long as you are able to read the data back into the game you are fine.

This covers a lot of ways to store data, and is by far the one used by most indie and development companies working on large games. It includes most scripting languages like Lua, JSON, and XML. It also includes just writing your data into a basic text files under .txt and picture files like jpeg and png. You can also use this method to store data into binary.

The most important aspect is that you are able to read the data in and out of any format you put in the text file.

3) Store it online

This is really an extension of Option 2. But there is a few tools like MySQL and data servers where you can store all your data online and have the clients read off the server data. Of course, your clients will be out of luck if your system goes down, but MMORPG's and other online gaming outlets all use this method of storing data.

Conclusion

Best way to handle it is possibly Option 2. It takes a little bit longer to write code that'll be able to allow for custom objects and level design in the game. In the end though, it makes it a lot easier to expand your game to make more levels and objects.

Thank you, thank you, thank you. this explanation just saved me so many questions (i had been told that serialization was the best way and the only option if i plan to allow players to play multi-player if they want, but this explanation contradicts that, and seems to actually explain it a bit more then others did.)
Offline jonjava
« Reply #8 - Posted 2013-07-08 17:53:35 »

"Text file" is very misleading. All a "Text file" is a File (and all a File is a collection of bytes) which bytes are ordered in a way (codec/protocol/charset) that is familiar with most text editing programs.

An mp3 music file is a text file if you open it with a text editor. But the bytes are ordered in a way that text files can't make sense of so you get a bunch of gibberish text.

The only reason you get a music player or a text editor opened up when you double-click/open a music or text file is because the suffic is either .mp3 or .txt - this suffix is only there to tell your Operating System which program (music player or text editor) it should try and open the file with (It essentially has nothing to do with the contents of the file).

Offline Jimmt
« League of Dukes »

JGO Kernel


Medals: 114
Projects: 4
Exp: 3 years



« Reply #9 - Posted 2013-07-09 15:06:19 »

Yes - technically all files are "text" files. Anything can be opened with Notepad. Why do you think this is? Because higher-level interpretations can always be translated down to "text".
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline heisenbergman

JGO Coder


Medals: 14
Projects: 1


L___ o_ G___ a__ P___


« Reply #10 - Posted 2013-07-10 06:05:07 »

I store my map as an image where each pixel corresponds to a tile. When I load the map I just load the pixel values into a 2D array and then render the map depending on the pixel values.

This. I do it exactly the same way in my game Smiley I find that doing it this way is easier because you're already seeing your map layout and it's easy to change things just by modifying a few pixels.

Offline HeroesGraveDev

JGO Kernel


Medals: 212
Projects: 11
Exp: 2 years


If it wasn't Awesome, it wasn't me.


« Reply #11 - Posted 2013-07-10 08:44:10 »

Yes - technically all files are "text" files. Anything can be opened with Notepad. Why do you think this is? Because higher-level interpretations can always be translated down to "text".

Technically all files are binary files. Pointing

Offline Jimmt
« League of Dukes »

JGO Kernel


Medals: 114
Projects: 4
Exp: 3 years



« Reply #12 - Posted 2013-07-10 09:15:38 »

Text as in characters Wink
Offline tdegroot96

Junior Member


Projects: 1



« Reply #13 - Posted 2013-07-10 10:26:53 »

You could gzip your objects.
It's a built-in feature.
Offline relminator
« Reply #14 - Posted 2013-07-10 11:05:26 »

I thought rougelikes generate their levels at runtime procedurally?
Online pjt33
« Reply #15 - Posted 2013-07-10 14:30:00 »

(i had been told that serialization was the best way and the only option if i plan to allow players to play multi-player if they want, but this explanation contradicts that, and seems to actually explain it a bit more then others did.)

"Serialisation" has a technical meaning in Java in terms of the java.io.Serializable interface, but it also has a more general meaning. ctomni231's comments are largely orthogonal to the question of serialisation. I would break it down instead as:

Top-level choice: build the levels with code or deserialise them from a string or byte[].

If you build them with code then making changes requires recompilation. I would say that this is rarely the correct option.

If you serialise and deserialise, you have two further choices to make: what format to use, and where to store the data. ctomni231's answer addresses where to store the data: in code (has the same downside of requiring recompilation, but Java4k developers tend to do this because it keeps things simple); in a file; in a database; or fetched across a network. (The latter options overlap).

tyeeeee1's answer addresses the serialisation format. The questions you have to ask when deciding on a format are 1) What do I need to store? 2) What might I need to store later? and 3) How am I going to edit the levels? If you just need to store a 2D grid and don't expect to add anything then (lossless - e.g. PNG) image files make convenient formats because you can edit them in any image editor and deserialise with javax.imageio.ImageIO. But you might want to represent a complex structure, in which case the choice is between using Java's serialisation (simple but brittle) or creating your own format (flexible, but requires investment of time in writing your level editor and debugging the custom serialisation/deserialisation).

One additional comment I will make is that if you do decide to create your own format, make sure that it has a version identifier at the start.
Offline sproingie
« Reply #16 - Posted 2013-07-10 19:32:16 »

I thought rougelikes generate their levels at runtime procedurally?


Nethack mostly does, but has several pre-made levels with a fixed map.  But even a procedural map is something you have to figure out how to save, since the random seed alone won't account for alterations afterward.


Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

xsi3rr4x (47 views)
2014-04-15 18:08:23

BurntPizza (43 views)
2014-04-15 03:46:01

UprightPath (59 views)
2014-04-14 17:39:50

UprightPath (41 views)
2014-04-14 17:35:47

Porlus (57 views)
2014-04-14 15:48:38

tom_mai78101 (80 views)
2014-04-10 04:04:31

BurntPizza (139 views)
2014-04-08 23:06:04

tom_mai78101 (239 views)
2014-04-05 13:34:39

trollwarrior1 (199 views)
2014-04-04 12:06:45

CJLetsGame (207 views)
2014-04-01 02:16:10
List of Learning Resources
by SHC
2014-04-18 03:17:39

List of Learning Resources
by Longarmx
2014-04-08 03:14:44

Good Examples
by matheus23
2014-04-05 13:51:37

Good Examples
by Grunnt
2014-04-03 15:48:46

Good Examples
by Grunnt
2014-04-03 15:48:37

Good Examples
by matheus23
2014-04-01 18:40:51

Good Examples
by matheus23
2014-04-01 18:40:34

Anonymous/Local/Inner class gotchas
by Roquen
2014-03-11 15:22:30
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!