Hardware Reference
In-Depth Information
6. Now write the main game loop. You will run this loop quite fast when the game
is running (10 times per second) so that the gold block trail is accurate enough to
walk along in the sky, but slow it right down to once per second while you are
testing it. Inside this game loop you will use your dummy functions, which you
will write soon.
while True:
time.sleep(1)
if treasure_x == None and len(bridge) == 0:
placeTreasure()
checkHit()
homingBeacon()
buildBridge()
7. Save your program with File Save and then click Run Run Module from the
menu to run it. You should not have any errors in the program, and for now it
should just print some messages once per second on the Python Shell window.
You now have the framework of your program in place, ready for you to start
adding new code to it, bit by bit.
Placing Treasure in.the Sky
The first function you need to write is the one that places treasure at a random position
in the sky. You will use three global variables for the coordinates of the treasure, and
their initial value will be None . he None value is a special Python value, indicating
that the variable is in memory but has nothing stored in it. You will use this in your
game loop to check whether a new piece of treasure needs to be built.
1. Create the global variables to track the position of the treasure, add the lines
in bold:
treasure_x = None
treasure_y = None
treasure_z = None
2. Fill in the placeTreasure() function (and take out the print statement you
put in earlier) with this code:
def placeTreasure():
global treasure_x, treasure_y, treasure_z
pos = mc.player.getTilePos()
 
 
Search WWH ::




Custom Search