Hardware Reference
In-Depth Information
blocksBetween = mcdrawing.getLine(
alienPos.x, alienPos.y, alienPos.z,
alienTarget.x,alienTarget.y,alienTarget.z)
for blockBetween in blocksBetween:
alienShape.move(blockBetween.x, blockBetween.y,
blockBetween.z)
time.sleep(0.25)
alienPos = alienTarget.clone()
13. At this point the program will return to the top of the while loop. When the
mode has been set to "missionaccomplished" and the while loop finishes,
the last line of the program is to make the alien spaceship disappear:
alienShape.clear()
14. Run the program and watch out for the aliens who will come down from the sky
directly above you.
You can download the complete code for the alien invasion from the Adventures in
Minecraft companion website at www.wiley.com/go/adventuresinminecraft.
DIGGING INTO THE CODE
Each time the aliens chase the player, a random taunt is picked from the con-
stant ALIEN_TAUNTS and posted to the chat.
mc .postToChat(ALIEN_TAUNTS[
random.randint(0,len(ALIEN_TAUNTS)-1)])
ALIEN_TAUNTS is a list of strings; the random.randint() function is used to
pick an item from the list, randomly picking a number between 0 and the length
of the ALIEN_TAUNTS list minus 1.
1 is taken away from the length of the list because, while len() returns the
actual number of items in the list (i.e. 3), but you have to reference items in the
list starting at 0 (i.e. 0,1,2).
CHALLENGE
The alien spaceship is really simple. Try creating an amazing spaceship, one you
really like. Change the spaceship so that when it lands it goes into “lurk” mode,
where it will stay close to the player but not attack; and then, based on a ran-
dom probability, switches without warning to attack mode.
Search WWH ::




Custom Search