Hardware Reference
In-Depth Information
he updateBox() and drawScreen() functions are unchanged, but the updateScore()
function has been altered to accommodate the score of both players. he moveBall() function
has been enhanced to include top and bottom limits for the left player's bat, and for both players
a new function batBounce() is called when a collision is detected. More on this shortly.
he waitForServe() function now includes code to allow either player to serve the ball, and
there is a longer time before an automatic serve, along with a separate serve sound for each
player. here are also a few changes to global variables, adding one to indicate who is serving.
So back to the batBounce() function. his performs two functions - the irst to determine
the ball's return velocity vector and the second to play a sound dependent on the player striking
the ball. As the code is written this is the same as the serve sound, but it could be changed.
he major new feature in this function is in determining how far along the bat the collision
occurred. his basically is a loating-point number between -1 and +1, with zero being
returned if it is plumb center. After you have gotten this fraction it needs to be multiplied by
the number that corresponds to the maximum Y velocity you want if the ball just grazes the
top or bottom of the bat. In the code I have used a value of 14. hen to keep the overall speed
of the ball constant, the X velocity is the maximum velocity you want it to be if there is a
dead center hit minus any Y component of the speed. his is all done in the two lines
delta[1] = int(-14.0 * ((point * 0.05) + 0.6))
delta[0] = 16 - abs(delta[1])
Note how the loating-point calculation is converted to an integer before assigning it to the
delta global variable. his keeps the delta values as integers, as operations on integers are
much faster to perform for the computer.
he inal bit of fun is the sound efects. What I did was scour the Internet looking for tennis
sounds and found some interesting examples of famous tennis players' grunts as they hit the
ball. Using Audacity, I clipped out the short hit/grunt noise and saved it as an .ogg format ile.
I found a line judge's “out” call, along with some real bounce sounds. hese sounds enhance the
playing of the game tremendously, especially because there is also some crowd noise. However,
for that retro 70s sound, you can't beat simple tonal bleeps; the choice is yours.
Over to You
Well, that is the end of my bit, but it is not the end of this project. here are many changes,
enhancements and improvements you can make. his applies to both the single- and two-
player version of the game. he simplest involves changing the colours: You might want
Search WWH ::




Custom Search