Teach Your Kids To Code: A Parent-friendly Guide to Python Programming
Game Programming: Coding for Fun 235 But we’re not going to draw this rectangle yet. Those variables would be enough to draw a r ...
236 Chapter 10 the bottom of the screen. Our next task is to add logic to make the ball bounce off the paddle and gain points, a ...
Game Programming: Coding for Fun 237 To add the logic for subtracting a life when the ball hits the bottom of the screen, we hav ...
238 Chapter 10 (picx, picy) (paddlex, paddley) (paddlex, paddley) paddlew (picw/2) (picw/2) (picx, picy) Figure 10-4: Two collis ...
Game Programming: Coding for Fun 239 is picx + picw/2, to be less than or equal to the top-right corner of the paddle, whose x-c ...
240 Chapter 10 There’s just one more condition to check. Remember that the ball and paddle are virtual; that is, they don’t exis ...
Game Programming: Coding for Fun 241 if picx + picw/2 >= paddlex and picx + picw/2 <= paddlex + \ paddlew: points += 1 spe ...
242 Chapter 10 The first step is putting together the string of text that we want to display. In a typical video game, we’d see ...
Game Programming: Coding for Fun 243 same goes for larger fonts versus smaller fonts. The text string will be rendered on a rect ...
244 Chapter 10 pic = pygame.image.load("CrazySmile.bmp") colorkey = pic.get_at((0,0)) pic.set_colorkey(colorkey) picx = 0 picy = ...
Game Programming: Coding for Fun 245 if picx + picw / 2 >= paddlex and picx + picw / 2 <= paddlex + \ paddlew: points += 1 ...
246 Chapter 10 Game Over Version 1.0 never stopped playing because we didn’t add logic to handle the game being over. We know th ...
Game Programming: Coding for Fun 247 F1 key (pygame.K_F1). The code that follows this second if statement will be our play again ...
248 Chapter 10 detection (where we make the ball bounce back from each edge of the screen) to the following: if picx <= 0 or ...
Game Programming: Coding for Fun 249 all of their remaining lives on a single bounce off the bottom edge. This is because the ba ...
250 Chapter 10 Putting It All Together Here’s our finished version 2.0, SmileyPong2.py. At just under 80 lines of code, it’s a f ...
Game Programming: Coding for Fun 251 picx += speedx picy += speedy if picx <= 0 or picx >= 700: speedx = -speedx * 1.1 if ...
252 Chapter 10 You can continue to build on the game elements in this example (see “Programming Challenges” on page 261), or you ...
Game Programming: Coding for Fun 253 We begin by initializing the mixer (just like we initialize Pygame with pygame.init()). The ...
254 Chapter 10 make these changes and hear the result, make sure you’ve down- loaded the pop.wav sound file into the same folder ...
«
8
9
10
11
12
13
14
15
16
17
»
Free download pdf