|
41.
|
|
|
start_moving_right: the user pressed the "f" key
|
|
|
|
(no translation yet)
|
|
|
|
Located in
data/templates/ubuntu-pygame/help/tutorial.xml:145(listitem)
|
|
42.
|
|
|
stop_moving_right: the user released the "f" key
|
|
|
|
(no translation yet)
|
|
|
|
Located in
data/templates/ubuntu-pygame/help/tutorial.xml:146(listitem)
|
|
43.
|
|
|
Create two tracking variables, _moving_left and _moving_right
|
|
|
|
(no translation yet)
|
|
|
|
Located in
data/templates/ubuntu-pygame/help/tutorial.xml:150(listitem)
|
|
44.
|
|
|
Set these tracking variables to True or False in the start/stop_moving_left/right functions
|
|
|
|
(no translation yet)
|
|
|
|
Located in
data/templates/ubuntu-pygame/help/tutorial.xml:151(listitem)
|
|
45.
|
|
|
In the guy's update function, change the x coordinates of the guy based on these variables
|
|
|
|
(no translation yet)
|
|
|
|
Located in
data/templates/ubuntu-pygame/help/tutorial.xml:152(listitem)
|
|
46.
|
|
|
The functionaly that is specific to the player's sprite is in the guy.py file. The first thing we will do is work on placing the guy properly. Fortunately, the is an existing function that we can modify for this. The function init_position is called to each time the guy needs to be placed on the screen, like after he gets killed for instance . When created, the guy calls the based class function center_on_screen. As you may guess, we will want to change this function. so the guys is positionedhalfway down the screen, and we want him to start a few pixels from the bottom. Fortunaately we know how to get the screen dimensions, so it's easy make the change to init_position. <placeholder-1/> Now when you run the game, the guy starts at the bottom, which is what we want, but he also rotates when we use the s and the d button, which we do not want. So let's change that next by implementing four new functions: <placeholder-2/> Here's how we will implement these functions: <placeholder-3/>
|
|
|
|
(no translation yet)
|
|
|
|
Located in
data/templates/ubuntu-pygame/help/tutorial.xml:126(para)
|
|
49.
|
|
|
First, add the tracking variables to the Guy.__init__function. Add these after the call to BaseSprite.__init__(). <placeholder-1/> Now the functions for responding to keys simply set those tracking variables as appropriate. So we add these four new functions to guy.py. <placeholder-2/>
|
|
|
|
(no translation yet)
|
|
|
|
Located in
data/templates/ubuntu-pygame/help/tutorial.xml:156(para)
|
|
50.
|
|
|
Now we need change the guy's coordinates based on the tracking variable. Every sprite has an update function. This function is called for every "tick" in the game, and the sprite looks at it's internal data, and updates itself appropriately. By default, the guy's rotation is handled by BaseSprite, so we can ignore that, especially since we won't be using rotation anyway. We're also not using acceleration for the guy, so we can delete a bit of code. Funally, we don't want the guy to "wrap" though the screen, so we whould catch that condition.
|
|
|
|
(no translation yet)
|
|
|
|
Located in
data/templates/ubuntu-pygame/help/tutorial.xml:181(para)
|
|
51.
|
|
|
def update(self):
"""update - Update internal data for a game tick"""
BaseSprite.update(self)
if self._moving_left:
self.x -= 5
if self.x < 0:
self.x = 0
if self._moving_right:
self.x += 5
if self.x + self.rect.width > shooterconfig.screen_width:
self.x = shooterconfig.screen_width - self.rect.width
|
|
|
represents a line break.
Start a new line in the equivalent position in the translation.
|
|
|
represents a space character.
Enter a space in the equivalent position in the translation.
|
|
|
|
(no translation yet)
|
|
|
|
Located in
data/templates/ubuntu-pygame/help/tutorial.xml:186(programlisting)
|
|
52.
|
|
|
Let's start with moving the guy 5 pixels per tick. So we can change the top of the update function to look like this: <placeholder-1/>
|
|
|
|
(no translation yet)
|
|
|
|
Located in
data/templates/ubuntu-pygame/help/tutorial.xml:184(para)
|