Game Development Reference
In-Depth Information
20 - Dodger
is a color for the background. However, the line windowSurface.fill
(BACKGROUNDCOLOR) is not as clear what the argument being passed means.
We can also easily change some simple aspects about our game without having the
change much of the code by changing the values stored in these constant variables. By
changing WINDOWWIDTH on line 4, we automatically change the code everywhere
WINDOWWIDTH is used. If we had used the value 600 instead, then we would have to
change each occurrence of 600 in the code. This would be especially confusing because
600 would also be used for the height of the window as well, and we would not want to
change those values.
4. WINDOWWIDTH = 600
5. WINDOWHEIGHT = 600
6. TEXTCOLOR = (255, 255, 255)
7. BACKGROUNDCOLOR = (0, 0, 0)
Here we set the height and width of the main window. Since the rest of our code works
off of these constant variables, changing the value here will change it everywhere in our
program.
Instead of storing color tuples into a variable named WHITE or BLACK , we will use
constant variables for the color of the text and background. Remember that the three
integers in the color tuples range from 0 to 255 and stand for red, green, and blue.
8. FPS = 40
Just so the computer does not run the game too fast for the user to handle, we will call
mainClock.tick() on each iteration of the game loop to slow it down. We need to
pass an integer to mainClock.tick() so that the function knows how long to pause the
program. This integer will be the number of frames per second we want the game to run. A
"frame" is the drawing of graphics on the screen for a single iteration through the game
loop. We will set up a constant variable FPS to 40 , and always call mainClock.tick
(FPS) . You can change FPS to a higher value to have the game run faster or a lower value
to slow the game down.
9. BADDIEMINSIZE = 10
10. BADDIEMAXSIZE = 40
11. BADDIEMINSPEED = 1
12. BADDIEMAXSPEED = 8
13. ADDNEWBADDIERATE = 6
Here we set some more constant variables that will describe the falling baddies. The
width and height of the baddies will be between BADDIEMINSIZE and
BADDIEMAXSIZE . The rate at which the baddies fall down the screen will be between 377
Search WWH ::




Custom Search