def __init__(self, x, y, direction): self.x, self.y = (x, y) self.direction = direction if direction < 0: self.speed = -800 else: self.speed = 800 self.emitter = emitter.StaticEmitter( rate=300, template=Particle( position=(x, y, 0), velocity=(0, 0, 0), color=(1, 1, 0, 0.5), size=(8, 8, 0), # rotation? # up? ), velocity=Disc((0,0,0), (0,0,1), 200), time_to_live=self.duration, ) self.fader = controller.Fader(start_alpha=1,fade_out_start=0,fade_out_end=.5,end_alpha=0) self.group = ParticleGroup( controllers=[ self.emitter, controller.Gravity((0, -100, 0)), controller.Movement(), self.fader, controller.Lifetime(1), ], renderer=Render('zap-star.png'), ) self.emitter.emit(1, self.group)
def test_Lifetime_controller(self): from lepton import controller, Particle, ParticleGroup g = ParticleGroup() g.new(Particle(age=0)) g.new(Particle(age=0.8)) g.new(Particle(age=1.0)) g.new(Particle(age=0.75)) lifetime = controller.Lifetime(max_age=0.75) g.update(0) lifetime(0, g) p = list(g) self.assertEqual(len(g), 2) self.assertFloatEqiv(p[0].age, 0.0) self.assertFloatEqiv(p[1].age, 0.75)
def particle_splash(self, pos, vel): img = self.load_sprite('sprites/drip') img.anchor_x = img.width / 2 img.anchor_y = img.height / 2 e = StaticEmitter(position=domain.Disc((pos.x, SEA_LEVEL, 0), (0, 0, 1), 50), velocity=domain.Disc((vel.x, vel.y, 0), (0, 0, 1), 200), size=[(64.0, 64.0, 0), (80.0, 80.0, 0), (100.0, 100.0, 0)], template=Particle(color=(1.0, 1.0, 1.0, 1.0), ), rate=100, time_to_live=0.3) self.splash_group = ParticleGroup(controllers=[ controller.Movement(), controller.Gravity((0, -900, 0)), controller.Lifetime(max_age=2), e ], renderer=Renderer(img), system=self.particles)
def __init__(self, x, y, size): self.emitter = emitter.StaticEmitter( template = Particle( position=(x, y, 0), color=(1, 1, 1, .01), velocity=(0, 0, 0), size=(64, 64, 0), ), velocity=Disc((0,0,0), (0,0,1), 400), ) self.group = ParticleGroup( controllers=[ self.emitter, controller.Growth(50), controller.Movement(), controller.Fader(start_alpha=1,fade_out_start=0,fade_out_end=.7,end_alpha=0), controller.Lifetime(.7), ], renderer = Render('point64.png'), ) self.emitter.emit(50, self.group)
def load(cls): super(Rocket, cls).load() img = loader.image('data/sprites/rocket-spark.png') cls.particle_texture = img w = img.width h = img.height img.anchor_x = w * 0.5 img.anchor_y = h * 0.5 cls.particle_controllers = [ controller.Movement(), controller.Lifetime(max_age=2), controller.Growth(30.0), controller.ColorBlender([ (0, (1.0, 0.9, 0.0, 1.0)), (1, (0.0, 0.0, 0.0, 0.2)), (3, (0.0, 0.0, 0.0, 0.0)), ]), controller.Bounce(domain=domain.Plane((0, SEA_LEVEL, 0), (0, 1, 0)), bounce=0.02) ] cls.particle_renderer = Renderer(cls.particle_texture)
def __init__(self, rect, scale=1): x, y = rect.center self.emitter = emitter.StaticEmitter( rate = 20, template = Particle( position=(x, y, 0), color=(1, 1, 1, .5), velocity=(0, 0, 0), size=(8, 8, 0), ), velocity=Disc((0,0,0), (0,0,1), rect.width*.75*scale), ) self.group = ParticleGroup( controllers=[ self.emitter, controller.Movement(), controller.Clumper(50), controller.Fader(start_alpha=1,fade_out_start=0,fade_out_end=1,end_alpha=0), controller.Lifetime(1), ], renderer = Render(self.filename), ) self.emitter.emit(1, self.group)
def __init__(self, x1, y1, x2, y2): self.emitter = emitter.StaticEmitter( rate = (x2-x1) // 5, template = Particle( position=(x1, y1, 0), color=(1, 1, 1, .5), velocity=(0, 0, 0), size=(32, 32, 0), ), position=Line((x1, y1, 0), (x2, y1, 0)), velocity=AABox((-100, -50, 0), (100, -200, 1)), ) self.group = ParticleGroup( controllers=[ self.emitter, controller.Movement(), controller.Growth(100), controller.Gravity((0, -50, 0)), controller.Fader(start_alpha=1,fade_out_start=0,fade_out_end=1,end_alpha=0), controller.Lifetime(2), ], renderer = Render('black-bubble.png'), ) self.emitter.emit(1, self.group)
# The global particle system # Groups within here will be renderer # Actors should define emitters; the world will spawn these particles = ParticleSystemNode() def load(name): return pyglet.resource.texture(name) wake_particles = particles.create_group( controllers=[ # Drag(0.1, 0.0, (0, 0, 0)), controller.Movement(), controller.Lifetime(5), controller.Fader(start_alpha=0.0, max_alpha=0.3, end_alpha=0.0, fade_in_end=0.2, fade_out_start=0.3, fade_out_end=5.0) ], texture=load('foam.png')) smoke_particles = particles.create_group(controllers=[ controller.Movement(), controller.Lifetime(8), controller.Fader(start_alpha=0.0, max_alpha=0.2, end_alpha=0.0,
SpriteTexturizer = Mock() particle_system = Mock() load_texture = Mock() else: import pyglet.resource load_texture = pyglet.resource.texture particle_system = lepton.default_system # We should now be able to define all the particle engine stuff # without code changes to the rest of the game exhaust = load_texture('exhaust.png') exhaust_particles = ParticleGroup( controllers=[ controller.Movement(), controller.Lifetime(1), controller.ColorBlender([ (0.0, (1.0, 0.3, 0.3, 0.3)), (0.2, (1.0, 0.8, 0.3, 0.3)), (0.5, (1.0, 1.0, 1.0, 0.2)), (1.0, (1.0, 1.0, 1.0, 0.0)), ]), controller.Growth(-3) ], renderer=BillboardRenderer(SpriteTexturizer(exhaust.id)), ) explosion_particles = ParticleGroup( controllers=[ controller.Movement(), controller.Lifetime(2),