Game Design, Programming

Sixth Artifact: Level-changing

I have been working hard on bug fixing everything this week. A lot of progress has been made. For example, the guards no longer plays lighthouse when the player is nearby, was a minus instead of a plus when calculating the distance that was the reason for that. Anyway, let’s get to this week’s artifact.

So, we are going to have four levels in our game, and we do not want to load all four at the same time. I have not coded this part yet, but I have been thinking about it a lot the last couple of days.

We need a way to change from one level to another, but how are we going to do that? I got two ideas: one using if/else and the other using different states.

First, the idea about using different states. The way it is supposed to work is that depending on which level the player is on, different “level states” are loaded. So, a lot of code had to be copied from the game state into the different level states. This was the first way I came up with. At first it sounded like a good way to do it, but the more I think about it, the more I think that another way is better. Not so good on copying code, because if I have to change it later, I have to change in everyone.

The other way to do it would be to have a variable that says which level to load. Then in the Enter function in GameState, we look which level to load and set the path to the folder where the level information lies.

As I said, the more I think about it, the more I think the second way is the better. What I need to do to make it work is putting everything common to all levels in one folder. That would be all pictures, except the level background (which is specific for each level), animation text files, sounds, music and probably something more I have forgotten now.

Each level has its own folder which contains the information about walls, furniture’s, guards, starting position, etc.

Then, when the player has finished the level, we change the variable that indicates which level to load and manually call Exit() and then Enter(). So, instead of creating a new function where every wall, furniture and guard is deleted and then re-initialized for the new level, we use the two functions we already have for the state manager and seem to work as intended anyway.

The picture is a room on our second level.

Level2Picture

Standard

One thought on “Sixth Artifact: Level-changing

  1. Sebastian says:

    Heya

    I did this exact thing for our project a few weeks ago, and just like you I had that precise choice. For our project the second one was way simpler. Each level had the exact same properties as the others (except the tutorial) and the only thing I needed to do when a single level was completed, was to change one variable and tell the state-manager to reload the current state.
    Putting everything that is needed for a specific level in a certain folder is a nice idea, however there must exist a global folder as well (if there are images or music that are needed on several levels). You wouldn’t want the game to take up unnecessary disk space.

    Good luck now on the last week!

Leave a comment