Hardware Reference
In-Depth Information
2. To find out the coordinates of your doormat in the Minecraft world, run your
whereAmI.py program again, and then stand on the doormat. Write down
the x, y and z coordinates somewhere, because you will need them when you
come to write your new program so that you can locate the doormat in the
Minecraft world.
You're probably already impatient to start building huge structures! In Adventure 3,
you will learn how to do that automatically by writing Python programs but, for
now, just build something simple, focusing on getting the program to work
properly. You might like to build a simple house around your doormat, making
sure that the doormat is in the open doorway of your house.
Writing the.Welcome Home Game
Now that you understand how if statements work, you can write the Welcome Home
Game by following these steps:
1. Choose File New File from the Python Shell menu to create a new program.
2. Choose File Save As from the editor menu to save your program, and call it
welcomeHome.py . Remember that you need to save your program in your My
Adventures folder for it to work properly.
3. Import the modules you need for this program by typing:
import mcpi.minecraft as minecraft
import time
4. Connect to the Minecraft game, remembering to check the capitalisation of the
word Minecraft :
mc = minecraft.Minecraft.create()
5. Put in the main game loop that senses your player's position, with a delay so it
doesn't run too quickly:
while True:
time.sleep(1)
pos = mc.player.getTilePos()
6. Add the if statement that checks whether your player is standing on the mat.
This uses the if statement with an and to check two conditions. Both the x and
z parts of the coordinate for your doormat must match the player's position for
the program to say the player is standing on the doormat. Still have the x and z
 
Search WWH ::




Custom Search