Browse Source

*** empty log message ***

Mike Goslin 24 years ago
parent
commit
8f1605a30e
2 changed files with 57 additions and 0 deletions
  1. 1 0
      direct/src/interval/IntervalGlobal.py
  2. 56 0
      direct/src/interval/ParticleInterval.py

+ 1 - 0
direct/src/interval/IntervalGlobal.py

@@ -6,6 +6,7 @@ from ActorInterval import *
 from FunctionInterval import *
 from LerpInterval import *
 from MopathInterval import *
+from ParticleInterval import *
 from SoundInterval import *
 from WaitInterval import *
 

+ 56 - 0
direct/src/interval/ParticleInterval.py

@@ -0,0 +1,56 @@
+"""ParticleInterval module: contains the ParticleInterval class"""
+
+from PandaModules import *
+from Interval import *
+
+import BattleParticles
+
+class ParticleInterval(Interval):
+    # Name counter
+    particleNum = 1
+    # create ParticleInterval DirectNotify category
+    notify = directNotify.newCategory('ParticleInterval')
+    # Class methods
+    def __init__(self, particleEffect, parent, worldRelative=1, loop=0, 
+                                                duration=0.0, name=None):
+        """__init__(particleEffect, parent, worldRelative, loop, duration, name)
+        """
+        # Generate unique name
+        id = 'Particle-%d' % ParticleInterval.particleNum
+        ParticleInterval.particleNum += 1
+        if (name == None):
+            name = id
+        # Record instance variables
+        self.particleEffect = particleEffect 
+        self.parent = parent
+        self.worldRelative = worldRelative
+        self.loop = loop
+        assert(duration > 0.0 or loop == 1)
+        # Initialize superclass
+        Interval.__init__(self, name, duration)
+        # Update stopEvent
+        self.stopEvent = id + '_stopEvent'
+        self.stopEventList = [self.stopEvent]
+
+    def updateFunc(self, t, event=IVAL_NONE):
+        """ updateFunc(t, event)
+        Go to time t
+        """
+        # Update particle effect based on current time
+        if (t >= self.getDuration()):
+            # If duration reached or stop event received, stop particle effect 
+            BattleParticles.cleanupParticleEffect(self.particleEffect)
+            self.ignore(self.stopEvent)
+        elif (event == IVAL_INIT):
+            # IVAL_INIT event, start new particle effect
+            BattleParticles.startParticleEffect(self.particleEffect,
+                                                self.parent, self.worldRelative)
+            # Accept event to kill particle effect 
+            self.acceptOnce(self.stopEvent,
+                        lambda s = self: 
+                BattleParticles.cleanupParticleEffect(s.particleEffect))
+        # Print debug information
+        self.notify.debug('updateFunc() - %s: t = %f' % (self.name, t))
+            
+
+