Jump to content
  • Advertisement
Sign in to follow this  

adding multiple levels to your game

This topic is 4522 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.

Share this post


Link to post
Share on other sites
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".

Share this post


Link to post
Share on other sites
I agree with Zahlman, an example of such a file could be:

width 128
height 128
player 3 35
wall 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++).

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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>

VS

023
826
312
As you can see, it's much easier to read the bottom example then the XML. And they both result in the same thing.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!