Game Development Reference
In-Depth Information
20 - Dodger
After the player presses a key, the program execution will return from the
waitForPlayerToPressKey() call on line 198. Depending on how long the player
takes to press a key, the "game over" sound effect may or may not still be playing. We want
to stop this sound effect before this loop ends and we start a new game, so we have a call to
gameOverSound.stop() here.
Modifying the Dodger Game
That's it for our graphical game. You may find that the game is too easy or too hard. But
the game is very easy to modify because we took the time to use constant variables instead
of typing in the values directly. Now all we need to do to change the game is modify the
value set in the constant variables.
For example, if you want the game to run slower in general, change the FPS variable on
line 8 to a smaller value such as 20 . This will make both the baddies and the player's
character move slower since the game loop will only be executed 20 times a second instead
of 40.
If you just want to slow down the baddies and not the player, then change
BADDIEMAXSPEED to a smaller value such as 4 . This will make all the baddies move
between 1 (the value in BADDIEMINSPEED ) and 4 pixels per iteration through the game
loop instead of 1 and 8.
If you want the game to have fewer but larger baddies instead of many fast baddies, then
increase ADDNEWBADDIERATE to 12 , BADDIEMINSIZE to 40 , and BADDIEMAXSIZE
to 80 . Now that baddies are being added every 12 iterations through the game loop instead
of every 6 iterations, there will be half as many baddies as before. But to keep the game
interesting, the baddies are now much larger than before.
While the basic game remains the same, you can modify any of the constant variables to
drastically affect the behavior of the game. Keep trying out new values for the constant
variables until you find a set of values you like the best.
Summary: Creating Your Own Games
Unlike our previous text-based games, Dodger really looks like the kind of modern
computer game we usually play. It has graphics and music and uses the mouse. While
Pygame provides functions and data types as building blocks, it is you the programmer who
puts them together to create fun, interactive games.
And it is all because you know exactly how to instruct the computer to do it, step by step,
line by line. You can speak the computer's language, and get it to do large amounts of
number crunching and drawing for you. This is a very useful skill, and I hope you will
continue to learn more about Python programming. (And there is still more to learn!)
Here are several websites that can teach you more about programming Python:
Search WWH ::




Custom Search