Commits

Daniel Pope committed 0b3af64

New: sounds for all of the engines

Comments (0)

Files changed (8)

+Graphics and Programming - Daniel Pope
+
+Various sounds retrieved from OpenGameArt.org - attribution to follow

korovic/components/engines.py

 from .base import Component, ActivateableComponent
 from .squid import Slot
 
+from ..sound import load_sound
 from .. import loader
 
 
+class ActiveSound(object):
+    sound_channel = None
+    sound = None
+
+    def reset(self):
+        super(ActiveSound, self).reset()
+        self.on_stop()
+
+    def on_start(self):
+        if self.sound_channel is None:
+            self.sound_channel = self.sound.play(loops=-1, fade_ms=50)
+
+    def on_stop(self):
+        if self.sound_channel is not None:
+            self.sound_channel.fadeout(50)
+            self.sound_channel = None
+
+
 class OnAnimation(Component):
     abstract = True
     @classmethod
     FORCE = v(100000, 0)
     FUEL_CONSUMPTION = 6
     OFFSET = v(0, 0)
+    started = False
+
+    def on_start(self):
+        pass
+
+    def on_stop(self):
+        pass
 
     def update(self, dt):
+        ran = False
         if self.active:
             if self.squid.draw_fuel(self.FUEL_CONSUMPTION * dt):
+                if not self.started:
+                    self.on_start()
+                    self.started = True
+                ran = True
                 self.apply_force_relative(self.FORCE, self.OFFSET)
+        if not ran and self.started:
+            self.on_stop()
+            self.started = False
 
     def is_enabled(self):
         return self.squid.has_fuel()
         return AngleEditor(self)
 
 
-class JetEngine(OnAnimation, Engine):
+class JetEngine(ActiveSound, OnAnimation, Engine):
     """A jet engine."""
+    sound = load_sound('data/sounds/jet.wav')
 
 
 class Renderer(object):
         batch.draw()
             
 
-class Rocket(Engine):
+class Rocket(ActiveSound, Engine):
+    sound = load_sound('data/sounds/rocket.wav')
     @classmethod
     def load(cls):
         super(Rocket, cls).load()
         if not self.active:
             self.time_left = self.BURN_TIME
             self.active = True
+            self.on_start()
             
             # Stuff in any numbers for now, update later
             self.vel_domain = domain.Disc(
             if self.time_left > 0:
                 self.update_emitter(dt)
                 super(Rocket, self).update(dt)
+            else:
+                self.on_stop()
 
     def draw_particles(self):
         self.particlegroup.draw()
         super(Rocket, self).draw()
 
 
-class Propeller(OnAnimation, Engine):
+
+
+
+prop_sound = load_sound('data/sounds/prop.wav')
+
+class Propeller(ActiveSound, OnAnimation, Engine):
     MASS = 3
     slot_mask = Slot.TOP | Slot.BOTTOM | Slot.NOSE
     FORCE = v(45000, 0)
         Slot.NOSE: 0
     }
     FUEL_CONSUMPTION = 3
+    sound = prop_sound
 
     def set_angle(self):
         """Angle is not user modifiable"""
-
+    
     @property
     def angle(self):
         return self.angles[self.slot.flags]
         return SlotEditor(self)
 
 
-class PulseJet(Engine):
+class PulseJet(ActiveSound, Engine):
     MASS = 20
     slot_mask = Slot.TOP
     FORCE = v(40000, 0)
     FUEL_CONSUMPTION = 1
     OFFSET = v(0, 22)  # Offset of force from attachment point
+    sound = load_sound('data/sounds/pulsejet.wav')
 
     def editor(self):
         return AngleEditor(self, min_angle=-5, max_angle=30)
 
 
-class Rotor(OnAnimation, Engine):
+class Rotor(ActiveSound, OnAnimation, Engine):
     MASS = 30
     FORCE = v(0, 140000)
     OFFSET = v(0, 100)
     slot_mask = Slot.TOP
+    sound = load_sound('data/sounds/heli.wav')
 
     FUEL_CONSUMPTION = 5
 

korovic/data/sounds/heli.wav

Binary file added.

korovic/data/sounds/jet.wav

Binary file added.

korovic/data/sounds/prop.wav

Binary file added.

korovic/data/sounds/pulsejet.wav

Binary file added.

korovic/data/sounds/rocket.wav

Binary file added.

korovic/data/sounds/thruster.wav

Binary file added.