Changeset 242

Show
Ignore:
Timestamp:
01/05/07 03:18:50 (5 years ago)
Author:
mg
Message:

Thruster sound effect.

Location:
trunk/src/pyspacewar
Files:
2 added
2 modified

Legend:

Unmodified
Added
Removed
  • trunk/src/pyspacewar/sounds/README.txt

    r239 r242  
    22http://www.partnersinrhyme.com/pir/PIRsfx.shtml 
    33 
    4 Grenade2.wav was produced from Grenade2.pcm with 
    5 mplayer Grenade2.au -ao pcm:file=Grenade2.wav 
     4Grenade2.wav and Pink_Noise1.wav were produced from the corresponding .au files 
     5with 
     6 
     7  mplayer Grenade2.au -ao pcm:file=Grenade2.wav 
     8  mplayer Pink_Noise1.au -ao pcm:file=Pink_Noise1.wav 
  • trunk/src/pyspacewar/ui.py

    r241 r242  
    19711971    def _load_sounds(self): 
    19721972        """Load bitmaps of planets.""" 
     1973        self.thruster_sound_playing = False 
     1974        self.thruster_sound = pygame.mixer.Sound(find('sounds', 
     1975                                                      'Pink_Noise1.wav')) 
     1976        self.thruster_sound.set_volume(0.5) 
    19731977        self.fire_sound = pygame.mixer.Sound(find('sounds', 
    19741978                                                  'Gun_Silencer.wav')) 
     
    21182122        pressed = pygame.key.get_pressed() 
    21192123        self.ui_mode.handle_held_keys(pressed) 
     2124        self.update_continuous_sounds() 
    21202125 
    21212126    def quit(self): 
     
    22902295        if not self.ai_controlled[player_id]: 
    22912296            self.respawn_sound.play() 
     2297 
     2298    def update_continuous_sounds(self): 
     2299        """Loop certain sound effects while certain conditions hold true.""" 
     2300        makes_noise = False 
     2301        for player_id, ship in enumerate(self.ships): 
     2302            if not self.ai_controlled[player_id]: 
     2303                makes_noise = (ship.forward_thrust or ship.rear_thrust or 
     2304                               ship.left_thrust or ship.right_thrust or 
     2305                               ship.engage_brakes) or makes_noise 
     2306        if self.thruster_sound_playing and not makes_noise: 
     2307            self.thruster_sound.stop() 
     2308        elif not self.thruster_sound_playing and makes_noise: 
     2309            self.thruster_sound.play(-1) 
     2310        self.thruster_sound_playing = makes_noise 
    22922311 
    22932312    def draw(self):