Game Development Reference
In-Depth Information
Objective complete - mini debriefing
This one script is all that is needed to create a new interesing level each ime the Space bar
key is pressed. Try it a few imes to see what kind of designs the computer comes up with.
Due to the randomized costume selecion, you'll noice that the paths through the maze will
be diferent each ime.
Classified intel
You might noice that in many cases, the paths will be relaively short with walls blocking
the passage at fairly short distances. This is because each ile has an equal chance of being
selected by the randomizer. However, some iles, the straight corridors especially, contain
more wall segments than open passageways.
We can manipulate the random selecion of iles to favor the ones that are more open.
We already made sure that the more closed iles are at the front of the costume list while
the more open paths are towards the end with the open square closing the list.
We use this knowledge to perform a calculaion on the random selecion which favors higher
numbers over lower ones. We calculate this using the following steps:
1. Instead of pick random (1) to (12) , set the value from 1 to 144 .
2. From the resuling number, take the square root.
3. As a final step, use the round block to round the number to a whole, so it points
to a specific costume again:
Why does this work? This is because the square root of the higher numbers in the extended
range resolve to a higher value more often. For example, only square root of 1 and 2 rounded
off will resolve as 1 . But all the numbers from 133 up to 144 will resolve as 12 . That means 12
chances to come up with costume 12 and only 2 chances to come up with costume 1 .
Creating a character
To make use of our generated maze, we will need to include a character the player can
control. We'll use the default Scratch cat as the protagonist and add all the required control
script to make it move through the maze.
 
Search WWH ::




Custom Search