Hardware Reference
In-Depth Information
his ensures that the sound is produced as soon as possible after the software command is
given. Without this there is an unacceptable delay, which is sometimes called latency. You
need to create a sound ile in the .ogg format with a sample rate of 22.05 KHz; call it
bounce.ogg and place it inside a folder called sounds . his sounds folder should be placed
in the same folder as the Python code. A short blip sound will do for now. If you like, you can
look inside the Python games folder at some of the sound iles that are there; you can copy
and rename beep.ogg , for example, here. I use the application Audacity for creating sound
iles. It is free, and there are versions that run on Windows machines or Macs.
A Single-Player Game
he next step produces a usable single-player game, complete with scoring. he point of a
single-player game is to see how many times you can return the ball from a perfect computer
player. You get three balls, and the number of returns you make from those balls is your score.
If it is the highest one of the session, it is transferred to the left number, and that is the one to
beat next time. here are a few steps in going from the simple bounce around a box to the sin-
gle player, but space in the topic restricts me from going through all the intermediate stages.
he chief change is that you no longer need to look at just a single value to detect a collision
because a bat also has a limited length; you need to see if the ball is sailing over the top or under-
neath it. he top and bottom collisions are still the same, though. here are a few shortcuts I
have taken to simplify the detection of a collision with a ball as opposed to a rectangle. Figure 5-6
shows the dimensions of the bat and ball. For the detection of a collision, you can consider just
the bounding box of the circular ball and not worry about the actual geometry of the circle.
Figure 5-6:
Measurements
for the bat
and ball.
Search WWH ::




Custom Search