Hardware Reference
In-Depth Information
14. Now you need to clear the time by drawing the hands again, only this time you
draw them using AIR . Type:
mcdrawing.drawLine(
clockMiddle.x, clockMiddle.y, clockMiddle.z,
hourHandX, hourHandY, clockMiddle.z,
block.AIR.id)
mcdrawing.drawLine(
clockMiddle.x, clockMiddle.y, clockMiddle.z-1,
minHandX, minHandY, clockMiddle.z-1,
block.AIR.id)
mcdrawing.drawLine(
clockMiddle.x, clockMiddle.y, clockMiddle.z+1,
secHandX, secHandY, clockMiddle.z+1,
block.AIR.id)
15. Save the file and run the program to see the result of your efforts. You should see
the Minecraft Clock appear directly above the player, who can look up and walk
to the side to see the time. Make sure the player is on the correct side of the clock
though; otherwise time will be going backward!
You can download the complete code for the Minecraft Clock from the companion
website www.wiley.com/go/adventuresinminecraft but I strongly recommend that
you type in the code yourself as you read through the steps. You'll learn a lot more
that way!
DIGGING INTO THE CODE
The findPointOnCircle() function works out a point (x, y) on a circle from
the centre position of the circle (cx, cy), the radius of the circle and the angle
you've specified (see FigureĀ 7-5).
1. The function is defined with a cx, cy, radius and angle as
input parameters:
def findPointOnCircle(cx, cy, radius,
angle):
2. The point on the circle (x, y) is calculated using the math functions
sin() and cos() , multiplied by the radius:
x = cx + math.sin(math.radians(angle))
* radius
y = cy + math.cos(math.radians(angle))
* radius
 
Search WWH ::




Custom Search