Hardware Reference
In-Depth Information
Listing 5-4 continued
drawScreen(ballPosition)
ballPosition = moveBall(ballPosition)
ballsLeft -= 1
print “press space for”,balls,”more balls”
pause = True
while pause :
checkForEvent()
def waitForServe(p,player) :
global batY, rally, delta, serve
computerBatDelta = 2
serve[player] = False
serveTime = time.time() + 4.0 #automatically serve again
while time.time() < serveTime and serve[player] == False:
checkForEvent()
drawScreen(p)
batY[player] += computerBatDelta ;
# move bat up and down when waiting
if batY[player] > limit[3] or batY[player] < ;
limit[2]:
computerBatDelta = -computerBatDelta
p[0] = batX[player]
p[1] = batY[player]
delta = deltaChoice[random.randint(0,maxDelta)]
if player == 1 :
delta[0] = -delta[0]
p1hitSound.play()
else:
p0hitSound.play()
rally = True
return p
def moveBall(p):
global delta, batY, rally, score, batThick, server
p[0] += delta[0]
p[1] += delta[1]
# now test to any interaction
if p[1] <= limit[2] : # test top
bounceSound.play()
delta[1] = - delta[1]
p[1] = limit[2]
elif p[1] >= limit[3] : # test bottom
Search WWH ::




Custom Search