class FishAnimatedProp(AnimatedProp.AnimatedProp): def __init__(self, node): AnimatedProp.AnimatedProp.__init__(self, node) self.fish = Actor.Actor() self.fish.reparentTo(self.node.getParent()) self.fish.setTransform(self.node.getTransform()) self.node.clearMat() self.fish.prepareBundle(self.node) self.fish.loadAnims({ 'jump': 'phase_4/models/props/SZ_fish-jump', 'swim': 'phase_4/models/props/SZ_fish-swim' }) self.splashSfxList = (loader.loadSfx('phase_4/audio/sfx/TT_splash1.mp3'), loader.loadSfx('phase_4/audio/sfx/TT_splash2.mp3')) self.node = self.fish self.geom = self.fish.getGeomNode() self.exitRipples = Ripples(self.geom) self.exitRipples.setBin('fixed', 25, 1) self.exitRipples.setPosHprScale(-0.29999999999999999, 0.0, 1.24, 0.0, 0.0, 0.0, 0.69999999999999996, 0.69999999999999996, 0.69999999999999996) self.splash = Splash(self.geom) self.splash.setPosHprScale(-1, 0.0, 1.23, 0.0, 0.0, 0.0, 0.69999999999999996, 0.69999999999999996, 0.69999999999999996) randomSplash = random.choice(self.splashSfxList) self.track = Sequence(FunctionInterval(self.randomizePosition), Parallel(self.fish.actorInterval('jump'), Sequence(Wait(0.25), Func(self.exitRipples.play, 0.75)), Sequence(Wait(1.1399999999999999), Func(self.splash.play), SoundInterval(randomSplash, volume = 0.80000000000000004, node = self.node))), Wait(5 + 10 * random.random()), name = self.uniqueName('Fish')) def delete(self): self.exitRipples.destroy() del self.exitRipples self.splash.destroy() del self.splash del self.track self.fish.removeNode() del self.fish del self.node del self.geom def randomizePosition(self): x = 5 * (random.random() - 0.5) y = 5 * (random.random() - 0.5) h = 360 * random.random() self.geom.setPos(x, y, 0) self.geom.setHpr(h, 0, 0) def enter(self): AnimatedProp.AnimatedProp.enter(self) self.track.loop() def exit(self): AnimatedProp.AnimatedProp.exit(self) self.track.stop() self.splash.stop() self.exitRipples.stop()
class Splash(NodePath): splashCount = 0 def __init__(self, parent = hidden, wantParticles = 1): NodePath.__init__(self, parent) self.assign(parent.attachNewNode('splash')) self.splashdown = globalPropPool.getProp('splashdown') self.splashdown.reparentTo(self) self.splashdown.setZ(-0.01) self.splashdown.setScale(0.4) ta = TransparencyAttrib.make(TransparencyAttrib.MBinary) self.splashdown.node().setAttrib(ta, 1) self.splashdown.setBin('fixed', 130, 1) self.ripples = Ripples(self) self.ripples.setBin('fixed', 120, 1) self.wantParticles = 1 if self.wantParticles: self.pSystem = BattleParticles.createParticleEffect('SplashLines') self.pSystem.setScale(0.4) self.pSystem.setBin('fixed', 150, 1) self.particles = self.pSystem.particlesDict.get('particles-1') self.track = None self.trackId = Splash.splashCount Splash.splashCount += 1 self.setBin('fixed', 100, 1) self.hide() return def createTrack(self, rate = 1): self.ripples.createTrack(rate) self.splashdown.setPlayRate(rate, 'splashdown') animDuration = self.splashdown.getDuration('splashdown') * 0.65 rippleSequence = Sequence(Func(self.splashdown.show), Func(self.splashdown.play, 'splashdown'), Wait(animDuration), Func(self.splashdown.hide)) if self.wantParticles: particleSequence = Sequence(Func(self.pSystem.show), Func(self.particles.induceLabor), Func(self.pSystem.start, self), Wait(2.2), Func(self.pSystem.hide), Func(self.pSystem.disable)) else: particleSequence = Sequence() self.track = Sequence(Func(self.show), Parallel(self.ripples.track, rippleSequence, particleSequence), Func(self.hide), name='splashdown-%d-track' % self.trackId) def play(self, rate = 1): self.stop() self.createTrack(rate) self.track.start() def loop(self, rate = 1): self.stop() self.createTrack(rate) self.track.loop() def stop(self): if self.track: self.track.finish() def destroy(self): self.stop() del self.track self.ripples.destroy() del self.ripples if self.wantParticles: self.pSystem.cleanup() del self.pSystem del self.particles self.removeNode()
class Splash(NodePath): splashCount = 0 def __init__(self, parent=hidden, wantParticles=1): NodePath.__init__(self, parent) self.assign(parent.attachNewNode('splash')) self.splashdown = globalPropPool.getProp('splashdown') self.splashdown.reparentTo(self) self.splashdown.setZ(-0.01) self.splashdown.setScale(0.4) ta = TransparencyAttrib.make(TransparencyAttrib.MBinary) self.splashdown.node().setAttrib(ta, 1) self.splashdown.setBin('fixed', 130, 1) self.ripples = Ripples(self) self.ripples.setBin('fixed', 120, 1) self.wantParticles = 1 if self.wantParticles: self.pSystem = BattleParticles.createParticleEffect('SplashLines') self.pSystem.setScale(0.4) self.pSystem.setBin('fixed', 150, 1) self.particles = self.pSystem.particlesDict.get('particles-1') self.track = None self.trackId = Splash.splashCount Splash.splashCount += 1 self.setBin('fixed', 100, 1) self.hide() return def createTrack(self, rate=1): self.ripples.createTrack(rate) self.splashdown.setPlayRate(rate, 'splashdown') animDuration = self.splashdown.getDuration('splashdown') * 0.65 rippleSequence = Sequence(Func(self.splashdown.show), Func(self.splashdown.play, 'splashdown'), Wait(animDuration), Func(self.splashdown.hide)) if self.wantParticles: particleSequence = Sequence(Func(self.pSystem.show), Func(self.particles.induceLabor), Func(self.pSystem.start, self), Wait(2.2), Func(self.pSystem.hide), Func(self.pSystem.disable)) else: particleSequence = Sequence() self.track = Sequence(Func(self.show), Parallel(self.ripples.track, rippleSequence, particleSequence), Func(self.hide), name='splashdown-%d-track' % self.trackId) def play(self, rate=1): self.stop() self.createTrack(rate) self.track.start() def loop(self, rate=1): self.stop() self.createTrack(rate) self.track.loop() def stop(self): if self.track: self.track.finish() def destroy(self): self.stop() del self.track self.ripples.destroy() del self.ripples if self.wantParticles: self.pSystem.cleanup() del self.pSystem del self.particles self.removeNode()
class Splash(NodePath): splashCount = 0 def __init__(self, parent=hidden, wantParticles=1): """__init()""" # Initialize the superclass NodePath.__init__(self, parent) # Create a toplevel node to hold splash effects self.assign(parent.attachNewNode('splash')) # Load up a copy of the splash actor self.splashdown = globalPropPool.getProp('splashdown') self.splashdown.reparentTo(self) self.splashdown.setZ(-0.01) self.splashdown.setScale(0.4) # Adjust transparency of splash to use MBinary ta = TransparencyAttrib.make(TransparencyAttrib.MBinary) self.splashdown.node().setAttrib(ta, 1) self.splashdown.setBin('fixed', 130, 1) # Add in a ripple effect self.ripples = Ripples(self) self.ripples.setBin('fixed', 120, 1) # Add some particles self.wantParticles = wantParticles if self.wantParticles: self.pSystem = BattleParticles.createParticleEffect('SplashLines') self.pSystem.setScale(0.4) self.pSystem.setBin('fixed', 150, 1) self.particles = self.pSystem.particlesDict.get('particles-1') # Track for playing back splash effect self.track = None self.trackId = Splash.splashCount Splash.splashCount += 1 self.setBin('fixed', 100, 1) # Start out hidden self.hide() def createTrack(self, rate=1): # Init ripple track self.ripples.createTrack(rate) # Compute anim duration self.splashdown.setPlayRate(rate, 'splashdown') # Cut off the very end of the splash anim animDuration = self.splashdown.getDuration('splashdown') * 0.65 rippleSequence = Sequence( Func(self.splashdown.show), Func(self.splashdown.play, 'splashdown'), Wait(animDuration), Func(self.splashdown.hide), ) if self.wantParticles: particleSequence = Sequence( Func(self.pSystem.show), Func(self.particles.induceLabor), Func(self.pSystem.start, self), Wait(2.2), Func(self.pSystem.hide), Func(self.pSystem.disable), ) else: particleSequence = Sequence() # Create track self.track = Sequence( Func(self.show), Parallel( # Ripples sequence self.ripples.track, # Splashdown actor sequence rippleSequence, particleSequence, ), Func(self.hide), name='splashdown-%d-track' % self.trackId) def play(self, rate=1): # Stop existing track, if one exists self.stop() # Create new track at given rate self.createTrack(rate) # Play back track self.track.start() def loop(self, rate=1): # Stop existing track, if one exists self.stop() # Create new track at given rate self.createTrack(rate) # Loop track self.track.loop() def stop(self): if self.track: self.track.finish() def destroy(self): self.stop() del self.track self.ripples.destroy() del self.ripples if self.wantParticles: self.pSystem.cleanup() del self.pSystem del self.particles self.removeNode()
class FishAnimatedProp(AnimatedProp.AnimatedProp): def __init__(self, node): AnimatedProp.AnimatedProp.__init__(self, node) self.fish = Actor.Actor() self.fish.reparentTo(self.node.getParent()) self.fish.setTransform(self.node.getTransform()) self.node.clearMat() self.fish.prepareBundle(self.node) self.fish.loadAnims({ 'jump': 'phase_4/models/props/SZ_fish-jump', 'swim': 'phase_4/models/props/SZ_fish-swim' }) self.splashSfxList = ( loader.loadSfx('phase_4/audio/sfx/TT_splash1.mp3'), loader.loadSfx('phase_4/audio/sfx/TT_splash2.mp3')) self.node = self.fish self.geom = self.fish.getGeomNode() self.exitRipples = Ripples(self.geom) self.exitRipples.setBin('fixed', 25, 1) self.exitRipples.setPosHprScale(-0.29999999999999999, 0.0, 1.24, 0.0, 0.0, 0.0, 0.69999999999999996, 0.69999999999999996, 0.69999999999999996) self.splash = Splash(self.geom) self.splash.setPosHprScale(-1, 0.0, 1.23, 0.0, 0.0, 0.0, 0.69999999999999996, 0.69999999999999996, 0.69999999999999996) randomSplash = random.choice(self.splashSfxList) self.track = Sequence(FunctionInterval(self.randomizePosition), Parallel( self.fish.actorInterval('jump'), Sequence(Wait(0.25), Func(self.exitRipples.play, 0.75)), Sequence( Wait(1.1399999999999999), Func(self.splash.play), SoundInterval(randomSplash, volume=0.80000000000000004, node=self.node))), Wait(5 + 10 * random.random()), name=self.uniqueName('Fish')) def delete(self): self.exitRipples.destroy() del self.exitRipples self.splash.destroy() del self.splash del self.track self.fish.removeNode() del self.fish del self.node del self.geom def randomizePosition(self): x = 5 * (random.random() - 0.5) y = 5 * (random.random() - 0.5) h = 360 * random.random() self.geom.setPos(x, y, 0) self.geom.setHpr(h, 0, 0) def enter(self): AnimatedProp.AnimatedProp.enter(self) self.track.loop() def exit(self): AnimatedProp.AnimatedProp.exit(self) self.track.stop() self.splash.stop() self.exitRipples.stop()
class Splash(NodePath): splashCount = 0 def __init__(self, parent=hidden, wantParticles=1, tint=(1, 1, 1, 1)): NodePath.__init__(self, parent) self.assign(parent.attachNewNode('splash')) self.splashdown = Actor( 'phase_4/models/props/SZ_splashdown-mod.bam', {'splashdown': 'phase_4/models/props/SZ_splashdown-chan.bam'}) self.setLightOff() self.splashdown.reparentTo(self) self.splashdown.setZ(-0.01) self.splashdown.setScale(0.4) self.setColorScale(tint) ta = TransparencyAttrib.make(TransparencyAttrib.MBinary) self.splashdown.node().setAttrib(ta, 1) self.splashdown.setBin('fixed', 130, 1) self.ripples = Ripples(self) self.ripples.setBin('fixed', 120, 1) self.wantParticles = wantParticles if self.wantParticles: self.pSystem = ParticleLoader.loadParticleEffect( "phase_4/etc/splashlines.ptf") self.pSystem.setScale(0.40000000000000002) self.pSystem.setBin('fixed', 150, 1) self.pSystem.setColorScale(tint) self.particles = self.pSystem.particlesDict.get('particles-1') self.track = None self.trackId = Splash.splashCount Splash.splashCount += 1 self.setBin('fixed', 100, 1) self.hide() def createTrack(self, rate=1): self.ripples.createTrack(rate) self.splashdown.setPlayRate(rate, 'splashdown') animDuration = self.splashdown.getDuration('splashdown') * 0.65 rippleSequence = Sequence(Func(self.splashdown.show), Func(self.splashdown.play, 'splashdown'), Wait(animDuration), Func(self.splashdown.hide)) if self.wantParticles: particleSequence = Sequence(Func(self.pSystem.show), Func(self.particles.induceLabor), Func(self.pSystem.start, self), Wait(2.2), Func(self.pSystem.hide), Func(self.pSystem.disable)) else: particleSequence = Sequence() self.track = Sequence(Func(self.show), Parallel(self.ripples.track, rippleSequence, particleSequence), Func(self.hide), name='splashdown-%d-track' % self.trackId) def play(self, rate=1): self.stop() self.createTrack(rate) self.track.start() def loop(self, rate=1): self.stop() self.createTrack(rate) self.track.loop() def stop(self): if self.track: self.track.finish() def destroy(self): self.stop() del self.track self.ripples.destroy() del self.ripples if self.wantParticles: self.pSystem.cleanup() del self.pSystem del self.particles self.removeNode()