Jump to content
  • Advertisement


This topic is now archived and is closed to further replies.


Levels in side scrollers

This topic is 5229 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

Ok, for the past month and a half I''ve been working on my side scrolling shooter ''Space Blasters''. I''ve got all the basic stuff done, enemies, collision, sprites, etc. But now, I''m having a bit of trouble with loading different levels. Each level would include - The enemies - Music - A boss (sub-bosses maybe) - A different background - Different bonuses - A set distance (the distance is used to calculate when the [sub]boss appears What would be the best way to load all those for the next usable level? I was thinking of using some sort of struct to hold the data and have a function to initialize them all but I figured I''d ask here first to get some confirmation.
VG-Force |Ekim Gram Productions

Share this post

Link to post
Share on other sites
Yes, a struct of some sort would definately be the best way to go, and you should probably load the data from a file so you don't have to recompile every time you want to change one little thing. Of course, that makes the data more vulnerable to change by users, which can be a good or a bad thing, depending on what you want. For example:
struct Level
int numEnemies;
Enemy enemies[MAXENEMIES];
int music;
int boss;
int background;
Bonus bonuses[MAXBONUSES];
int distance;

vector<Level> g_levels

And then you might have a data file that looks like:



Of course you can get rid of all the text (making it much easier to read in) and leave it as raw numbers. You could also use a binary file instead. If you were so inclined, you could even encrypt it.

[edited by - aprosenf on March 22, 2004 10:57:20 PM]

Share this post

Link to post
Share on other sites
@Ekim_Gram - I''d say that a struct or class to hold the level data would be a good idea. If you make a level a class, then it could have methods to load the new level in and could even affect things based on conditions. Like the irritating thing that steals your options in Gradius III. It only shows up if you have 4 options. Your level class could, for example, keep track of the player''s progress and if certain criteria are met, it could make changes. This could be used to adjust the difficulty to the player''s ability or could be used to have branching levels rather than linear progress through the game. Maybe secret levels?

This is off the topic, but I''m hoping to do a side-scrolling shooter in the near-ish future. I was wondering if you could maybe tell me how your levels are loaded and such? For example, how do you store the background image(s)? Is it one long image or is it broken up into smaller images? How do you store the spawn points of your enemies?

Also, how do you do collision detection with the ground (assuming that you HAVE a ground)? For example, in Gradius III, you can crash into mountains above and below you. If you have levels like that, how do you handle the collision detection?

@Unsuspected - I''ve not managed to do it myself yet, but I think it has something to do with how your file reading objects are set up. Your file stream "thingies" have to be set to work in binary. I think. I''d like to know more about that myself...


Share this post

Link to post
Share on other sites
Original post by Unsuspected
I''m really curious; how do you write and read binary files as oppose to ascii files?

Share this post

Link to post
Share on other sites
Well, that link was for C and I see that there''s more than one curious person. Note, for starters, that the notions of ASCII and binary do not exist under Unix: in that case, a file is a file. (Can''t help you with Mac.)

Rather than using the stream insertion and extraction operators (or getline), use the std::ostream:write and std::istream::read methods. They take the address of the destination buffer (a pointer, usually a pointer to char because char is the system byte size) and the size/length of data to read:
#include <fstream>
#include <iostream>
int main()
using namespace std;
ifstream fin("input.bin");
ofstream fout("output.bin");
char data[1024];
fin.read(&data[0], 1024 * sizeof(char));
fout.write(data, 1024 * sizeof(char));
return 0;

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

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

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!