adding multiple levels to your game

Started by
6 comments, last by Rob Loach 18 years, 3 months ago
Up until now, I've been making short single-leveled games just to test what I've learned so far. Now, I want to make a "Real" game. You know, one that has more than one level/area. :) What methods do you guys/gals like to use for creating multiple levels? For a 2D tile-based game, I've got these big double-layered tile-maps, all these enemy positions (.x/.y), and misc. variables, etc... Setting all these things up for level 1 is a decent amount of code, but to reset everything differently for each level doesn't seem like the best way to go about this. Or is it? Any general suggestions would be much appreciated. Thank you and Happy New Year.
Advertisement
You want to represent the level data ("map") for each level in a file, and load it in at the beginning of each level. Instead of writing *code* to say "put an enemy here" however many times, you write *data* for each one saying "there is an enemy here", and then write *one* piece of code that says "put an enemy in each place that the provided file says there is one".
Yeah, that sounds much better. I'll start looking for an article/tutorial on how to set that up. Thanks for your time.
I agree with Zahlman, an example of such a file could be:
width 128height 128player 3 35wall 6 3 6 10

Which could translate into, 128x128 map, player's pos is 3(x),35(y), there should be a wall from point(6,3) to point(6,10). In the same way you could add enemies like this:
enemy 5 95 rebel
This would then be a enemy of type rebel at position 5,95. When you have all this in a text file it shouldn't be too hard reading with your language's IO functions/classes (std::ifstream in C++).
Oh yeah... that stuff I learned before graphics/DirectX. :-) Got to love that simple command-prompt. I've got a book or two for reference. I may have been in a bit of a hurry to get into DirectX. HeHe!

Thank You.
You might want to look into XML (to help organize your levels and make them easier to read/edit) and/or a scripting language (Lua/Python) to add some additional functionality/puzzles/whatever.
"For sweetest things turn sour'st by their deeds;Lilies that fester smell far worse than weeds."- William Shakespere, Sonnet 94
Quote:Original post by xycos
You might want to look into XML (to help organize your levels and make them easier to read/edit) and/or a scripting language (Lua/Python) to add some additional functionality/puzzles/whatever.


Gotta walk before you run. Stay away from XML and expecially Lua/Python for a while. Get the hang of file I/O first and then move onto more advanced topics.

Happy Coding.
Although it's completely dependant on your game design, some games don't even need map data to have multiple levels. When working on Blastoids, I knew that every level would be quite similar. I decided that I would make a little function that would generate the next level for me as opposed to reading the data in from a file.

The little function I created created a random number of asteroids depending on what level they were on. It also set the asteroids just outside the playing field and sent them on a random spin, speed and direction. It proved to be quite sufficient for what I was looking for.

If you're game design requires map data to be loaded, my suggestion would be to look at what needs to be loaded. Do you want the player to be able to save their progress mid game? How would you go about doing that? Serialization is a valid option, but then you might have to make your own map editor interface for your game. Take into account what you want to have loaded for each map and think about what will affect your game design.

Quote:Original post by xycos
You might want to look into XML (to help organize your levels and make them easier to read/edit) and/or a scripting language (Lua/Python) to add some additional functionality/puzzles/whatever.
Although XML and scripting languages are extremely valid choices for loading data, they're rather hard to work with for tile maps:
<map width=3 height=3><tile>0</tile><tile>2</tile><tile>3</tile><tile>8</tile><tile>2</tile><tile>6</tile><tile>3</tile><tile>1</tile><tile>2</tile></map>VS023826312
As you can see, it's much easier to read the bottom example then the XML. And they both result in the same thing.
Rob Loach [Website] [Projects] [Contact]

This topic is closed to new replies.

Advertisement