Hardware Reference
In-Depth Information
7. Open up the holes by setting the blocks below the hole position to be AIR using
setBlocks() :
for hole in holes:
mc.setBlocks(hole.x, hole.y, hole.z,
hole.x, hole.y - 2, hole.z,
block.AIR.id)
time.sleep(2)
Once the holes are created, a delay is put in so the holes stay there for two
seconds.
8. Close up the holes by using the same loop you used to open them, but this time
set the blocks back to GRASS :
for hole in holes:
mc.setBlocks(hole.x, hole.y, hole.z,
hole.x, hole.y - 2, hole.z,
block.GRASS.id)
time.sleep(2)
The program will now return to the top of the while loop and recreate a new set
of holes.
9. Your holes function is now complete. Add the following code to the bottom of
the program:
HOLESZ = 15
thread.start_new_thread(theHoles, (arenaPos, HOLESZ))
he HOLESZ constant is the z position down the arena where the holes obstacle
will be created.
10. Run the program. As before, you should see the arena created with the wall and
river obstacles, but now you should also see the holes continually opening and
closing in random locations towards the end of the arena.
Try out the arena. See if you can get backward and forward over and through the
obstacles without falling down or getting stuck.
You can adjust the constants in the game to make it your own. Perhaps make the
arena longer or wider, put the obstacles in different positions or make it more
difficult by making them faster or harder to get across.
Search WWH ::




Custom Search