From bb13d19a05729a44a14bff6cd03f7fa66d2787eb Mon Sep 17 00:00:00 2001 From: Daniel Drake Date: Sun, 31 Aug 2008 19:31:10 +0000 Subject: SOUNDS!!!! --- 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 + diff --git a/sounds/death.wav b/sounds/death.wav new file mode 100644 index 0000000..7e37639 --- /dev/null +++ b/sounds/death.wav Binary files differ diff --git a/sounds/startup.wav b/sounds/startup.wav new file mode 100644 index 0000000..79fefa6 --- /dev/null +++ b/sounds/startup.wav Binary files differ diff --git a/sounds/wooo.wav b/sounds/wooo.wav new file mode 100644 index 0000000..c1864d4 --- /dev/null +++ b/sounds/wooo.wav Binary files differ -- cgit v0.9.1