Hardware Reference
In-Depth Information
8. To move the bridge across the arena one block at a time, you need to calculate the
number of steps the bridge would have to go through in order to get from one
side to the other; this is the width of the arena minus the width of the bridge:
steps = ARENAX - BRIDGEWIDTH
9. Move the bridge from side to side by using two for loops (one to go left and one
to go right) and by using the MinecraftShape.moveBy() function to move
the bridge one block to the side for each step, adding a small delay in between
steps:
while not gameOver:
for left in range(0, steps):
bridgeShape.moveBy(1,0,0)
time.sleep(1)
for right in range(0, steps):
bridgeShape.moveBy(-1,0,0)
time.sleep(1)
10. Your river function is now complete. It needs to be called from the main pro-
gram in a new thread, so add the following code to the bottom of the program:
RIVERZ = 4
thread.start_new_thread(theRiver, (arenaPos, RIVERZ))
11. Time to run the program! You should now see the arena with the wall in the mid-
dle, the river toward the start of the arena and the bridge going back and forth.
Enter the arena and try to get across the bridge. If you're good with the controls
you might find this pretty easy—but wait until you are under pressure to collect
the diamonds at the same time and do it as quickly as possible! Chances are you
will miss the jump a lot more.
Creating the.Holes
The final obstacles you need to create in Crafty Crossing are the holes. These are ran-
dom holes in the arena floor that close up every few seconds and open again in differ-
ent positions (see Figure 9-9).
You will use the randint() function to find random positions for the holes. BLACK
WOOL blocks will appear briefly in the floor before the holes open up, giving the player
some warning and a chance to get out of the way. You create the holes by turning
blocks in the arena floor to AIR . They stay that way for a few seconds before being
turned back to GRASS and new holes are created elsewhere.
 
Search WWH ::




Custom Search