Hardware Reference
In-Depth Information
2.
Create two variables to hold the points the player has scored and the level they
are currently on:
level = 0
points = 0
3.
Create the
game
loop. Place a comment over it to remind you where it is, as fur-
ther instructions in this adventure will refer to indenting code under the
game
loop:
#game loop
while not gameOver:
The variable
gameOver
is set to
False
at the start of the program; it will be set
to
True
when the player runs out of time or completes the game. This variable is
also used in the obstacles functions, and when it is set to
True
it will result in all
the obstacles stopping.
4.
Indented under the
game
loop, change the position of the player so that he is at
the start of the arena and ready to begin:
mc.player.setPos(arenaPos.x + 1, arenaPos.y + 1,
arenaPos.z + 1)
5.
Start the clock for the level by getting the current time and putting it into a vari-
able:
start = time.time()
6.
Set the level complete flag to
False
and create the level loop. As you did with
the
game
loop, create a comment here to remind you where the
level
loop is, as
further instructions will refer to indenting code under the
level
loop:
levelComplete = False
#level loop
while not gameOver and not levelComplete:
7.
Indented under the
level
loop, put in a small delay. You need this because the
program will loop all the time while the game is playing and, without it, the pro-
gram would use all the computer's processing power:
time.sleep(0.1)
8.
Run the program. The only change you will see is that the player is automatically
put at the start of the arena, but it will give you the chance to check that every-
thing is working properly and no errors have occurred.