Alpha Revolver Games

General Development Update: Behind the memory level.

Leave a comment

So, last week I started (and finished shortly thereafter) the 9th level for Monster Mayhem; Memory.

The mechanics of the level are simple: at the start of the level, a tune will be played. Once the tune is over, the player uses the buttons on screen to recreate it. Now, there are a lot of potential ways to implement this type of system; I chose to use arrays.

There are multiple reasons why I chose to use arrays, the primary one being that arrays are a really efficient way of storing data. Another reason though, is that I had never previously taken time to wrap my head around arrays, and I wanted to take the opportunity to learn about them, and grow as a developer.

This first array game_tune[i] is initialised and populated on the level’s start up (In the create event) using for loops; another extremely useful tool, especially when doing repetitive things (like initialising arrays)

//initialising array
for(i = 3; i > -1; i -= 1){
   game_tune[i] = 0;

the code above initialises the array from back to front. We do it this way, rather than from front to back, so that Game Maker knows exactly how long the array will be (as you are initialising the last entry in the array first), this means that it will reserve a space in memory that is the exact size of the array. If you initialised the array from 0 upwards, the memory has to be re-allocated for every additional value added. This has a negligible performance difference when dealing with small arrays, but I’d say that its better to get into good habits sooner.

//populating array
for(i = 0; i < 4; i += 1){
   game_tune[i] = choose(“r”, “b”, “g”, “w”);
   show_debug_message(“game_tune[” + string(i) + “] = ” + string(game_tune[i]));

This next portion of code fills the empty slots in the array with either “r”, “b”, “g” or “w” (i.e. red, blue, green or white). These blocks of code will result in something like this:

//initialising array

game_tune[3] = 0;

game_tune[2] = 0;

game_tune[1] = 0;

game_tune[0] = 0;

//populating array

game_tune[0] = “b”;

game_tune[1] = “g”;

game_tune[2] = “w”;

game_tune[3] = “w”;

The game will then use the array to play the tune at the start of the game. In the example above the tune would go, Blue, Green, White, White.

After the tune is player, the player is able to press the buttons to try and recreate the tune. Each time they play a note, it is stored in the second array, player_tune[i], and then compared with the corresponding value in game_tune. If the entries are the same, the game continues and the player can play another note. If they are different, the level is lost.

For example. if the player plays the blue note in the example above, then:

player_tune[0] = “b”;

that is then compared against:

game_tune[0] = “b”;

because they are both blue, the level continues. If the player played any other note, they would lose the level.

The reason I wanted to go into so much detail in the actual development of this level is because I was really proud of how quickly I was able to learn about arrays and for loops. I could have developed this level in a sub-optimal way using some other solution, and it would have been absolutely fine.

Instead however, I chose to challenge myself in a professional capacity; to learn a better way of doing things. And the coolest part of all of it was that I learned this stuff as I implemented it, and it had barely any effect on how long it took to develop. It was a really rewarding, yet surreal experience where I felt like I was one with the matrix. I can’t remember the last time I enjoyed learning this much.

See ya next time,

Steven 😉

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s