Teach Your Kids To Code: A Parent-friendly Guide to Python Programming
User Interaction: Get into the Game 215 Advanced Interaction: Smiley Explosion One fun animation that my students and my sons en ...
216 Chapter 9 Pygame includes support for sprite graphics through its pygame .sprite.Sprite class. Remember from Chapter 8 that ...
User Interaction: Get into the Game 217 once we write a useful class for one programming project, we can often reuse that class ...
218 Chapter 9 screen = pygame.display.set_mode([800,600]) pygame.display.set_caption("Smiley Explosion") mousedown = False keep_ ...
User Interaction: Get into the Game 219 set up all the starting values we need in our sprite object. The two underscores on eith ...
220 Chapter 9 graphics without coding them from scratch. At v, we set the image of the sprite object (self.image) to the pic gra ...
User Interaction: Get into the Game 221 The update() function takes one parameter—the sprite object itself, self—and the code fo ...
222 Chapter 9 Putting It All Together Here’s our full SmileyExplosion.py app: SmileyExplosion.py import pygame import random BLA ...
User Interaction: Get into the Game 223 while keep_going: for event in pygame.event.get(): if event.type == pygame.QUIT: keep_go ...
224 Chapter 9 in every direction. In the final upgrade to this app, we’ll see an even more impressive and powerful feature of sp ...
User Interaction: Get into the Game 225 v elif pygame.mouse.get_pressed()[2]: # Right mouse button, pop w pos = pygame.mouse.get ...
226 Chapter 9 Putting It All Together Here’s the complete SmileyPop.py code. SmileyPop.py import pygame import random BLACK = (0 ...
User Interaction: Get into the Game 227 while keep_going: for event in pygame.event.get(): if event.type == pygame.QUIT: keep_go ...
228 Chapter 9 In our closing example, we added sprite-based collision detec- tion to see whether the user right-clicked the mous ...
User Interaction: Get into the Game 229 #2: Painting in Colors Let the user draw in two or more consistent colors using any of t ...
...
10 Game Programming: Coding for Fun In Chapter 9, we combined animation and user inter- action to make a fun app. In this chapte ...
232 Chapter 10 Games that we enjoy playing have certain elements of game design. Here is a breakdown of our Smiley Pong design: ...
Game Programming: Coding for Fun 233 Wikimedia Commons Figure 10-1: Atari’s famous Pong game from 1972 The gameplay for a single ...
234 Chapter 10 Figure 10-2: The Smiley Pong game we’ll build The first feature we’ll add to the former SmileyBounce2.py app is t ...
«
8
9
10
11
12
13
14
15
16
17
»
Free download pdf