The game file that needs to be imported and loaded for this session is 5961_04_08.stencyl
.
We're going to modify our instructions so that the statues are dropped at a random location, so ensure that the Drop Actors Randomly
behavior is being displayed. Execute the following steps in order to introduce randomness to our behavior:
0
into the textbox immediately after the word between.The actors are now falling at a random location somewhere between the leftmost edge of the screen and the rightmost edge of the screen.
The first step was to drag the screen width x 0.5 blocks out of the behavior because we no longer needed them. We then added the random number between … and … block, which allows us to specify a low number and high number, and then uses this information to generate a random number within that range. We specified a lower number of 0
, which is the x coordinate for the left-hand side of the screen, and a higher number of screen width, which is the x coordinate for right-hand side of the screen. When our game is running, the random number between 0 and screen width instruction will automatically generate for us a random x position between zero and 640. The random number is then added to the x of camera
to ensure that the statues always fall within the viewport.
Finally, we pressed the key combination of Ctrl + K, or Command + K on Mac OS X. This shortcut removes any unused blocks from the behavior designer, such as the ones that we dragged out of the behavior in the first step.
Unused blocks don't have to be removed from the behavior designer, they are ignored when the game is compiled, and they don't use any extra memory in our compiled game. However, it's a good idea to tidy up the behavior editor when the blocks are no longer required.
Let's solve two more problems. The first problem is a technical one; depending on the speed of the computer's processor, after approximately 10 to 20 statues have been dropped, the game starts to lag, it slows down to an unacceptable speed because there are too many active actors on screen. Computers have limited resources and it is our job, as the game developer, to use these resources effectively.
The second problem is a gameplay issue; if too many statues have fallen, it can become impossible to complete the level, because the statues might block the monkey's path through the jungle. In some games, this may be the desired gameplay, but we want to create a game that is a little less stressful for our player on the first level, perhaps gameplay could become more difficult in later levels, but not just yet.
There are many ways to resolve such problems in a game, and it's usually down to the imagination of the developer to find a solution. We're going to solve both problems simultaneously, with a new behavior.
52.15.57.52