~rick-rickspencer3/pygame-template/trunk

« back to all changes in this revision

Viewing changes to crashteroids/baseSprite.py

  • Committer: Rick Spencer
  • Date: 2010-03-13 17:14:36 UTC
  • Revision ID: rick.spencer@canonical.com-20100313171436-7q76ajghbacfprvz
made update_image a private function (_update_image). Completed documentation for BaseSprite.py

Show diffs side-by-side

added added

removed removed

Lines of Context:
49
49
        self.rect.height -= 5
50
50
        self.rect.width -= 5
51
51
 
52
 
        self.update_image()
 
52
        self._update_image()
53
53
 
54
54
 
55
55
    def __init_position(self):
56
56
        """init_position - initializes values for positioning, and provides 
57
57
        a default position implemention, places the sprite in the center of
58
 
        the screen.
 
58
        the screen. This is an internal implementation that centers the 
 
59
        sprite. Use the default public implementation for a default
 
60
        implementation to be called externally.
59
61
 
60
62
        """
61
63
 
120
122
        self._accelerating = False
121
123
  
122
124
    def update(self):
123
 
        """update - update internal data and position
 
125
        """update - update internal data and position.
 
126
        Typically called by the game controller each game
 
127
        tick.
124
128
 
125
129
        """
126
130
        #update the orientation
137
141
  
138
142
        #change the image if rotating
139
143
        if self._rotating_left or self._rotating_right:
140
 
            self.update_image()
 
144
            self._update_image()
141
145
  
142
146
        #adjust the velocity based on orientation
143
147
        up = 360/self.rotation_rate
192
196
  
193
197
        self.rect.topleft = [self.x,self.y]
194
198
  
195
 
    def update_image(self):
 
199
    def _update_image(self):
 
200
        """_update_image - internal function to manage updating
 
201
        a sprite's image. Maintains a master image to avoid image
 
202
        corruption after repeated rotations of the same image.        
 
203
 
 
204
        """
 
205
 
196
206
        oldCenter = self.rect.center
197
207
        self.image = pygame.transform.rotate(self.master_image,self.orientation)
198
208
        self.rect = self.image.get_rect()
202
212
        self.rect.center = oldCenter
203
213
 
204
214
    def explode(self):
 
215
        """explode - function called when a sprite is destroyed
 
216
        in game play. Default implentation calls kill() which 
 
217
        simply removes the sprite from play. Subclasses of baseSprite
 
218
        override explode to add explosion animations.
 
219
 
 
220
        """
 
221
 
205
222
        self.kill()#remove self from any spritegroups by default
206
223
 
207
224
    def init_position(self):
 
225
        """init_position - Typically called after a sprite is 
 
226
        created to place the sprite into game play. This defualt
 
227
        implementation places sprite randomly at the edges of the
 
228
        screen. Sublclasess override this function to determine
 
229
        other start positions. This function can be modified to
 
230
        create different default start position logic for all
 
231
        sprites in the game.
 
232
 
 
233
        """
 
234
 
208
235
        #leave room in the center for the guy
209
236
        sw = crashteroidsconfig.screen_width
210
237
        sh = crashteroidsconfig.screen_height
211
238
 
212
239
        quad = random.randint(0,3)
213
 
        print quad
214
240
        if quad == 0:
215
241
            #top left
216
242
            right_bound = sw/2 - 100