Step 2

Creating our loop

Next, let’s add the shown code to create the first half of our loop.

Here, we make sure our loop is constantly updating both where the player is and what block they are on. We also add points since they are currently not touching the floor.

We then have our if statement. The “!=” means is not equal to. The and means that both the condition before and after the word “and” must be True, if either of them are False the if statement code will be skipped.

So with this if statement, if the block we are on is not a glass block and it’s also not an air block, we run the code for us to lose.

When we lose, we post a lose message and also tell the player how many points they got. We also see the break keyword. This ends the loop that it is in, even an infinite loop, with this we can end the game.

With this all done, go ahead and test it out. If you jump off the glass blocks you should get a lose message. Your score will probably be very high, this is because we haven’t added in the “sleep” yet, we’ll work on this next.