Step 3

Completing the program


Next, let’s add the shown code to complete the program!

Here we see another new keyword, else. The code inside the else only occurs when the if statement code gets skipped. Here, this means this code will only happen when we DON’T lose.

Inside the else statement we get random values for x and z and then use those values to place a random glass block near the player.

After this, we make a 1.25 second delay before destroying the block the player was standing on, forcing them to always be moving.

Lastly, we have one more 1 second delay to give the player some time before their next jump.

Running the program


Now that all the code is done, let’s try it out!

If done correctly, you should see glass blocks spawning around you and the game should continue as long as you jump on them.

If anything out of the ordinary happens, double check your code for any bugs. Once it’s all working see how high a score you can get! Feel free to try messing with the code to modify/improve it as you see fit.