Changeset 99:f5d56688943b


Ignore:
Timestamp:
Sep 2, 2009, 12:50:28 PM (11 years ago)
Author:
David Fraser <davidf@…>
Branch:
default
Convert:
svn:b4e93282-eac8-4b8b-b765-0f5d36de2b68@100
Message:

Added background music support, and daytime and night time music (really animal sounds, not music)

Files:
2 added
4 edited

Legend:

Unmodified
Added
Removed
  • data/sounds/sources.txt

    r98 r99  
    4040ArchiveMember: ColetteBoulanger44/rooster.wav
    4141
     42[daytime.ogg]
     43URL: http://www.archive.org/download/Berklee44v6/Berklee44v6.zip
     44Source: http://www.archive.org/details/Berklee44v6
     45License: http://creativecommons.org/licenses/by/3.0/
     46Credit: Sound samples by Berklee recorded for Richard Boulanger for use in the One Laptop per Child music library. See http://wiki.laptop.org/go/Sound_samples for details.
     47ArchiveExtension: zip
     48ArchiveMember: Berklee44v6/animal_noises1.wav
     49
    4250[nightfall.ogg]
    4351URL: http://www.archive.org/download/Berklee44v6/Berklee44v6.zip
     
    4856ArchiveMember: Berklee44v6/dog1.wav
    4957OriginalFormat: mplayer
     58
     59[nighttime.ogg]
     60URL: http://www.archive.org/download/Berklee44v6/Berklee44v6.zip
     61Source: http://www.archive.org/details/Berklee44v6
     62License: http://creativecommons.org/licenses/by/3.0/
     63Credit: Sound samples by Berklee recorded for Richard Boulanger for use in the One Laptop per Child music library. See http://wiki.laptop.org/go/Sound_samples for details.
     64ArchiveExtension: zip
     65ArchiveMember: Berklee44v6/fakejungle1.wav
    5066
    5167[kill-chicken.ogg]
  • gamelib/engine.py

    r98 r99  
    4646    def init(self):
    4747        """Add some chickens to the farm"""
     48        sound.stop_background_music()
    4849        self.game.gameboard.tv.sun(True)
    4950
     
    5354        self.game.gameboard.clear_foxes()
    5455        self.game.gameboard.update_chickens()
     56        sound.background_music("daytime.ogg")
    5557
    5658    def event(self, e):
     
    8082    def init(self):
    8183        """Add some foxes to the farm"""
     84        sound.stop_background_music()
    8285        self.game.gameboard.tv.sun(False)
    8386
     
    8790        pygame.time.set_timer(MOVE_FOX_ID, 200)
    8891        self.game.gameboard.spawn_foxes()
     92        sound.background_music("nighttime.ogg")
    8993
    9094    def event(self, e):
  • gamelib/equipment.py

    r84 r99  
    22
    33import random
     4import sound
    45
    56class Equipment(object):
     
    2526    def hit(self, gameboard, wielder, target):
    2627        """Closer is more accurate."""
     28        sound.play_sound("fire-rifle.ogg")
    2729        return random.randint(1, 100) > 60 + 10*wielder.pos.dist(target.pos)
    2830
  • gamelib/sound.py

    r97 r99  
    3030    sound.play()
    3131
     32CURRENT_MUSIC_FILE = None
    3233
     34def stop_background_music():
     35    """stops any playing background music"""
     36    global CURRENT_MUSIC_FILE
     37    CURRENT_MUSIC_FILE = None
     38    # TODO: fadeout in a background thread
     39    pygame.mixer.music.stop()
     40
     41def background_music(filename):
     42    """plays the background music with the given filename from the data sounds directory"""
     43    global CURRENT_MUSIC_FILE
     44    if not SOUND_INITIALIZED:
     45        return
     46    file_path = data.filepath("sounds", filename)
     47    if CURRENT_MUSIC_FILE == file_path:
     48        return
     49    stop_background_music()
     50    if not os.path.exists(file_path):
     51        return
     52    CURRENT_MUSIC_FILE = file_path
     53    pygame.mixer.music.load(file_path)
     54    pygame.mixer.music.set_volume(0.3)
     55    pygame.mixer.music.play(-1)
     56
Note: See TracChangeset for help on using the changeset viewer.