Making Different Levels?

Hey Guys,

   So Ive been moving along pretty well lately, and I think its time to take my games to the next step. Im trying to figure out how to implement a level structure. For instance right now Im working on a shooter kind of like space invaders. I want there to be a level structure, so for instance the first few levels increase in alien ship count and speed, and then every 5th level is some sort of boss battle. Im having trouble figuring out how to achieve this. Is this a technique that I should save until Ive gotten better at this? I mean I know how to increase the difficulty and make a boss battle, but I can only understand how to implement them as totally separate games. How can I create a flow that carries through the entire game experience?

I was thinking of doing it with states. So Like each level is a state, and if the game is in a certain state, code is executed that pertains to that state. So if level5 is the current state, some boss code will run… does that make sense, or way too complicated?

Depends a lot on what you’re going for. How procedurally generated is your game? How pre-built. A fully pre-made game should have a Level object that can be loaded from some sort of file. Then there is only one Level active at one time, and perhaps different ways to link between them (like in an RPG, a door in one level might lead into another one). In your game, you can just have them lead to one another in a linear fashion as long as the order is stored somewhere.

I would imagine your Level object to be something like this:


public class Level
{
    Wave[] enemyWaves;
    float powerupChance;
    EnemyType[] possibleEntities;
    float scrollSpeed;
    //etc.
}

Pretty much anything that is specific to an individual level should be a member in the Level object. Then you just create the objects somehow (whether through a level editor or a text file or XML or whatever). I usually have the World contain one level, then as the player moves around the World fetches data from the Level to decide how to respond. In your case, that means the World would spawn enemies based on timing, scroll the screen at different speeds, etc.

What a damn, I’m creating clone of space invader too (in pulpcore but) and going to implant the levels. On my design, the key is located on the method where everything be declared (ship, aliens, speed, etc) called newGame(int level). I pass a value of next level and the method will determine aliens, speed, etc for next game based on that value. Example


void newGame(int lvl){
    for (int i=0; i<lvl*6; i++)
        aliensContainer.add(new Alien());
}

On that example, each level will increase the aliens by 6 (lvl1 6 aliens, lvl2 12 aliens and so on).

Yeah, you could certainly do that. I try to avoid it these days because it’s so difficult to maintain - at the very least I make text files for each level and then just parse them. That’s just as fast to implement.

If you want to have a boss each 5 levels you need to check (simply by %5) the value and make it appear a boss rather commonAlien*6. Hope can help you.

not only difficult. That also just applies on linear way :smiley:

Thanks guys. Game programming is proving to be harder than any programming project Ive ever had in school, BY A MILE!

To be a good game programmer you need to be a jack of all trades, whereas most other areas you just need to be a specialist.

yeah, because you just need to pass your teacher’s taste in your work :smiley:

Yeah I guess so. Its just so rewarding, I got my character to jump tonight and I havent been so excited in ages lol

Haha awesome. Congrats. :slight_smile: