views:

196

answers:

4

The title says it all... The game will be written in C++

Programming:

enemies.puch_back(new DefaultEnemy(200, 300, 3, 5));
enemies.puch_back(new DefaultEnemy(500, 400, 4, 5));
enemies.puch_back(new DefaultEnemy(300, 420, 3, 15));
enemies.at(2).createAward(new Key(4), "pling.wav");

Or Interpret them from a file like this:

DefaultEnemy 200 300 3 5
DefaultEnemy 500 400 4 5
DefaultEnemy 300 420 3 15
CreateAward 2 "pling.wav" Key 4

Program it would be more easy and people can't (without speaking of hacking) edit your levels. But it maybe a bit rubbish to program it all? Are there other reasons to choose for programming or interpreting?

How about memory-management (if I should go for interpreting)?

How to delete the (game)objects when the level unloads?
I found it. Sorry.

Thanks

+6  A: 

First variant is equivalent to hardcoding game resources. This is absolutely bad and is suitable only for debugging.

Every games store their resources in external files - xml, archived packages and parse and load them during runtime.

Therefore, modern game engines almost every time have their set of tools which is bundled with it.

Deleting game resources is also a vast question - it depends. Depends on your objects' lifetime management and on that fact if you need to unpack your data into temporal files.

Kotti
Your statements are way too general and provide no evidence to back them up.
Ben Voigt
@Ben Don't you think that this kind of *"general"* question requires a non-general answer?
Kotti
You say *absolutely bad* and *every game*, when in fact these statements are only true of _some_ games. Perhaps the majority, perhaps not, but it definitely isn't as universal a rule as you try to make it.
Ben Voigt
+2  A: 

Well I would save the level design in a file. Thats what scripting is for right. This then gives me a way to JUST change the levels..

Also It will keep your objects (the stuff used in the levels) seperate from the logic (the game logic). This will help debugging and have a clearer structure

Ram Bhat
Actually, writing the levels in a language the debugger knows will help debugging. With a level interpreter, you'll just end up stepping though the interpreter implementation and it will be much harder to follow the high level logic.
Ben Voigt
+2  A: 

Depends on if you can spare the resources for interpretation, and who else you intend to use your work. If you and you alone are creating it, then there's nothing wrong per se with hardcode.

If, however, you ever intend users or anyone else to modify it, ever, then interpret.

DeadMG
I disagree. Hardcoding means recompiling everything each time you want to change something as little as the position of an enemy. Even if you're developing alone it's a pain. Pretty much any non trivial game uses external data file instead of hardcoding them.
nico
Depends on if you have other reasons to recompile each build, and how long it will take you to create a suitable file format. Interpreting stuff isn't free on the dev time either.
DeadMG
@nico: That is also true... But, always reinterpreting it when the level loads OR recompile it once when the level changes....
Martijn Courteaux
External file for level information can by a dynamic library containing code just as easily as a data file. No need for recompiling *everything*, and with a decent makefile system, you may only recompile a single function. With code, it's also a lot easier to add a hook for changing things at runtime.
Ben Voigt
+11  A: 

Always separate application from data.

Konerak
Separation is good and will improve maintainability, but the best way to accomplish this might be by modular code following good encapsulation practices. Unless there's a need for users to change the levels, why build your own parser, semantic checker, etc when the compiler does all of that for you? Also, compiling the levels will make the game load much faster.
Ben Voigt
@Ben Voigt: That is also what I thought...
Martijn Courteaux