Friday, August 26, 2011

My work in game maker


One of the more recently active projects I’ve been doing is getting acclimated to game maker and building a game for my game prototyping class. The class itself has students produce games in game maker on a rather rigorous schedule. A secondary goal I've had through my education is exploring procedurally generated content in games. While I don't always get to do this and it doesn’t work for all projects, I was able to explore this while ramping up and preparing a game project for the class.

The game itself is currently untitled but it is supposed to be a 2d platformer. However as things have progressed I’ve found that that it seems to be much more in the style of a metroidVania style game. The major feature of the game is the procedurally developed levels that provide a semi-consistent “city and sewer” style levels. Through changing other variables I can also have more naturalistic caves or possibly even other types of levels. Since they are randomly generated the player doesn't know exactly what the level contains or the exact layout. However, the levels all have the same style so the player does get a sort of ‘feel’ for what kinds of terrain they can expect through a level. This keeps things consistent yet also fresh.

OK enough beating around the bush; I’m now going to tell you (generally) how the algorithm works. I can’t post code since this is a student project and I will not own the rights to the code that implements this algorithm (school contract thing). However I can tell you what I’m doing. Ok, lets move to step one

step one: basic info
I use a 2 dimensional array to contain where all the tiles will go and what the tiles are going to be(fairly standard stuff). This array is the back bone and how the computer reads through the level data. Most things are basically just different types of array parsing and changing values to get the level to look the way I want.

Step two: build tiles
The random function is by far the most powerful function ever invented ever. What I do to build a cityscape type level is define random horizontal chunks of tiles (normaly 3-5 tiles; where the player object is one tile in size) then I randomly set a height to the chunks and initialize them into the array.



Step three: cutting away
after I’ve done a basic initialization of the array I do some cutting away of blocks. There are roughly three substeps to this, swiss cheese, holes and smoothing.

Swiss cheese is where pockets are cut at random into the array (these pockets are 3x3). They don’t always cut into the areas where there are blocks but it's just to add some additional randomness to the level


Holes are cut by parsing through the array to find areas where there is a large discrepancy between the heights of groups of tiles. Ok so that doesn’t make much sense but basically it's an algorithm that bores horizontal “holes” through the level. It generally starts at some empty space and ends when it hits some other empty space.

This part of my code I think is the most inelegant portion I wrote. But it does what I need it to do when I combine it with ...

Smoothing is part where I search for wayward tiles that are just ‘hanging out’. It's kinda weird to have a ton of random blocks floating in space. While you can't prevent all of them, parsing for blocks that doesn’t have other blocks near them Greatly reduces the number of occurrences. You can do more smoothing if you like as well, however each iteration does reduce the number of blocks and if you over do it it will make your level sparse. I don't do more than a couple iterations with some different tweaks.



Step four: extra stuff
This is now where I add in the layer of breakable blocks (It's like smoothing except that it changes any array element that is ‘adjacent’ to empty space to a number denoting that it should be built as a breakable block). If I had a enemy AI up and running I would toss spawn points in here (basically just random checks to see if a space is available and keep looking if it is not). At the end I cap off the sides and bottom of the level so Players don't fall off into space never to be scene again.



What I have learned so far is that Game Maker can require some Zen like patience and requires you to work in harmony with the program. It is not easy to get along with it if you are used to defining everything for yourself but if you are in harmony you can be very effective. In reality your first 40 hours with a new computer program is always going to be painful because you are learning how it likes to do things. I’ve also learned it's a good idea to let the player have some control over the random environment, which is why I have breakable blocks. This lets players have enough control to get to most places in a level without any problems.

Going on from here I really will need to add enemies; and some over-world mechanics (and then do a final art pass). The initial concept of this game is that the player would be a space ranger tasked with rescuing Colonists from worlds being invaded by aliens. The players space ship would have limited space and couldn’t take all of the people off the planets. While the player would have the option of only rescuing scientists; this would be balanced with the scientists not working as effectively unless they had additional crew members that the scientists would value.

While this will be implemented as a much more simple ‘collection and matching’ mechanic, It will hopefully create more of an emotional response in the player. As the game itself will be planned to be endless and force players to make morally questionable decisions, asking what kind of scientists and people they want to save from certain death at the hands of an alien menace.