Game Development: Should I program my levels or interpret them from a file?
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?
Always separate application from data.
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.
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
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.
精彩评论