Friday 18 March 2011

Dynamic Level Generation Part 1

This purpose of this post is to document the development of the Dynamic Level Generation algorithm.

First things first is to divide the screen into a grid:
This grid is completely scalable and can have more or less rows and columns.
Each block in the grid has a red square drawn in each of them representing a wall. The top and bottom rows are kept free for the player sprite.
Using a random algorithm, we can have a 50/50 chance of a wall being drawn:
This demonstrates that each part of the walls can be added dynamically, but a 50/50 chance is just an example so far.

To begin the process, I have drawn up the first draft a decision tree for visualizing the AI behind the algorithm:

For the first version of the algorithm, we are going to exclude the decision for drawing an obstacle.

Depending on the difficulty, there will be a block count for each row e.g. easy = 0-2, medium = 0-3, hard = 0-4.
If the block count has been reached for that row, the algorithm will proceed to the next.

In a nutshell, there is more of a chance that block will be placed connected to each other, resulting in the desired "walls" being created:

At the moment, walls are still very crude, and there is still the possibility that the path from top to bottom will become blocked or that free blocks will be trapped within:
The next stage of the development is to make sure there will always be a path from top to bottom.

No comments:

Post a Comment