Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/bridge.py
diff options
context:
space:
mode:
authorDaniel Drake <dsd@laptop.org>2008-08-31 19:31:10 (GMT)
committer Daniel Drake <dsd@laptop.org>2008-08-31 19:31:10 (GMT)
commitbb13d19a05729a44a14bff6cd03f7fa66d2787eb (patch)
tree54ed363e7b9019a7bdf71d22561466a32ae07aa3 /bridge.py
parentc6764388bbdd3c053b9dd7d9a13ccb0aa6815ac0 (diff)
SOUNDS!!!!
Diffstat (limited to 'bridge.py')
-rw-r--r--bridge.py29
1 files changed, 26 insertions, 3 deletions
diff --git a/bridge.py b/bridge.py
index 08bdc00..6b0cf28 100644
--- a/bridge.py
+++ b/bridge.py
@@ -13,6 +13,7 @@ class Bridge:
self.train_off_screen = False
self.train_was_created = False
self.level_completed = False
+ self.sounds = {"wooo":loadSound("sounds/wooo.wav"), "death":loadSound("sounds/death.wav"), "startup":loadSound("sounds/startup.wav")}
def create_world(self):
self.world.set_color((100,150,50))
@@ -59,14 +60,19 @@ class Bridge:
pos = self.first_train.GetPosition()
if pos.x > 14.0:
- self.level_completed = True
+ if not self.level_completed:
+ self.level_completed = True
+ self.sounds['wooo'].play()
elif pos.y < 0.0:
- print "TRAIN FELL OFF!", pos.x
- self.train_off_screen = True
+ if not self.train_off_screen:
+ self.sounds['death'].play()
+ print "TRAIN FELL OFF!", pos.x
+ self.train_off_screen = True
def create_train(self, worldpoint = (-100,490), train = (100, 50), wheelrad = 20, cars = 3, force = False):
if not force and self.train_was_created:
return
+ self.sounds['startup'].play()
self.train_was_created = True
points = []
self.train_off_screen = False
@@ -107,3 +113,20 @@ class Bridge:
ftrain = self.world.get_bodies_at_pos(frontlink)
if len(ftrain) and len(btrain):
self.world.add.distanceJoint(btrain[0], ftrain[0], backlink, frontlink)
+
+# function for loading sounds (mostly borrowed from Pete Shinners pygame tutorial)
+def loadSound(name):
+ # if the mixer didn't load, then create an empy class that has an empty play method
+ # this way the program will run if the mixer isn't present (sans sound)
+ class NoneSound:
+ def play(self): pass
+ def set_volume(self): pass
+ if not pygame.mixer:
+ return NoneSound()
+ try:
+ sound = pygame.mixer.Sound(name)
+ except:
+ print "error with sound: " + name
+ return NoneSound()
+ return sound
+