Teach Your Kids To Code: A Parent-friendly Guide to Python Programming
8 timers and animation: What Would Disney Do? One way that I learned to program in my teens was by programming short games and a ...
176 Chapter 8 Games and animations have several things in common. First, they’re fun! Second, they both involve drawing graphics ...
Timers and Animation: What Would Disney Do? 177 To get started, install the pygame module by downloading the installer from the ...
178 Chapter 8 Type the following in a new IDLE window or download it from http://www.nostarch.com/teachkids/: ShowDot.py import ...
Timers and Animation: What Would Disney Do? 179 how much red is in your color, the second number is the amount of green, and the ...
180 Chapter 8 You should see an image like the one in Figure 8-2 when you run ShowDot.py. Take some time to play around with thi ...
Timers and Animation: What Would Disney Do? 181 • The game loop is always used in Pygame. In our earlier pro- grams, we used ...
182 Chapter 8 As we build our ShowPic.py program, we’ll learn about the three main parts of a game or animation in Pygame. First ...
Timers and Animation: What Would Disney Do? 183 while keep_going: # Game loop for event in pygame.event.get(): u if event.type = ...
184 Chapter 8 In this case, we’ve told blit() that we want to draw pic at the loca- tion (100,100), or right 100 pixels and down ...
Timers and Animation: What Would Disney Do? 185 while keep_going: # Game loop for event in pygame.event.get(): if event.type == ...
186 Chapter 8 Figure 8-5: In this first attempt at animation, our smiley image will streak off the screen. We still call each dr ...
Timers and Animation: What Would Disney Do? 187 new version of the program as SmileyMove.py (the final version is shown on page ...
188 Chapter 8 Look back at Figure 8-5 for a glimpse of the smiley image before it slides out of view. This first version may lea ...
Timers and Animation: What Would Disney Do? 189 of frames per second our program draws. Currently, we’re moving the smiley image ...
190 Chapter 8 SmileyMove.py import pygame # Setup pygame.init() screen = pygame.display.set_mode([600,600]) keep_going = True pi ...
Timers and Animation: What Would Disney Do? 191 Figure 8-6: Our goal is to keep the smiley “bouncing” between the corners of the ...
192 Chapter 8 Let’s figure out what that value might be. We know our screen is 600 pixels wide because we created our screen wit ...
Timers and Animation: What Would Disney Do? 193 Our CrazySmile.bmp file measures 100 pixels across (and 100 pixels down). So if ...
194 Chapter 8 Changing direction “Bouncing” off the edge of the screen means going in the oppo- site direction after hitting tha ...
«
6
7
8
9
10
11
12
13
14
15
»
Free download pdf