3
"Project-Id-Version: PACKAGE VERSION\n"
4
"Report-Msgid-Bugs-To: \n"
5
"POT-Creation-Date: 2011-04-04 08:43-0400\n"
6
"PO-Revision-Date: 2011-04-05 03:53+0000\n"
7
"Last-Translator: Michael Terry <michael.terry@canonical.com>\n"
8
"Language-Team: LANGUAGE <LL@li.org>\n"
10
"Content-Type: text/plain; charset=UTF-8\n"
11
"Content-Transfer-Encoding: 8bit\n"
12
"X-Launchpad-Export-Date: 2011-04-06 04:42+0000\n"
13
"X-Generator: Launchpad (build 12559)\n"
15
#: data/templates/ubuntu-pygame/help/tutorial.xml:13(firstname)
19
#: data/templates/ubuntu-pygame/help/tutorial.xml:14(surname)
23
#: data/templates/ubuntu-pygame/help/tutorial.xml:16(corpauthor)
27
#: data/templates/ubuntu-pygame/help/tutorial.xml:20(date) data/templates/ubuntu-pygame/help/tutorial.xml:25(invpartnumber)
31
#: data/templates/ubuntu-pygame/help/tutorial.xml:0(application)
32
msgid "Quickly PyGame Template"
35
#: data/templates/ubuntu-pygame/help/tutorial.xml:24(productnumber)
39
#: data/templates/ubuntu-pygame/help/tutorial.xml:26(title)
40
msgid "<application>Quickly PyGame Template</application> 0.6.1 Tutorial"
43
#: data/templates/ubuntu-pygame/help/tutorial.xml:31(title)
44
msgid "About This Guide"
45
msgstr "Maidir leis an treoir"
47
#: data/templates/ubuntu-pygame/help/tutorial.xml:32(para)
49
"Use <application>The Quickly Pygame Template</application> to write old "
50
"school arcade games for running on Ubuntu. PyGame is a framework that "
51
"handles sprites, collisons, sounds, and everything you need to make a game. "
52
"You just need to add the game play. The Quickly template creates a starter "
53
"game for you and comes ready for you to turn into your fun game, and then "
54
"easily package and share it with other Ubuntu users."
57
#: data/templates/ubuntu-pygame/help/tutorial.xml:35(para)
59
"The Quickly Pygame Template inherits from the Quickly Application template. "
60
"So you get all the commands that you get from the that template, except "
64
#: data/templates/ubuntu-pygame/help/tutorial.xml:41(title)
65
msgid "Creating and Running Your Game"
68
#: data/templates/ubuntu-pygame/help/tutorial.xml:44(para)
70
"In this tutorial we will start making a top down shooter reminiscent of the "
71
"space arcade shooters of the 1980s."
74
#: data/templates/ubuntu-pygame/help/tutorial.xml:50(para)
76
"We'll do this by creating a default game, editing some of the generated "
77
"code, writing some new code, and adding our images for sprits."
80
#: data/templates/ubuntu-pygame/help/tutorial.xml:53(para)
82
"Creating a default working game couldn't be simpler. First, open a terminal "
83
"window to type commands into. When it's open, type the command:"
86
#: data/templates/ubuntu-pygame/help/tutorial.xml:56(programlisting)
90
"$quickly create ubuntu-pygame shooter\n"
94
#: data/templates/ubuntu-pygame/help/tutorial.xml:60(para)
96
"This will create a shooter sub directory containing a complete directory "
97
"tree and files for an empty python application. The command finishes by "
98
"running the newly created game. The game is played by using the \"s\" and "
99
"\"f\" keys to rotate the guy, the \"j\" key to shoot, and the \"l\" key to "
103
#: data/templates/ubuntu-pygame/help/tutorial.xml:63(para)
105
"You can play the newly created game. Notice that the <application>Quickly "
106
"PyGame Template</application> inferred that the game title is \"Shooter\". "
107
"Also note that there is a guy that you can control with the s,f,j, and l "
108
"keys. There is an enemy and a homing missle. You also get a \"Game Over\" "
109
"screen, scoring, and levels build in for free."
112
#: data/templates/ubuntu-pygame/help/tutorial.xml:66(para)
114
"Close the game by closing the window or using the Esc key. Since the game "
115
"isn't installed into Ubuntu yet, you can't start the game from the "
116
"application menu yet. To start the game, use the terminal to first cd into "
117
"the new subdirectory, and then use \"quickly run\" to start the program."
120
#: data/templates/ubuntu-pygame/help/tutorial.xml:69(programlisting)
129
#: data/templates/ubuntu-pygame/help/tutorial.xml:75(title)
130
msgid "Creating your own Sprites"
133
#: data/templates/ubuntu-pygame/help/tutorial.xml:79(listitem)
135
"Ink Scape is a great and free tool for creating your sprites. It's in the "
136
"Featured Applications section of the Software Center."
139
#: data/templates/ubuntu-pygame/help/tutorial.xml:80(listitem)
141
"If you use Ink Scape, you'll want to export the images as PNGs. But keep the "
142
"Ink Scape files around in case you want to edit the sprites later."
145
#: data/templates/ubuntu-pygame/help/tutorial.xml:81(listitem)
147
"Whatever size you make the sprites, that's the size they will be in the game."
150
#: data/templates/ubuntu-pygame/help/tutorial.xml:82(listitem)
152
"The game will look for sprites in the data/media folder, so make sure you "
156
#: data/templates/ubuntu-pygame/help/tutorial.xml:76(para)
158
"The first think you probably noticed about the game is that the graphics are "
159
"so blah! Let's start by adding our own sprites. We;ll do a compbination of "
160
"replacing sprites with our own images, and also add a new sprite which we'll "
161
"use later. Here's a few things to keep in mind: <placeholder-1/>"
164
#: data/templates/ubuntu-pygame/help/tutorial.xml:85(para)
166
"I made new images for the guy (the sprite the player controls), enemies, "
167
"bullets, and the game background. I also made a new sprite called "
168
"\"enemy_bullet.png\" which we'll add into the game later. <placeholder-1/> "
169
"Just drag your new sprite images into the shooter/data/media and tell it to "
170
"replace the images. Now when you run the game, you'll see your new sprites "
171
"at work. <placeholder-2/> Oops. As you can see, the background image I "
172
"created was for a game of different dimensions. It's for a game that's 400 "
173
"pixels wide by 500 pixels high. In the next section, we'll make the game "
177
#: data/templates/ubuntu-pygame/help/tutorial.xml:98(title)
178
msgid "Changing the Screen Dimensions"
181
#: data/templates/ubuntu-pygame/help/tutorial.xml:99(para)
183
"The first change we'll make is to change the screen dimensions to be "
184
"oriented from top to bottom. We do this by changing a little code. So let's "
185
"fire up the code editor first. Run the edit command to fire up the editor."
188
#: data/templates/ubuntu-pygame/help/tutorial.xml:102(programlisting)
190
msgid "$quickly edit"
193
#: data/templates/ubuntu-pygame/help/tutorial.xml:104(programlisting)
197
"#screen dimensions\n"
198
"screen_width = 400\n"
199
"screen_height = 500\n"
202
#: data/templates/ubuntu-pygame/help/tutorial.xml:103(para)
204
"This command should open your code in Gedit. The screen dimensions are set "
205
"in the file \"shooterconfig.py\". So just go to that file and change the "
206
"width to 400 and the height to 500. <placeholder-1/> Save the file and run "
207
"the game again. Notice that the screen wrapping and centering and everything "
208
"was taken care of for you. That's because you made the change in the "
209
"shooterconfig.py file. This is the right place to add and change variables "
210
"that should be availble throughout the game. We'll be make a few more "
211
"changes here later."
214
#: data/templates/ubuntu-pygame/help/tutorial.xml:114(title)
215
msgid "Programming the Guy"
218
#: data/templates/ubuntu-pygame/help/tutorial.xml:115(para)
220
"For this game, what we want is the guy to move left and right across the "
221
"bottom and not wrap through the screen. Also, we want to make the bullets "
222
"look like they are coming out of the guy's front."
225
#: data/templates/ubuntu-pygame/help/tutorial.xml:121(listitem)
227
"Place the guy at the beginning of each level at the middle and bottom of the "
231
#: data/templates/ubuntu-pygame/help/tutorial.xml:122(listitem)
233
"Add functions to guy.py for moving and stop movig right and left, and remove "
234
"the rotate functions."
237
#: data/templates/ubuntu-pygame/help/tutorial.xml:123(listitem)
239
"Change the keyboard input in the bin/shooter file to call these new "
243
#: data/templates/ubuntu-pygame/help/tutorial.xml:118(para)
244
msgid "To make the guy move just left and right we need to: <placeholder-1/>"
247
#: data/templates/ubuntu-pygame/help/tutorial.xml:128(programlisting)
251
" def init_position(self):\n"
252
" \"\"\"init_position - resets the Guy's position near the\n"
253
" bottom of the screen\n"
256
" sw = shooterconfig.screen_width\n"
257
" sh = shooterconfig.screen_height\n"
260
" self.y = sh - 80\n"
263
#: data/templates/ubuntu-pygame/help/tutorial.xml:143(listitem)
264
msgid "start_moving_left: the user pressed the \"s\" key"
267
#: data/templates/ubuntu-pygame/help/tutorial.xml:144(listitem)
268
msgid "stop_moving_left: the user released the \"s\" key"
271
#: data/templates/ubuntu-pygame/help/tutorial.xml:145(listitem)
272
msgid "start_moving_right: the user pressed the \"f\" key"
275
#: data/templates/ubuntu-pygame/help/tutorial.xml:146(listitem)
276
msgid "stop_moving_right: the user released the \"f\" key"
279
#: data/templates/ubuntu-pygame/help/tutorial.xml:150(listitem)
280
msgid "Create two tracking variables, _moving_left and _moving_right"
283
#: data/templates/ubuntu-pygame/help/tutorial.xml:151(listitem)
285
"Set these tracking variables to True or False in the "
286
"start/stop_moving_left/right functions"
289
#: data/templates/ubuntu-pygame/help/tutorial.xml:152(listitem)
291
"In the guy's update function, change the x coordinates of the guy based on "
295
#: data/templates/ubuntu-pygame/help/tutorial.xml:126(para)
297
"The functionaly that is specific to the player's sprite is in the guy.py "
298
"file. The first thing we will do is work on placing the guy properly. "
299
"Fortunately, the is an existing function that we can modify for this. The "
300
"function init_position is called to each time the guy needs to be placed on "
301
"the screen, like after he gets killed for instance . When created, the guy "
302
"calls the based class function center_on_screen. As you may guess, we will "
303
"want to change this function. so the guys is positionedhalfway down the "
304
"screen, and we want him to start a few pixels from the bottom. Fortunaately "
305
"we know how to get the screen dimensions, so it's easy make the change to "
306
"init_position. <placeholder-1/> Now when you run the game, the guy starts at "
307
"the bottom, which is what we want, but he also rotates when we use the s and "
308
"the d button, which we do not want. So let's change that next by "
309
"implementing four new functions: <placeholder-2/> Here's how we will "
310
"implement these functions: <placeholder-3/>"
313
#: data/templates/ubuntu-pygame/help/tutorial.xml:158(programlisting)
317
" self._moving_left = False\n"
318
" self._moving_right = False\n"
321
#: data/templates/ubuntu-pygame/help/tutorial.xml:164(programlisting)
325
" def start_moving_right(self):\n"
326
" self._moving_left = False\n"
327
" self._moving_right = True\n"
329
" def start_moving_left(self):\n"
330
" self._moving_left = True\n"
331
" self._moving_right = False\n"
333
" def stop_moving_left(self):\n"
334
" self._moving_left = False\n"
336
" def stop_moving_right(self):\n"
337
" self._moving_right = False\n"
341
#: data/templates/ubuntu-pygame/help/tutorial.xml:156(para)
343
"First, add the tracking variables to the Guy.__init__function. Add these "
344
"after the call to BaseSprite.__init__(). <placeholder-1/> Now the functions "
345
"for responding to keys simply set those tracking variables as appropriate. "
346
"So we add these four new functions to guy.py. <placeholder-2/>"
349
#: data/templates/ubuntu-pygame/help/tutorial.xml:181(para)
351
"Now we need change the guy's coordinates based on the tracking variable. "
352
"Every sprite has an update function. This function is called for every "
353
"\"tick\" in the game, and the sprite looks at it's internal data, and "
354
"updates itself appropriately. By default, the guy's rotation is handled by "
355
"BaseSprite, so we can ignore that, especially since we won't be using "
356
"rotation anyway. We're also not using acceleration for the guy, so we can "
357
"delete a bit of code. Funally, we don't want the guy to \"wrap\" though the "
358
"screen, so we whould catch that condition."
361
#: data/templates/ubuntu-pygame/help/tutorial.xml:186(programlisting)
365
" def update(self):\n"
366
" \"\"\"update - Update internal data for a game tick\"\"\" \n"
368
" BaseSprite.update(self)\n"
370
" if self._moving_left:\n"
372
" if self.x < 0:\n"
374
" if self._moving_right:\n"
376
" if self.x + self.rect.width > shooterconfig.screen_width:\n"
377
" self.x = shooterconfig.screen_width - self.rect.width\n"
380
#: data/templates/ubuntu-pygame/help/tutorial.xml:184(para)
382
"Let's start with moving the guy 5 pixels per tick. So we can change the top "
383
"of the update function to look like this: <placeholder-1/>"
386
#: data/templates/ubuntu-pygame/help/tutorial.xml:202(para)
388
"So the guy is ready. He starts in the right place, tracks whether he is "
389
"moving left or right, and updates his position as desired. Now we just need "
390
"to hook him up the keys."
393
#: data/templates/ubuntu-pygame/help/tutorial.xml:205(para)
395
"Keyboard contol is handled in the shoort file in the bin directory. For each "
396
"click of the clock, the controller_tick function is called. Detecting "
397
"keyboard input and directing it as appropriate is handled in this funciton. "
398
"So what we wante to do is find where the f and s key events are handled, and "
399
"call the guy's start/stop_moving_left/right functions there."
402
#: data/templates/ubuntu-pygame/help/tutorial.xml:211(listitem)
403
msgid "Call the start_moving functions instead of rotate functions."
406
#: data/templates/ubuntu-pygame/help/tutorial.xml:212(listitem)
407
msgid "Remove the call to the accelerate function."
410
#: data/templates/ubuntu-pygame/help/tutorial.xml:213(listitem)
411
msgid "Remve the call to the hyperspace function."
414
#: data/templates/ubuntu-pygame/help/tutorial.xml:216(programlisting)
418
" #control the guy\n"
419
" if not game.paused: \n"
420
" if event.key == pygame.K_f:\n"
421
" g.start_moving_right()\n"
422
" if event.key == pygame.K_s:\n"
423
" g.start_moving_left()\n"
424
" if event.key == pygame.K_j:\n"
429
#: data/templates/ubuntu-pygame/help/tutorial.xml:208(para)
431
"Key down events are handled first, in a section commented \"control\" the "
432
"guy. We want to make a few changes here. <placeholder-1/> These last two "
433
"functions aren't needed for our new game. So let's make the changes and this "
434
"part of the controller_tick function will change to this: <placeholder-2/>"
437
#: data/templates/ubuntu-pygame/help/tutorial.xml:230(programlisting)
441
" #key up events, typically stop actions\n"
442
" if event.type == pygame.KEYUP:\n"
443
" if event.key == pygame.K_F11:\n"
444
" pygame.display.toggle_fullscreen() \n"
445
" if event.key == pygame.K_f:\n"
446
" g.stop_moving_right()\n"
447
" if event.key == pygame.K_s:\n"
448
" g.stop_moving_left()\n"
452
#: data/templates/ubuntu-pygame/help/tutorial.xml:228(para)
454
"We'll handle the key up functions similarly. <placeholder-1/><placeholder-2/>"
457
#: data/templates/ubuntu-pygame/help/tutorial.xml:248(listitem)
459
"The bullets accelerate and go way to fast, they'll miss enemies by skipping "
463
#: data/templates/ubuntu-pygame/help/tutorial.xml:249(listitem)
465
"The bullets should go to the top of the screen, and not stop before or wrap "
469
#: data/templates/ubuntu-pygame/help/tutorial.xml:250(listitem)
471
"The bullets should appear to come out of the middle of the guy, instead of "
475
#: data/templates/ubuntu-pygame/help/tutorial.xml:253(programlisting)
479
" self.max_velocity = 20\n"
480
" self.max_ticks = 20\n"
483
#: data/templates/ubuntu-pygame/help/tutorial.xml:258(programlisting)
487
" def update(self):\n"
488
" \"\"\"update - update internal data and position.\n"
489
" Typically called by the game controller each game\n"
494
" BaseSprite.update(self)\n"
496
" if self.y < 1:\n"
498
" if self.y == shooterconfig.screen_height:\n"
502
#: data/templates/ubuntu-pygame/help/tutorial.xml:282(programlisting)
506
" def shoot(self):\n"
507
" \"\"\"shoot - fire a bullet. Adds the bullet to the bullet sprite "
509
" If the maximum number of bullets premitted would be exceeded, \n"
510
" the bullet will not fire. If the guy is exploding, the guy will no\n"
516
" #only allow max numbe of bullets on the screen at a time\n"
517
" if len(self.bullets.sprites()) < self.max_bullets:\n"
518
" center_x = (self.x + self.rect.width / 2) - 3\n"
519
" b = Bullet(center_x,self.y,self.orientation)\n"
520
" self.bullets.add(b)\n"
523
#: data/templates/ubuntu-pygame/help/tutorial.xml:245(para)
525
"Now we've got the guy working the way we want, but we need to make a few "
526
"changes to to how the guy's bullets are working: <placeholder-1/> We'll "
527
"handle the first problem my changing the Bullet class in the bullet.py file. "
528
"The acceleration and speed of bullets in the game is configured in the "
529
"__init__ function of this file. The rate at whcih a bullet accelerates is "
530
"controlled by member variable acceleration_divisor. We won't need to change "
531
"that. However, the maximum speed a bullet will reach is defined ny "
532
"max_velocity, and the lifetme of the bullet is defined by max_ticks. Let's "
533
"make the bullets go slower, but last longer, by changing max_velocity to 20, "
534
"and max_ticks to 20 in the Bullet __init__ funciton. <placeholder-2/> This "
535
"simple change is all that is necessary to control the bullets throughout the "
536
"game. Note that making this change in the Bullet class means all bullets in "
537
"the game, including enemy bullets, will now work this way. So let's quickly "
538
"deal with stopping bullets from wrapping as well. We'll add to the Bullet "
539
"class's update function to see if the bullet is above or below the screen, "
540
"and if so, we'll remove it. So we'll change the to of the update function in "
541
"bullet.py to look like this: <placeholder-3/> Note that a Sprite's kill "
542
"function, removes it from the game immediately, and with no fanfare. "
543
"Finally, we need to adjust the bullet so it comes out from the guys the way "
544
"we want it to. Since this is only related to the way the guy shoots bullets "
545
"and won't have anything to do with enemy bullets, we'll configure how "
546
"bullets emerge in the guy.py file. Let's just tweak the shoot function a "
547
"bit. As you can see in this function, when you create a bullet, you provide "
548
"it x and y coordinates. We'll just calculate at better x coordinate to "
549
"start. We'll find the middle of the width of the guy's image, and offset it "
550
"a bit so the bullet sprite looks like it comes out correctly. "
551
"<progamlisting> center_x = (self.x + self.rect.width / 2) - 3 "
552
"</progamlisting> So we change change the ugy's shoot funciton to look like "
553
"this: <placeholder-4/>"
556
#: data/templates/ubuntu-pygame/help/tutorial.xml:299(para)
558
"<placeholder-1/> Now we have the guy working as desired. Moves back and "
559
"forth across the bottom and shoots bullets the way we want. Next we'll go on "
560
"to changing the way the enemies work."
563
#: data/templates/ubuntu-pygame/help/tutorial.xml:308(title)
564
msgid "Programming Enemies"
567
#: data/templates/ubuntu-pygame/help/tutorial.xml:309(para)
569
"The generated game always adds two enemies for each level, a homing missle "
570
"and a stock \"enemy\". The homing missle does pretty much what's it name "
571
"suggests, homes in on the guy and kills him. The Enemy doesn't do much of "
572
"anything. Just kind of plunks down and waits to get killed. First we're "
573
"going to remove the homing missle from the game, and then we'll customize "
574
"the enemies to be a bit more menancing."
577
#: data/templates/ubuntu-pygame/help/tutorial.xml:314(programlisting)
581
" #TODO: set up enemies here\n"
582
" #You can add more enemies or use different enemies\n"
583
" #depening on the level\n"
584
" for i in xrange(0,game.level + 3):\n"
585
" enemies.add(Enemy())\n"
588
#: data/templates/ubuntu-pygame/help/tutorial.xml:312(para)
590
"The bin/shooter fileset up a SpriteGroup already. It's called \"enemies\" "
591
"and gets populated each time a new level is created. New levels are created "
592
"in the next_level function in the bin/shooter file. The next_level function "
593
"is pretty simple, it increments the game level bu 1, removes any remaining "
594
"emenemities for the SpriteGroup and then repulates the enemies SpriteGroup. "
595
"Let's make a couple of basic chagnnges here. First, we'll change the xrange "
596
"so that it creates more enemies with each level, and second, we'll just "
597
"delete the line that creates the homing missle. Change the next_level "
598
"function to make the last few lines as below. <placeholder-1/> So for the "
599
"first level, there will by for enemies, and each time there is an new level "
600
"created the number of enemies will increase by 1. Aslo, no more homing "
601
"missles. <placeholder-2/>"
604
#: data/templates/ubuntu-pygame/help/tutorial.xml:326(para)
606
"However, there are two things we need to do to enhance the game play with "
607
"our enemies. First, as you can see, they can start quite close to the guy, "
608
"even under. We'll need to fix that. Also, we should put them in motion so "
609
"they are a bit more of a challenge to shoot. We'll do both of the things by "
610
"modifying the Enemy class in the enemy.py file. Specifically in the "
611
"init_postion function."
614
#: data/templates/ubuntu-pygame/help/tutorial.xml:329(para)
616
"If you open the enemy.py file and look for the init_position function, "
617
"you'll see there is a call to the function in __init__ but there is no "
618
"function for it. That's because enemy inherits from BaseSprite, which has a "
619
"default init_position implementation that randomly places it on the screen. "
620
"So we'll simply override the init_position function in the Enemy class in "
624
#: data/templates/ubuntu-pygame/help/tutorial.xml:334(programlisting)
628
" sh = shooterconfig.screen_height\n"
629
" sw = shooterconfig.screen_width\n"
632
#: data/templates/ubuntu-pygame/help/tutorial.xml:339(programlisting)
639
#: data/templates/ubuntu-pygame/help/tutorial.xml:343(programlisting)
643
" self.x = random.randint(20,sw - self.rect.width - 20)\n"
644
" self.y = random.randint(20,sh/2)\n"
647
#: data/templates/ubuntu-pygame/help/tutorial.xml:348(programlisting)
651
" self.velocity_x = random.randint(-30,30)\n"
654
#: data/templates/ubuntu-pygame/help/tutorial.xml:352(programlisting)
658
" def init_position(self):\n"
659
" sh = shooterconfig.screen_height\n"
660
" sw = shooterconfig.screen_width\n"
662
" self.x = random.randint(20,sw - self.rect.width - 20)\n"
663
" self.y = random.randint(20,sh/2)\n"
664
" self.velocity_x = random.randint(-30,30)\n"
667
#: data/templates/ubuntu-pygame/help/tutorial.xml:332(para)
669
"First, to make it a bitter easier to code, grab a reference to the screen "
670
"height and widgth that you configured and keep those in easier to use "
671
"variables. <placeholder-1/> Next, we want to choose random start position "
672
"along the X axis. But we don't want the enemy to start too close to either "
673
"side or it might get stuck in a spot where the guy can't shoot it. To "
674
"generate random integers, use the randome module, so you'll have to add an "
675
"import to the top of the file. <placeholder-2/> We can use the screenwidth "
676
"to and the enemies own width to determine the right most starting position. "
677
"For the Y axis, we want the enemies to be far enough away that they can't "
678
"too easily kill the guy. We'll also make sure they don't get out of reach of "
679
"the guy's bullets. So between 20 and half way down seems about right. "
680
"<placeholder-3/> Finally, let's put each enemy in motion by picking a random "
681
"velocity_x within some reasonable bounds. <placeholder-4/> Notice that one "
682
"in 60 of the enemies won't be moving. That's okay because we added padding "
683
"to keep the enemies from ending up too close to the sides. The full "
684
"init_position function you need to add looks like this: <placeholder-5/> "
685
"When you run the game, you can see that the enemies are moving and are good "
686
"targets to shoot at. But next we'll make the enemies fight back."
689
#: data/templates/ubuntu-pygame/help/tutorial.xml:366(listitem)
690
msgid "Figure out where to place the bullet on the screen"
693
#: data/templates/ubuntu-pygame/help/tutorial.xml:367(listitem)
694
msgid "Configure the bullet's velocity and maximum speed"
697
#: data/templates/ubuntu-pygame/help/tutorial.xml:368(listitem)
698
msgid "Create the bullet object and add it to a SpriteGroup"
701
#: data/templates/ubuntu-pygame/help/tutorial.xml:371(programlisting)
705
"#create the player's guy and some enemies\n"
706
"bullets = pygame.sprite.RenderUpdates()\n"
708
"enemies = pygame.sprite.RenderUpdates()\n"
709
"enemy_bullets = pygame.sprite.RenderUpdates()\n"
712
#: data/templates/ubuntu-pygame/help/tutorial.xml:380(listitem)
714
"Clear out all the sprites in the group when creating a new level or "
715
"resetting a level after the guy dies."
718
#: data/templates/ubuntu-pygame/help/tutorial.xml:381(listitem)
720
"Tell the bullets in the sprite group to update themselves at the right time."
723
#: data/templates/ubuntu-pygame/help/tutorial.xml:382(listitem)
724
msgid "Tell the bullets to draw themselves at the right time."
727
#: data/templates/ubuntu-pygame/help/tutorial.xml:383(listitem)
729
"Pass a reference to the sprite group to each enemy that is created, so it "
730
"can add it's bullets to the group."
733
#: data/templates/ubuntu-pygame/help/tutorial.xml:386(programlisting)
740
#: data/templates/ubuntu-pygame/help/tutorial.xml:390(programlisting)
744
"def update_sprites():\n"
745
" \"\"\"update_sprites - call update() for all sprites\"\"\"\n"
747
" bullets.update()\n"
748
" enemies.update() \n"
749
" enemy_bullets.update()\n"
752
#: data/templates/ubuntu-pygame/help/tutorial.xml:399(programlisting)
757
" enemies.draw(screen)\n"
758
" enemy_bullets.draw(screen)\n"
761
#: data/templates/ubuntu-pygame/help/tutorial.xml:405(programlisting)
765
" def __init__(self,enemy_bullets):\n"
766
" \"\"\"Creates an Enemy \"\"\"\n"
767
" self.enemy_bullets = enemy_bullets\n"
771
#: data/templates/ubuntu-pygame/help/tutorial.xml:412(programlisting)
775
" enemies.add(Enemy(enemy_bullets))\n"
778
#: data/templates/ubuntu-pygame/help/tutorial.xml:416(programlisting)
782
"from bullet import Bullet\n"
785
#: data/templates/ubuntu-pygame/help/tutorial.xml:421(programlisting)
789
" def shoot(self):\n"
791
" b = Bullet(self.x,self.y, 180)\n"
792
" b.max_velocity = 6\n"
793
" b.max_ticks = 50\n"
794
" self.enemy_bullets.add(b)\n"
797
#: data/templates/ubuntu-pygame/help/tutorial.xml:431(programlisting)
801
" if not game.paused:\n"
802
" for e in enemies:\n"
803
" if random.randint(0,20) == 1:\n"
807
#: data/templates/ubuntu-pygame/help/tutorial.xml:441(programlisting)
811
"enemy_bullet_image = image_path + \"enemy_bullet.png\"\n"
814
#: data/templates/ubuntu-pygame/help/tutorial.xml:445(programlisting)
818
" def shoot(self):\n"
820
" img = shooterconfig.enemy_bullet_image\n"
821
" b = Bullet(self.x,self.y, 180, img)\n"
822
" b.max_velocity = 6\n"
823
" b.max_ticks = 50\n"
824
" self.enemy_bullets.add(b)\n"
827
#: data/templates/ubuntu-pygame/help/tutorial.xml:363(para)
829
"Let's add the ability for an enemy to drop a bomb. By default, enemies can't "
830
"do anything like that, so we'll have to add a new function. The function "
831
"will need to do the following things: <placeholder-1/> We should probably "
832
"start with this last part. We'll want to create a special sprite group for "
833
"the bullets to go into. This is primarily so that we can use the "
834
"SpriteGroups collision detection capabilities later. Also it's easier to "
835
"manage updates of sprites when they are in a group. First things first, "
836
"we'll create the sprite group. There's a place in the bin/shooter for "
837
"setting up enemies and such, so create another sprite group there. You "
838
"create a sprite group by calling a function in the pygame.sprite module "
839
"called \"RenderUpdates\". Lookk for the code block below, and notice the new "
840
"line creating the new sprite group by calling RenderUpdates. <placeholder-"
841
"2/> Now that we have the sprite group called enemy_bullets we want to do "
842
"three more things with it for now. <placeholder-3/> So for the first part, "
843
"we'll call the sprite group's empty function in next_level and reset_level "
844
"This function simply removes each sprite in the sprite group from game play. "
845
"Do this as the first thing for each of these function. <placeholder-4/> For "
846
"the second point, we'll add to the function in bin/shooter called "
847
"update_sprites. As you may have guessed, this function is called each tick "
848
"and tells each sprite to update. For sprites in a sprite group, this is "
849
"easy, because the SpriteGroup class includes an update function that calls "
850
"update for each of it's sprites. So just add that to the end of the "
851
"update_sprites function in bin/shooter, so it looks like the listing here: "
852
"<placeholder-5/> The view_tick function is called once per tick as well. "
853
"This funciton updates the view on the screen. We'll add a line of code to "
854
"tell the bullets to draw themselves right under where the enemies draw "
855
"themselves. <placeholder-6/> Finally, we need to pass a reference to each "
856
"enemy as it is created and create a member variable to store that reference. "
857
"So we need to make a change in the enemy.py fil, to add an argument for the "
858
"SpriteGroup in the __init__ function, and also we need to pass the "
859
"SpriteGroup when creating enemies. So change the Enemy class in enemy.py so "
860
"the top of the __init__ function looks like so: <placeholder-7/> And then "
861
"back in the bin/shooter file in the next_level function when creating "
862
"enemies, pass in enemy_bullets. <placeholder-8/> Now we have a functioning "
863
"sprite group and the enemies have a reference to it, we are ready to start "
864
"actually adding some bullets to it. We'll do this by adding a member "
865
"function called \"shoot\" to the enemy. Don't forget to import the Bullet "
866
"class into the enemy.py file. <placeholder-9/> First thing is we'll check "
867
"that the enemy is alive. We don't have to do this, but for this game, we "
868
"don't want it to shoot if it's int the process of exploding. Then we'll just "
869
"create a bullet and add it to the SpriteGroup. The last argument we'll pass "
870
"in is to set the orientatin to 180. Orientation goes clockwise for 360 "
871
"degrees, with zero being directly up, and 180 being directly down. In code, "
872
"it looks like the listing below. <placeholder-10/> So now we just need to "
873
"tell the enemies to shoot. We'll do this back in the bin/shooter file, in "
874
"the\"controller_tick function. After the section where we respond to "
875
"keyboard input, we'll add a few lines to make the enemies shoot. First, "
876
"we'll make sure the game is not paused, not very fair to shoot in a paused "
877
"game, is it? Next we'll loop through the enemies and desider if we should "
878
"call shoot. using our friend random.randint, we'll do this say, one time "
879
"twenty. So if you add this code to the end of the controller_tick function, "
880
"your enemies will start dropping bombs. <placeholder-11/><placeholder-12/> "
881
"So if you run the game, you'll see that the enemies are dropping bulltes "
882
"like bombs. Nice. However, maybe it would be nicer if the sprites for the "
883
"enemy bullets were different than the sprites for the guy's bullets. "
884
"Remember at the beginning of the tutorial we added an image called "
885
"enemy_bullet.png to the data/media directory. Now we'll write a bit of code "
886
"to use that image. First thing, we should add a reference to it in the "
887
"shooterconfig.py file. In this way, the Enemy class will be able to find it. "
888
"Just add the following line along with the other image path setting code in "
889
"shooterconfig.py. <placeholder-13/> So now we need to tell the bullets in "
890
"the Enemy class to use that image. Fortunately the Bullet class takes an "
891
"optional parameter for the name of an image to use. So just modify the shoot "
892
"function in the Enemy class to include the path. <placeholder-14/> Now the "
893
"enemies are dropping bombs with our new image. <placeholder-15/>"
896
#: data/templates/ubuntu-pygame/help/tutorial.xml:459(para)
898
"But of course, you many notice the bombs aren't too menancing. In the next "
899
"chapter we'll add collision detection to make the bombs kill the guy."
902
#: data/templates/ubuntu-pygame/help/tutorial.xml:464(title)
903
msgid "Collision Detection"
906
#: data/templates/ubuntu-pygame/help/tutorial.xml:465(para)
908
"Collision detection is when you check for sprites that are overlapping, and "
909
"run code based on what happened. PyGame makes this very easy by providing "
910
"some functions to check for overlapping sprites for you. As you will see, it "
911
"works for individual sprites as well as sprite groups."
914
#: data/templates/ubuntu-pygame/help/tutorial.xml:470(programlisting)
918
" b = pygame.sprite.spritecollideany(g, enemy_bullets)\n"
924
#: data/templates/ubuntu-pygame/help/tutorial.xml:481(programlisting)
928
" hits_dict = pygame.sprite.groupcollide(bullets, enemy_bullets, True, "
932
#: data/templates/ubuntu-pygame/help/tutorial.xml:468(para)
934
"Ok, so let's start by making the bombs that the enemies drop actually kill "
935
"the guy. To do this, we want to check if the bombs ever collide with the "
936
"guy, and if they do, we'll tell the guy to explode, and then we'll remove "
937
"the bomb from the screen. So the logic is \"tell me if the guy collides with "
938
"any enemy_bullets\". There is a funciton for this called, "
939
"pygame.sprite.spritecollideany, which takes a single sprite and a sprite "
940
"group and returns a reference to any sprite in the sprite group that "
941
"collided with the single sprite. If there were no collisions, than e will be "
942
"None. Otherwise, we'll want to tell the guy to explode and tell the bullet "
943
"to just \"kill\", which will remove it from play. So we can call it like "
944
"this: <placeholder-1/> There is a function in bin/shooter called "
945
"check_collisions which is called once per tick, and is the perfect place to "
946
"add this code. Add it right under the similar test for the guy colliding "
947
"with enemies. Now those bombs can kill the guys. <placeholder-2/> If you "
948
"play for a bit, you may notice that the bullets and the bombs just kind of "
949
"pass by each other. We can ramp up the game play by making the enemy bullets "
950
"destroy the guy's bullets, but not visa versa. So that logic here is, have "
951
"any of the sprites in the bullets sprite group collided with the bullets in "
952
"the enemy bullets sprite group. There is function for this as well, "
953
"pygame.sprite.groupcollide. groupcollide takes two sprite lists and returns "
954
"a dictionary. The keys in the dictionary are any sprites from the first "
955
"group that are involved in a collision, and the values are the sprites from "
956
"the second group that collided with the sprite that for key. It's a bit hard "
957
"to explain, but I bet the code is pretty readable. Add this line to the "
958
"check_collisions function. <placeholder-3/> Now if you run the game, it's a "
959
"bit more challenging as the enemies are a bit more offensive. This code just "
960
"kills the bullets involed in any collisions. Notice that I passed in True "
961
"False at the end of this function. These paramaters determine whether to "
962
"kill sprites form either group involved in the collusion. The True tells the "
963
"function to kill any bullets involved in collisions, so this was simple to "
967
#: data/templates/ubuntu-pygame/help/tutorial.xml:488(title)
968
msgid "Playing Sounds"
971
#: data/templates/ubuntu-pygame/help/tutorial.xml:491(programlisting)
975
"tink_sound = sound_path + \"tink.wav\" \n"
979
#: data/templates/ubuntu-pygame/help/tutorial.xml:495(programlisting)
983
"#set up some objects and models\n"
984
"tink_sound = pygame.mixer.Sound(shooter.shooterconfig.tink_sound) \n"
988
#: data/templates/ubuntu-pygame/help/tutorial.xml:500(programlisting)
992
" hits_dict = pygame.sprite.groupcollide(bullets, enemy_bullets, True, "
994
" if len(hits_dict) > 0:\n"
995
" tink_sound.play() \n"
999
#: data/templates/ubuntu-pygame/help/tutorial.xml:506(programlisting)
1003
" self.launch_sound = "
1004
"pygame.mixer.Sound(shooterconfig.guy_shoot_sound)\n"
1005
" self.launch_sound.set_volume(.2)\n"
1006
" self.launch_sound.play() \n"
1010
#: data/templates/ubuntu-pygame/help/tutorial.xml:489(para)
1012
"The game is pretty much done in terms of game play, but I want to make one "
1013
"small enhancement. When the enemy bullets kill one of the guy's bullets, I'd "
1014
"like to play a little sound to signify this. So first, I added a little "
1015
"\"tink\" sound to the data/media directory. After you add your sound, you "
1016
"need to add a reference to it in the shootercongif.py file. <placeholder-1/> "
1017
"Now, I want to add a little code after the collision detection between the "
1018
"bullets to play that sound if they collided. I can't just hop straight to "
1019
"that though, first I have to create a sound object.In pygame you manage "
1020
"sounds with the \"mixer\" module. I don't want to create this object over "
1021
"and over again. So I'll add it to the bin/shooter file where the other "
1022
"objects and such for the game are set up. <placeholder-2/> Now that I've "
1023
"told the mixer module to give me a sound, I can go ahead and check if there "
1024
"were any collisions between bullets, and play my sound. <placeholder-3/> So "
1025
"it seems to be working well, but what if you are finding that one of the "
1026
"sounds is too quiet or too loud? Or perhpas you want a certain sound to be "
1027
"loud sometimes and queit other times, for example to simulate distance. This "
1028
"is easy to do because each sound object has a set_volume function that you "
1029
"can use to set the sound between 0 (for slient) and 1 (for normal volume). "
1030
"The bullet launch sound I used was a bit loud, so in the bullet.py file, "
1031
"I'll adjust the Bullet class to play the sound a bit more quietly. "
1035
#: data/templates/ubuntu-pygame/help/tutorial.xml:514(title)
1039
#: data/templates/ubuntu-pygame/help/tutorial.xml:518(listitem)
1040
msgid "Creating a game using $quickly create ubuntu-pygame"
1043
#: data/templates/ubuntu-pygame/help/tutorial.xml:519(listitem)
1044
msgid "Adding your own sprites to the game"
1047
#: data/templates/ubuntu-pygame/help/tutorial.xml:520(listitem)
1048
msgid "Setting the screen size and other info in the config file"
1051
#: data/templates/ubuntu-pygame/help/tutorial.xml:521(listitem)
1052
msgid "Programming a player's guy to respond to keyboard input and to shoot"
1055
#: data/templates/ubuntu-pygame/help/tutorial.xml:522(listitem)
1056
msgid "Programming enemies to move and shoot"
1059
#: data/templates/ubuntu-pygame/help/tutorial.xml:523(listitem)
1060
msgid "Using collision detection to blow up Sprites"
1063
#: data/templates/ubuntu-pygame/help/tutorial.xml:524(listitem)
1064
msgid "Playing and adjusting sounds"
1067
#: data/templates/ubuntu-pygame/help/tutorial.xml:528(listitem)
1069
"The bullets that the guy shoots and the bombs that the enemies drop make the "
1070
"same sound, it would probably be nicer if they each made a different sounds."
1073
#: data/templates/ubuntu-pygame/help/tutorial.xml:529(listitem)
1075
"The default explosions are crayon drawings, they don't fit in much with the "
1076
"look of the game. Perhaps some new images for the explosion stages would be "
1080
#: data/templates/ubuntu-pygame/help/tutorial.xml:530(listitem)
1082
"There are no power ups! You could create power up classes the derive from "
1083
"BaseSprite to give the guy extra powers, like bigger bullets, more bullets, "
1087
#: data/templates/ubuntu-pygame/help/tutorial.xml:531(listitem)
1089
"More special enemies, for example you could use the HomingMissle class to "
1090
"create harder to kill enemies."
1093
#: data/templates/ubuntu-pygame/help/tutorial.xml:532(listitem)
1095
"The high score list is stored in desktopcouch, so it will sync with your "
1096
"other computers. But it will have to be adjusted to the size we set for the "
1097
"window, and perhaps you can also let the player choose the name that's "
1101
#: data/templates/ubuntu-pygame/help/tutorial.xml:515(para)
1103
"So now you have a working game! This tutorial introduced the following key "
1104
"concepts for using the Quickly PyGame Template. <placeholder-1/> But there "
1105
"is still a lot to do to have a propper game. For example: <placeholder-2/>"
1108
#. Put one translator per line, in the form of NAME <EMAIL>, YEAR1, YEAR2
1109
#: data/templates/ubuntu-pygame/help/tutorial.xml:0(None)
1110
msgid "translator-credits"
1112
"Launchpad Contributions:\n"
1113
" Michael Terry https://launchpad.net/~mterry"