Hardware Reference
In-Depth Information
Use the following steps to create the alien invasion program:
1. Open IDLE, click New New File and save the file as AlienInvasion.py in
the MyAdventures folder.
2. Import the minecraft , block , minecraftstuff and time modules:
import mcpi.minecraft as minecraft
import mcpi.block as block
import mcpi.minecraftstuff as minecraftstuff
import time
3. Create the distanceBetweenPoints() function:
def distanceBetweenPoints(point1, point2):
xd = point2.x - point1.x
yd = point2.y - point1.y
zd = point2.z - point1.z
return math.sqrt((xd*xd) + (yd*yd) + (zd*zd))
4. Create the constants for the program. HOVER_HEIGHT is the number of blocks
the alien spaceship will hover over the player; ALIEN_TAUNTS is a list of the
taunts that will be posted to the chat while the aliens are chasing the player:
HOVER_HEIGHT = 15
ALIEN_TAUNTS = ["<aliens>You cant run forever",
"<aliens>Resistance is useless",
"<aliens>We only want to be friends"]
You can change the aliens' taunts—see how creative you can be! Or add more if
you like.
5. Create the Minecraft and MinecraftDrawing objects:
mc = minecraft.Minecraft.create()
mcdrawing = minecraftstuff.MinecraftDrawing(mc)
6. Set the aliens' starting position and mode, which will be 50 blocks directly above
the player and “landing”:
alienPos = mc.player.getTilePos()
alienPos.y = alienPos.y + 50
mode = "landing"
7. Create the alien spaceship using MinecraftShape (look at Figure  8-6 for a
reminder of how this is done):
alienBlocks = [
minecraftstuff.ShapeBlock(-1,0,0,block.WOOL.id, 5),
 
Search WWH ::




Custom Search