Hardware Reference
In-Depth Information
3. Check to see if the type of block hit was DIAMOND_BLOCK . If it was, turn it to
AIR and subtract 1 from the diamondsLeft variable:
if blockHitType == block.DIAMOND_BLOCK.id:
mc.setBlock(hit.pos.x,hit.pos.y, hit.pos.z,
block.AIR.id)
diamondsLeft = diamondsLeft - 1
he diamondsLeft variable will be used to check that all the diamonds have
been collected when the player gets to the end of the arena.
4. Run the program; when you hit the DIAMOND blocks, they should turn to AIR
and disappear.
Remember that, in order to hit a block, you must be holding a sword and using
the right-click button on the mouse.
CHALLENGE
Can you make the diamonds harder to hit? Perhaps you can make them rise up
and down and allow the player to hit them only when they are in the air.
Out of.Time
If your player was given an infinite amount of time, the game would be really easy (and
boring). By introducing a time limit, you make the game challenging; and by making
the player get all the diamonds and get to the other side before the time runs out, you
give him a goal.
If the time runs out, it's game over. Your next task is to add the code to the level loop
that will check to see if the time has run out and, if it has, will set the gameOver flag
to True :
1. Indented under the level loop, tell the program to calculate the number of sec-
onds left in this level:
#level loop
while not gameOver and not levelComplete:
secondsLeft = TIMEOUTS[level] - (time.time() - start)
 
Search WWH ::




Custom Search