Ejemplo n.º 1
0
    def __init__(self, position):
        x, y = position

        spark_emitter = StaticEmitter(
            template=Particle(position=(uniform(x - 5,
                                                x + 5), uniform(y - 5,
                                                                y + 5), 0),
                              size=(10, ) * 3,
                              color=self.color),
            deviation=Particle(velocity=(gauss(0, 5), gauss(0, 5), 0),
                               age=1.5),
            velocity=domain.Sphere((0, gauss(40, 20), 0), 60, 60))

        spark_emitter.emit(int(gauss(60, 40)) + 50, self.sparks)

        spread = abs(gauss(0.4, 1.0))
        self.trail_emitter = PerParticleEmitter(
            self.sparks,
            rate=uniform(5, 30),
            template=Particle(size=(6, ) * 3, color=self.color),
            deviation=Particle(velocity=(spread, spread, spread),
                               age=self.lifetime * 0.75))

        self.trails.bind_controller(self.trail_emitter)
        self.splosions.add(self)
        pyglet.clock.schedule_once(self.die, self.lifetime)
Ejemplo n.º 2
0
    def emit(cls, position, velocity):
        x, y = position + velocity * 0.3
        emitter = StaticEmitter(template=Particle(position=(x, y, 0),
                                                  size=(5, ) * 3,
                                                  color=cls.color),
                                deviation=Particle(age=0.2),
                                velocity=domain.Disc((*-2 * velocity, 0),
                                                     (0, 0, 1), 100))

        emitter.emit(10, cls.sparks)
Ejemplo n.º 3
0
    def emit(cls, position):
        emitter = StaticEmitter(template=Particle(position=(*position, 0),
                                                  size=(16, ) * 3,
                                                  rotation=(0, 0, 1),
                                                  color=cls.color),
                                deviation=Particle(age=0.2,
                                                   rotation=(0, 0, 2)),
                                velocity=domain.Disc((0, 0, 0), (0, 0, 1),
                                                     100))

        emitter.emit(20, cls.fragments)
Ejemplo n.º 4
0
 def particles(self):
     self.part = ParticleGroup(renderer=BillboardRenderer(texturizer2),
                               controllers=[
                                   Movement(max_velocity=self.speed,
                                            damping=0.95),
                                   Magnet(self.objective,
                                          charge=500,
                                          exponent=0),
                               ])
     self.emiter = StaticEmitter(position=self.domain,
                                 template=Particle(
                                     color=self.color,
                                     size=(self.size, self.size, 0),
                                 ))
     self.emiter.emit(1, self.part)
Ejemplo n.º 5
0
	def test_StaticEmitter_emit(self):
		from lepton import ParticleGroup
		from lepton.emitter import StaticEmitter

		emitter = StaticEmitter()
		group = ParticleGroup()
		self.assertEqual(len(group), 0)
		emitter.emit(10, group)
		group.update(0)
		self.assertEqual(len(group), 10)

		# Negative emit value is equivilant to zero
		emitter.emit(-10, group)
		group.update(0)
		self.assertEqual(len(group), 10)
Ejemplo n.º 6
0
    def __init__(self):
        color = (uniform(0, 1), uniform(0, 1), uniform(0, 1), 1)
        while max(color[:3]) < 0.9:
            color = (uniform(0, 1), uniform(0, 1), uniform(0, 1), 1)

        spark_emitter = StaticEmitter(
            template=Particle(position=(uniform(-50, 50), uniform(-30, 30),
                                        uniform(-30, 30)),
                              color=color),
            deviation=Particle(velocity=(gauss(0, 5), gauss(0, 5), gauss(0,
                                                                         5)),
                               age=1.5),
            velocity=domain.Sphere((0, gauss(40, 20), 0), 60, 60))

        self.sparks = ParticleGroup(controllers=[
            Lifetime(self.lifetime * 0.75),
            Movement(damping=0.93),
            ColorBlender([(0, (1, 1, 1, 1)), (2, color),
                          (self.lifetime, color)]),
            Fader(fade_out_start=1.0, fade_out_end=self.lifetime * 0.5),
        ],
                                    renderer=PointRenderer(
                                        abs(gauss(10, 3)), spark_texturizer))

        spark_emitter.emit(int(gauss(60, 40)) + 50, self.sparks)

        spread = abs(gauss(0.4, 1.0))
        self.trail_emitter = PerParticleEmitter(
            self.sparks,
            rate=uniform(5, 30),
            template=Particle(color=color),
            deviation=Particle(velocity=(spread, spread, spread),
                               age=self.lifetime * 0.75))

        self.trails = ParticleGroup(controllers=[
            Lifetime(self.lifetime * 1.5),
            Movement(damping=0.83),
            ColorBlender([(0, (1, 1, 1, 1)), (1, color),
                          (self.lifetime, color)]),
            Fader(max_alpha=0.75,
                  fade_out_start=0,
                  fade_out_end=gauss(self.lifetime, self.lifetime * 0.3)),
            self.trail_emitter
        ],
                                    renderer=PointRenderer(
                                        10, trail_texturizer))

        pyglet.clock.schedule_once(self.die, self.lifetime * 2)
Ejemplo n.º 7
0
    def test_StaticEmitter_discrete(self):
        from lepton import Particle, ParticleGroup
        from lepton.emitter import StaticEmitter

        masses = (0.5, 2.0, 8.0)
        positions = ((1.0, 1.0, 1.0), (10.0, 20.0, 30.0), (-100.0, 0.0, 0.0))
        velocities = ((1, 1, 0), )
        colors = ((1.0, 1.0, 1.0, 0.5), (1.0, 0, 0, 1.0), (0, 1.0, 0, 1.0))
        emitter = StaticEmitter(rate=1,
                                mass=masses,
                                position=positions,
                                velocity=velocities,
                                color=colors)
        group = ParticleGroup()
        emitter(3, group)
        group.update(0)
        self.assertEqual(len(group), 3)
        for particle in group:
            self.failUnless(particle.mass in masses, (particle.mass, masses))
            self.failUnless(
                tuple(particle.position) in positions,
                (particle.position, positions))
            self.failUnless(
                tuple(particle.color) in colors, (particle.color, colors))
            self.assertVector(particle.velocity, (1, 1, 0))
Ejemplo n.º 8
0
def spawn_splinters(pos, vel):
    """Spawn a cannon smoke puff."""
    e = StaticEmitter(
        template=Particle(
            position=tuple(pos),
            velocity=tuple(vel * -0.1),
            size=(0.15, 0.15, 0.15),
            color=(1, 1, 1, 0.8),
        ),
        rotation=domain.Line((0, 0, -1), (0, 0, 1)),
        deviation=Particle(
            size=(0.05, 0.05, 0.05),
            velocity=(2.0, 2.0, 2.0),
        ),
    )
    e.emit(10, splinters1)
    e.emit(10, splinters2)
Ejemplo n.º 9
0
	def __init__(self):
		color=(uniform(0,1), uniform(0,1), uniform(0,1), 1)
		while max(color[:3]) < 0.9:
			color=(uniform(0,1), uniform(0,1), uniform(0,1), 1)

		spark_emitter = StaticEmitter(
			template=Particle(
				position=(uniform(-50, 50), uniform(-30, 30), uniform(-30, 30)), 
				color=color), 
			deviation=Particle(
				velocity=(gauss(0, 5), gauss(0, 5), gauss(0, 5)),
				age=1.5),
			velocity=domain.Sphere((0, gauss(40, 20), 0), 60, 60))

		self.sparks = ParticleGroup(
			controllers=[
				Lifetime(self.lifetime * 0.75),
				Movement(damping=0.93),
				ColorBlender([(0, (1,1,1,1)), (2, color), (self.lifetime, color)]),
				Fader(fade_out_start=1.0, fade_out_end=self.lifetime * 0.5),
			],
			renderer=PointRenderer(abs(gauss(10, 3)), spark_texturizer))

		spark_emitter.emit(int(gauss(60, 40)) + 50, self.sparks)

		spread = abs(gauss(0.4, 1.0))
		self.trail_emitter = PerParticleEmitter(self.sparks, rate=uniform(5,30),
			template=Particle(
				color=color),
			deviation=Particle(
				velocity=(spread, spread, spread),
				age=self.lifetime * 0.75))

		self.trails = ParticleGroup(
			controllers=[
				Lifetime(self.lifetime * 1.5),
				Movement(damping=0.83),
				ColorBlender([(0, (1,1,1,1)), (1, color), (self.lifetime, color)]),
				Fader(max_alpha=0.75, fade_out_start=0, fade_out_end=gauss(self.lifetime, self.lifetime*0.3)),
				self.trail_emitter
			],
			renderer=PointRenderer(10, trail_texturizer))

		pyglet.clock.schedule_once(self.die, self.lifetime * 2)
Ejemplo n.º 10
0
    def emit_sparks(self, pos, count):
        sparks = ParticleGroup(
            controllers=[
                Lifetime(1),
                Movement(damping=0.93),
                Fader(fade_out_start=0.75, fade_out_end=1.0),
            ],
            renderer=BillboardRenderer(SpriteTexturizer(self.particle1_tex.id)))

        spark_emitter = StaticEmitter(
            template=Particle(
                position=(pos[0], pos[1], 0),
                color=(1, 1, 1)),
            deviation=Particle(
                position=(1, 1, 0),
                velocity=(100, 100, 0),
                age=1.5),
            size=[(6, 6, 0), (7, 7, 0), (12, 12, 0)])
        spark_emitter.emit(count, sparks)
Ejemplo n.º 11
0
def spawn_smoke(pos, vel):
    """Spawn a cannon smoke puff."""
    e = StaticEmitter(template=Particle(
        position=tuple(pos),
        velocity=tuple(vel * 0.1),
        size=(0.2, 0.2, 0.2),
        color=(1, 1, 1, 0.2),
    ),
                      rotation=domain.Line((0, 0, -1), (0, 0, 1)),
                      deviation=Particle(velocity=(1.0, 1.0, 1.0), ),
                      rate=100,
                      time_to_live=0.1)
    smoke_particles.bind_controller(e)
Ejemplo n.º 12
0
    def test_StaticEmitter_partial(self):
        from lepton import Particle, ParticleGroup
        from lepton.emitter import StaticEmitter

        emitter = StaticEmitter(rate=1)
        group = ParticleGroup()
        # It should take four quarter second updates to emit one
        self.assertEqual(emitter(0.25, group), 0)
        self.assertEqual(emitter(0.25, group), 0)
        self.assertEqual(emitter(0.25, group), 0)
        self.assertEqual(emitter(0.25, group), 1)
        group.update(0)
        self.assertEqual(len(group), 1)
Ejemplo n.º 13
0
class fleet(object):
    def __init__(self, side, pos, objective, mode, size, data, color, speed):
        self.side = side
        self.pos = pos
        self.domain = Sphere(pos, size)
        self.objective = Sphere((objective[0], objective[1], objective[2]), 1)
        self.mode = mode
        self.target = None
        self.size = size
        self.data = data
        self.color = color
        self.speed = speed
        self.particles()

    def particles(self):
        self.part = ParticleGroup(renderer=BillboardRenderer(texturizer2),
                                  controllers=[
                                      Movement(max_velocity=self.speed,
                                               damping=0.95),
                                      Magnet(self.objective,
                                             charge=500,
                                             exponent=0),
                                  ])
        self.emiter = StaticEmitter(position=self.domain,
                                    template=Particle(
                                        color=self.color,
                                        size=(self.size, self.size, 0),
                                    ))
        self.emiter.emit(1, self.part)

    def moveAround(self):
        for part in self.part:
            self.pos = (part.position[0], part.position[1], part.position[2])
        if self.target:
            try:
                self.objective.center = self.target.domain.center
            except:
                pass
Ejemplo n.º 14
0
 def __init__(self, player, viewport, level):
     self.player = player
     self.viewport = viewport
     self.level = level
     self.emitter = StaticEmitter(
         rate=player.body.velocity.length,
         template=Particle(
             position=(*level.map_to_world(player.position), 0),
             color=(1.0, 1.0, 1.0, 1.0),
             size=(16.0, ) * 3,
         ),
     )
     self.group.bind_controller(self.emitter)
     pyglet.clock.schedule(self.update)
Ejemplo n.º 15
0
 def __init__(self, wpos):
     self.last_pos = wpos
     self.domain = Cylinder((*wpos, -10), (*wpos, 0), 5)
     self.emitter = StaticEmitter(rate=600,
                                  position=self.domain,
                                  template=Particle(
                                      color=(1.0, 1.0, 1.0, 0.3),
                                      size=(2.0, ) * 3,
                                      rotation=(0, 0, 1),
                                      velocity=(0, 0, 0),
                                  ),
                                  deviation=Particle(
                                      rotation=(0, 0, 0.5),
                                      angle=(0, 0, 6),
                                  ))
     self.group.bind_controller(self.emitter)
Ejemplo n.º 16
0
    def test_StaticEmitter_time_to_live(self):
        from lepton import Particle, ParticleGroup
        from lepton.emitter import StaticEmitter

        emitter = StaticEmitter(rate=1, time_to_live=3.0)
        group = ParticleGroup(controllers=[emitter])
        count = emitter(2, group)
        self.assertEqual(count, 2)
        self.assertEqual(emitter.time_to_live, 1)
        self.failUnless(emitter in group.controllers)
        count = emitter(2, group)
        # Since only one second remained before expiring
        # only one particle should be emitted
        self.assertEqual(count, 1)
        self.assertEqual(emitter.time_to_live, 0)
        self.failUnless(emitter not in group.controllers)
Ejemplo n.º 17
0
    def explosion(self, pos, magnitude):

        sparks = ParticleGroup(
          controllers=[
              Lifetime(3),
              Movement(damping=0.93),
              Fader(fade_out_start=0.75, fade_out_end=3.0),
          ],
          renderer=BillboardRenderer(SpriteTexturizer(self.particle1_tex.id)))

        spark_emitter = StaticEmitter(
          template=Particle(
              position=(pos[0], pos[1], 0),
              color=(1, 1, 1)),
          deviation=Particle(
              position=(1, 1, 0),
              velocity=(300, 300, 0),
              age=1.5),
          size=[(3, 3, 0), (4, 4, 0), (5, 5, 0), (5, 5, 0), (6, 6, 0), (7, 7, 0)])
        spark_emitter.emit(magnitude, sparks)

        fire = ParticleGroup(
          controllers=[
              Lifetime(2),
              Movement(damping=0.95),
              Growth(60),
              Fader(fade_in_start=0, start_alpha=0, fade_in_end=0.5, max_alpha=0.6,
                    fade_out_start=1.0, fade_out_end=2.0)
          ],
          renderer=BillboardRenderer(SpriteTexturizer(self.smoke1_tex.id)))

        fire_emitter = StaticEmitter(
          template=Particle(
              position=(pos[0], pos[1], 0),
              size=(50, 50, 0)),
          deviation=Particle(
              position=(0.5, 0.5, 0),
              velocity=(70, 70, 0),
              size=(20, 20, 0),
              up=(0, 0, math.pi * 2),
              rotation=(0, 0, math.pi * 0.06),
              age=2, ),
          color=[(0.5, 0, 0), (0.5, 0.5, 0.5), (0.4, 0.1, 0.1), (0.85, 0.3, 0)],
        )
        fire_emitter.emit(400, fire)
Ejemplo n.º 18
0
    def test_StaticEmitter_template(self):
        from lepton import Particle, ParticleGroup
        from lepton.emitter import StaticEmitter

        emitter = StaticEmitter(rate=1,
                                template=Particle(position=(1.0, 1.0, 1.0),
                                                  velocity=(0, 5, 2),
                                                  color=(0.5, 0.5, 0.5, 1.0)))
        group = ParticleGroup()
        count = emitter(1, group)
        group.update(0)
        self.assertEqual(count, 1)
        self.assertEqual(len(group), 1)
        particle = list(group)[0]
        self.assertVector(particle.position, (1, 1, 1))
        self.assertVector(particle.velocity, (0, 5, 2))
        self.assertColor(particle.color, (0.5, 0.5, 0.5, 1.0))
Ejemplo n.º 19
0
    def __init__(self, ship):
        self.ship = ship

        self.emitters = [
            StaticEmitter(template=Particle(
                position=tuple(p),
                velocity=tuple(v),
                size=(0.2, 0.2, 0.0),
                color=(1, 1, 1, 0.2),
            ),
                          deviation=Particle(
                              position=(0.02, 0.0, 0.02) if i < 2 else
                              (0.2, 0.0, 0.2),
                              size=(0.0, 0.07, 0.0),
                              velocity=(0.04, 0.0, 0.04),
                          ),
                          rate=5 if i < 2 else 20)
            for i, (p, v, rate) in enumerate(self.emitter_positions)
        ]
Ejemplo n.º 20
0
    def __init__(self, x, y):

        spark_tex = image.load(os.path.join(os.path.dirname(__file__), 'images/flare3.png')).get_texture()

        sparks = ParticleGroup(
            controllers=[
                Lifetime(2),
                Movement(damping=0.93),
                Fader(fade_out_start=0, fade_out_end=1.8),
            ],

            renderer=BillboardRenderer(SpriteTexturizer(spark_tex.id)))

        spark_emitter = StaticEmitter(
            template=Particle(
                position=(x,y),
                color=(1,1,1)),
            deviation=Particle(
                position=(1,1,0),
                velocity=(300,300,0),
                age=1.5),
            size=[(1,1,0), (2,2,0), (2,2,0), (2,2,0), (3,3,0), (4,4,0)])
        spark_emitter.emit(50, sparks)

        fire_tex = image.load(os.path.join(os.path.dirname(__file__), 'images/puff.png')).get_texture()

        fire = ParticleGroup(
            controllers=[
            Lifetime(4),
            Movement(damping=0.95),
            Growth(10),
            Fader(fade_in_start=0, start_alpha=0, fade_in_end=0.5, max_alpha=0.4,
                fade_out_start=1.0, fade_out_end=1.0)
            ],
            renderer=BillboardRenderer(SpriteTexturizer(fire_tex.id)))

        fire_emitter = StaticEmitter(
            template=Particle(
                position=(x, y),
                size=(10,10,0)),
            deviation=Particle(
                position=(2,2,0),
                velocity=(70,70,0),
                size=(5,5,0),
                up=(0,0,pi*2),
                rotation=(0,0,pi*0.06),
                age=.3,),
            color=[(0.5,0,0), (0.5,0.5,0.5), (0.4,0.1,0.1), (0.85,0.3,0)],
        )
        fire_emitter.emit(200, fire)
Ejemplo n.º 21
0
 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)
Ejemplo n.º 22
0
    def test_StaticEmitter_emit(self):
        from lepton import ParticleGroup
        from lepton.emitter import StaticEmitter

        emitter = StaticEmitter()
        group = ParticleGroup()
        self.assertEqual(len(group), 0)
        emitter.emit(10, group)
        group.update(0)
        self.assertEqual(len(group), 10)

        # Negative emit value is equivilant to zero
        emitter.emit(-10, group)
        group.update(0)
        self.assertEqual(len(group), 10)
Ejemplo n.º 23
0
    def set_active(self, _):
        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((0, 0, 0), (0, 0, 1), 100)
            self.pos_domain = domain.Cone((0, 0, 0), (-1, 0, 0), 1)
            self.template = Particle(
                size=(20.0, 20.0, 0),
                color=(1.0, 0.5, 0.0, 1.0),
            )
            self.emitter = StaticEmitter(
                position=self.pos_domain,
                velocity=self.vel_domain,
                template=self.template,
                rate=30,
                time_to_live=self.BURN_TIME,
            )
            self.particlegroup.bind_controller(self.emitter)
Ejemplo n.º 24
0
    def test_StaticEmitter_domain(self):
        from lepton import Particle, ParticleGroup
        from lepton.emitter import StaticEmitter

        expected = (-42, 0, 9)

        class TestDomain:
            generate_calls = 0

            def generate(self):
                self.generate_calls += 1
                return expected

        domain = TestDomain()
        emitter = StaticEmitter(rate=1, position=domain)
        self.assertEqual(domain.generate_calls, 0)
        group = ParticleGroup()
        count = emitter(2, group)
        group.update(0)
        self.assertEqual(count, 2)
        self.assertEqual(domain.generate_calls, 2)
        self.assertEqual(len(group), 2)
        for particle in group:
            self.assertVector(particle.position, expected)
Ejemplo n.º 25
0
    def __init__(self,
                 x,
                 y,
                 z,
                 r,
                 side=-1,
                 hp=50,
                 controlable=False,
                 weapon_range=5,
                 dispersion=5,
                 agility=50,
                 weapon_base_damage=2,
                 guidance=100,
                 shortguide=0,
                 partColor=(0.6, 0.5, 0.2, 1),
                 firerate=10,
                 shots=1,
                 vo=30,
                 maxvel=10,
                 ammoMaxvel=20,
                 combatDistance=50,
                 behavior=0,
                 commander=None,
                 multipleTargets=False,
                 name="",
                 ammoDamp=0.98):
        self.name = name
        self.domain = Sphere(
            (x, y, z), r
        )  # a.center -> vector del centro , a.outer_radius -> radio externo , a.inner_radius -> radio interno
        self.size = r
        self.controller = Collector(self.domain, callback=self.contact)
        self.magnet = Magnet(self.domain, charge=guidance, exponent=shortguide)
        self.commander = commander
        self.mission = self.domain.center
        self.target = None
        self.alive = True
        self.targetMode = ['standard', 1]
        self.behavior = behavior  # 0:free 1: escort 2: slave
        self.hp = hp
        self.agility = agility
        self.maxvel = maxvel
        self.timer = {0: 0, 1: 2, 2: 0, 3: 0, 4: 0}  # timers placeholder
        self.counter = {0: 0, 1: 0}  # counters placeholder
        self.side = side
        self.combatDistance = combatDistance
        self.velocity = Vec3(0, 0, 0)
        self.multipleTargets = multipleTargets
        self.firerate = firerate
        self.weapon_base_damage = weapon_base_damage
        wbd = self.weapon_base_damage
        rr = r * 2
        self.dispersion = dispersion
        self.vo = vo
        self.ammoDamp = ammoDamp
        self.ammoMaxvel = ammoMaxvel
        self.shots = shots
        self.weapon_range = weapon_range
        self.xx = self.yy = self.zz = 0
        self.Objective = Sphere((0, 0, 0), 1)
        self.color = partColor  # (0.4,0.5,0.4,0.5)
        #self.prevController = Collector(self.domain)#DUMMY CONTROLLER
        self.controlable = controlable
        self.impacto = ParticleGroup(renderer=BillboardRenderer(texturizer),
                                     controllers=[
                                         Lifetime(1),
                                         Fader(fade_out_start=0,
                                               fade_out_end=1),
                                     ])
        self.deathplosion = ParticleGroup(
            renderer=BillboardRenderer(texturizer),
            controllers=[
                Lifetime(self.size / 5 + 1),
                Fader(fade_out_start=0, fade_out_end=self.size / 5 + 1),
            ])
        self.selector_emitter = StaticEmitter(template=Particle(
            position=(0, 0, 0),
            color=self.color,
        ))
        self.impacto_emitter = StaticEmitter(
            template=Particle(
                position=(0, 0, 0),
                color=(0.9, 0.8, 0.8),
            ),
            position=self.domain,
            #size=[(5, 5, 5), (10, 10, 10), (15, 15, 15)],
        )
        self.hull = ParticleGroup(renderer=BillboardRenderer(texturizer2),
                                  controllers=[
                                      Lifetime(100000),
                                      Movement(max_velocity=self.maxvel,
                                               damping=0.98),
                                      Magnet(self.Objective,
                                             charge=self.agility,
                                             exponent=0),
                                  ])
        emiter = StaticEmitter(position=self.domain,
                               template=Particle(
                                   color=self.color,
                                   size=(rr, rr, rr),
                               ))
        emiter.emit(1, self.hull)

        if trails:
            if maxvel / r >= 20:
                self.trail = ParticleGroup(
                    renderer=BillboardRenderer(texturizer2),
                    controllers=[
                        Lifetime(trailSize[0]),
                        Fader(fade_in_start=0,
                              fade_in_end=0.1,
                              fade_out_start=0,
                              fade_out_end=trailSize[0]),
                        Growth(-1 * r),
                        PerParticleEmitter(self.hull,
                                           rate=trailSize[1],
                                           template=Particle(
                                               color=self.color,
                                               size=(rr, rr, rr),
                                           )),
                    ])

        self.ammo = ParticleGroup(renderer=BillboardRenderer(texturizer),
                                  controllers=[
                                      self.magnet,
                                      Movement(min_velocity=0,
                                               max_velocity=self.ammoMaxvel,
                                               damping=self.ammoDamp),
                                      Lifetime(self.weapon_range),
                                      Fader(fade_out_start=self.weapon_range -
                                            1,
                                            fade_out_end=self.weapon_range),
                                  ])

        self.weapon = PerParticleEmitter(
            self.hull,  # rate=self.firerate,
            template=Particle(
                velocity=self.velocity,  # fixed value
                position=(self.getPosition()),
                color=partColor,
            ),
            position=self.domain,
            size=[(wbd * 0.5, wbd * 0.5, wbd * 0.5), (wbd, wbd, wbd),
                  (wbd * 1.5, wbd * 1.5, wbd * 1.5)],
            deviation=Particle(
                velocity=(self.dispersion, self.dispersion,
                          self.dispersion * d3),
                rotation=(0, 0, math.pi / 6),
                #color=(0.05,0.05,0.05,0),
            ))
Ejemplo n.º 26
0

win.on_resize = resize

electron_lifetime = 22
max_electrons = 6
trail_lifetime = 4.5

texture = image.load(os.path.join(os.path.dirname(__file__), "flare3.png")).get_texture()
texturizer = SpriteTexturizer(texture.id)

nucleus = Sphere((0, 0, 0), 5)
protons = ParticleGroup(renderer=BillboardRenderer(texturizer), controllers=[Movement()])
proton_emitter = StaticEmitter(
    template=Particle(size=(30, 30, 0), color=(0.5, 1.0, 0.2, 0.5)),
    size=[(26, 26, 0), (30, 30, 0), (34, 34, 0)],
    deviation=Particle(rotation=(0, 0, math.pi / 6)),
)

proton_emitter.emit(3, protons)

electrons = ParticleGroup(
    renderer=BillboardRenderer(texturizer),
    controllers=[
        Movement(min_velocity=10),
        Lifetime(electron_lifetime * 1.5),
        Magnet(nucleus, charge=15000.0),
        Magnet(nucleus, charge=-15000.0, exponent=3),
        Fader(fade_in_end=1, fade_out_start=electron_lifetime * 1.4, fade_out_end=electron_lifetime * 1.5),
    ],
)
Ejemplo n.º 27
0
max_electrons = 6
trail_lifetime = 4.5

texture = image.load(os.path.join(os.path.dirname(__file__),
                                  'flare3.png')).get_texture()
texturizer = SpriteTexturizer(texture.id)

nucleus = Sphere((0, 0, 0), 5)
protons = ParticleGroup(renderer=BillboardRenderer(texturizer),
                        controllers=[
                            Movement(),
                        ])
proton_emitter = StaticEmitter(template=Particle(
    size=(30, 30, 0),
    color=(0.5, 1.0, 0.2, 0.5),
),
                               size=[(26, 26, 0), (30, 30, 0), (34, 34, 0)],
                               deviation=Particle(rotation=(0, 0,
                                                            math.pi / 6), ))

proton_emitter.emit(3, protons)

electrons = ParticleGroup(renderer=BillboardRenderer(texturizer),
                          controllers=[
                              Movement(min_velocity=10),
                              Lifetime(electron_lifetime * 1.5),
                              Magnet(nucleus, charge=15000.0),
                              Magnet(nucleus, charge=-15000.0, exponent=3),
                              Fader(fade_in_end=1,
                                    fade_out_start=electron_lifetime * 1.4,
                                    fade_out_end=electron_lifetime * 1.5),
Ejemplo n.º 28
0
class ship(object):
    def __init__(self,
                 x,
                 y,
                 z,
                 r,
                 side=-1,
                 hp=50,
                 controlable=False,
                 weapon_range=5,
                 dispersion=5,
                 agility=50,
                 weapon_base_damage=2,
                 guidance=100,
                 shortguide=0,
                 partColor=(0.6, 0.5, 0.2, 1),
                 firerate=10,
                 shots=1,
                 vo=30,
                 maxvel=10,
                 ammoMaxvel=20,
                 combatDistance=50,
                 behavior=0,
                 commander=None,
                 multipleTargets=False,
                 name="",
                 ammoDamp=0.98):
        self.name = name
        self.domain = Sphere(
            (x, y, z), r
        )  # a.center -> vector del centro , a.outer_radius -> radio externo , a.inner_radius -> radio interno
        self.size = r
        self.controller = Collector(self.domain, callback=self.contact)
        self.magnet = Magnet(self.domain, charge=guidance, exponent=shortguide)
        self.commander = commander
        self.mission = self.domain.center
        self.target = None
        self.alive = True
        self.targetMode = ['standard', 1]
        self.behavior = behavior  # 0:free 1: escort 2: slave
        self.hp = hp
        self.agility = agility
        self.maxvel = maxvel
        self.timer = {0: 0, 1: 2, 2: 0, 3: 0, 4: 0}  # timers placeholder
        self.counter = {0: 0, 1: 0}  # counters placeholder
        self.side = side
        self.combatDistance = combatDistance
        self.velocity = Vec3(0, 0, 0)
        self.multipleTargets = multipleTargets
        self.firerate = firerate
        self.weapon_base_damage = weapon_base_damage
        wbd = self.weapon_base_damage
        rr = r * 2
        self.dispersion = dispersion
        self.vo = vo
        self.ammoDamp = ammoDamp
        self.ammoMaxvel = ammoMaxvel
        self.shots = shots
        self.weapon_range = weapon_range
        self.xx = self.yy = self.zz = 0
        self.Objective = Sphere((0, 0, 0), 1)
        self.color = partColor  # (0.4,0.5,0.4,0.5)
        #self.prevController = Collector(self.domain)#DUMMY CONTROLLER
        self.controlable = controlable
        self.impacto = ParticleGroup(renderer=BillboardRenderer(texturizer),
                                     controllers=[
                                         Lifetime(1),
                                         Fader(fade_out_start=0,
                                               fade_out_end=1),
                                     ])
        self.deathplosion = ParticleGroup(
            renderer=BillboardRenderer(texturizer),
            controllers=[
                Lifetime(self.size / 5 + 1),
                Fader(fade_out_start=0, fade_out_end=self.size / 5 + 1),
            ])
        self.selector_emitter = StaticEmitter(template=Particle(
            position=(0, 0, 0),
            color=self.color,
        ))
        self.impacto_emitter = StaticEmitter(
            template=Particle(
                position=(0, 0, 0),
                color=(0.9, 0.8, 0.8),
            ),
            position=self.domain,
            #size=[(5, 5, 5), (10, 10, 10), (15, 15, 15)],
        )
        self.hull = ParticleGroup(renderer=BillboardRenderer(texturizer2),
                                  controllers=[
                                      Lifetime(100000),
                                      Movement(max_velocity=self.maxvel,
                                               damping=0.98),
                                      Magnet(self.Objective,
                                             charge=self.agility,
                                             exponent=0),
                                  ])
        emiter = StaticEmitter(position=self.domain,
                               template=Particle(
                                   color=self.color,
                                   size=(rr, rr, rr),
                               ))
        emiter.emit(1, self.hull)

        if trails:
            if maxvel / r >= 20:
                self.trail = ParticleGroup(
                    renderer=BillboardRenderer(texturizer2),
                    controllers=[
                        Lifetime(trailSize[0]),
                        Fader(fade_in_start=0,
                              fade_in_end=0.1,
                              fade_out_start=0,
                              fade_out_end=trailSize[0]),
                        Growth(-1 * r),
                        PerParticleEmitter(self.hull,
                                           rate=trailSize[1],
                                           template=Particle(
                                               color=self.color,
                                               size=(rr, rr, rr),
                                           )),
                    ])

        self.ammo = ParticleGroup(renderer=BillboardRenderer(texturizer),
                                  controllers=[
                                      self.magnet,
                                      Movement(min_velocity=0,
                                               max_velocity=self.ammoMaxvel,
                                               damping=self.ammoDamp),
                                      Lifetime(self.weapon_range),
                                      Fader(fade_out_start=self.weapon_range -
                                            1,
                                            fade_out_end=self.weapon_range),
                                  ])

        self.weapon = PerParticleEmitter(
            self.hull,  # rate=self.firerate,
            template=Particle(
                velocity=self.velocity,  # fixed value
                position=(self.getPosition()),
                color=partColor,
            ),
            position=self.domain,
            size=[(wbd * 0.5, wbd * 0.5, wbd * 0.5), (wbd, wbd, wbd),
                  (wbd * 1.5, wbd * 1.5, wbd * 1.5)],
            deviation=Particle(
                velocity=(self.dispersion, self.dispersion,
                          self.dispersion * d3),
                rotation=(0, 0, math.pi / 6),
                #color=(0.05,0.05,0.05,0),
            ))

    def nearest_enemy(self,
                      ships,
                      min_dist=99999,
                      side=-1,
                      addCollectors=False,
                      limit=10,
                      lazy=lazysearch):
        colla = 0
        target = None
        min_dist **= 2
        colld = min_dist
        if self.targetMode[0] == 'custom':
            selfRadius = self.targetMode[1]
        else:
            selfRadius = self.size
        selfAmmo = self.ammo
        if lazy != -1:
            c = lazysearch
            for ship in ships:
                if colla < limit and c > 0:
                    if ship != self and ship.side != side:
                        #var = math.fabs(ship.size - selfRadius) + 0.1
                        #var = 1 if math.fabs(ship.domain.radius - selfRadius) < selfRadius else 5
                        var = 0.1 if math.fabs(ship.size -
                                               selfRadius) < selfRadius else 2
                        dist = distance_to_ship(self, ship, squared=True) * var
                        if addCollectors:
                            if dist < colld:
                                colla += 1
                                selfAmmo.bind_controller(*[ship.controller])
                        if dist < min_dist and c > 0:
                            c -= 1
                            target = ship
                            min_dist = dist
                else:
                    break
        else:
            for ship in ships:
                if colla < limit:
                    if ship != self and ship.side != side:
                        #var = math.fabs(ship.size - selfRadius) + 0.1
                        #var = 1 if math.fabs(ship.domain.radius - selfRadius) < selfRadius else 5
                        var = 0.1 if math.fabs(ship.size -
                                               selfRadius) < selfRadius else 2
                        dist = distance_to_ship(self, ship, squared=True) * var
                        if addCollectors:
                            if dist < colld:
                                colla += 1
                                selfAmmo.bind_controller(*[ship.controller])
                        if dist < min_dist:
                            target = ship
                            min_dist = dist
                else:
                    break
        return target

    def getPosition(self):
        return (self.domain.center[0], self.domain.center[1],
                self.domain.center[2])

    def getPositionVec3(self):
        return Vec3(self.domain.center[0], self.domain.center[1],
                    self.domain.center[2])

    def contact(self, particle, group, bola):
        if self.hp > 0:
            #dam = math.ceil(particle.size[0] * (particle.color[0] + particle.color[1] + particle.color[2]))  # color-based damage
            dam = math.ceil(particle.size[0])
            self.hp -= dam
            self.impacto_emitter.template.position = self.getPosition()
            self.impacto_emitter.template.size = (dam, dam, dam)
            self.impacto_emitter.emit(1, self.impacto)
            if self.hp <= 0:
                self.color = (0.5, 0.1, 0.1)
                self.controlable = False
                self.destroy()

    def destroy(self,
                flag=True):  # flag = True if it has been destroyed in combat
        global trails
        self.alive = False
        for part in self.hull:  # remove hull particle
            self.hull.kill(part)
        if flag:  # if destroyed in combat, explode
            s = self.size
            ss = s * 10
            self.impacto_emitter.template.size = (ss, ss, ss)
            self.impacto_emitter.emit(int(2 * s + 1), self.deathplosion)
            ships.remove(self)
            battle.removeShip(self.side)

    def DirToTarget(self, target):
        direction = target.getPositionVec3() - self.getPositionVec3()
        direction = direction.normalize()
        return direction

    def targetManagement(self, ships):
        stimer = self.timer
        if stimer[2] <= 0:
            stimer[2] = random.randint(100, 500)
            if self.target == None or distance_to_ship(
                    self, self.target, squared=True) > (
                        self.weapon_range * self.ammoMaxvel * 1.5)**2:
                [
                    self.ammo.unbind_controller(i)
                    for i in self.ammo.controllers
                    if i.__class__.__name__ == "Collector"
                ]
                self.target = self.nearest_enemy(
                    ships,
                    side=self.side,
                    min_dist=self.weapon_range * self.ammoMaxvel * 1.5,
                    addCollectors=self.multipleTargets,
                    lazy=False)
                if self.target and self.target.alive:
                    self.magnet.domain = self.target.domain
                    if not self.multipleTargets:
                        self.ammo.bind_controller(*[self.target.controller
                                                    ])  # NO COLLECTOR TEST
                if self.commander and self.target == None:
                    self.mission = self.commander.getOrders(self).domain.center
        if stimer[3] <= 0:
            stimer[3] = 30
            if self.target and not self.target.alive:  # targeting a dead ship
                self.target = None
                stimer[2] = 10
        if stimer[1] <= 0 and self.target:
            for part in self.hull:
                h = part
            d = self.DirToTarget(self.target)
            self.weapon.template.velocity = d * self.vo + h.velocity
            self.weapon.emit(self.shots, self.ammo)
        stimer[2] -= 1
        stimer[3] -= 1

    def moveAround(self, ships):
        timer = self.timer
        for part in self.hull:
            self.domain.center = part.position
        timer[1] -= 1
        if timer[1] < 0:
            timer[1] = self.firerate
        if not self.controlable:
            self.targetManagement(ships)
            if timer[0] <= 0:
                timer[0] = random.randint(100, 300)
                agg = int(self.combatDistance)
                self.counter[0] += 1
                if self.counter[0] == 3:
                    agg += 100
                    self.counter[0] = 0
                self.xx = random.randint(-agg, agg)
                self.yy = random.randint(-agg, agg)
                self.zz = random.randint(-agg, agg)
            if timer[4] <= 0:
                timer[4] = 2
                if self.target and self.target.alive:
                    stdc = self.target.domain.center
                    self.Objective.center[0] = stdc[0] + self.xx
                    self.Objective.center[1] = stdc[1] + self.yy
                    if d3:
                        self.Objective.center[2] = stdc[2] + self.zz
                else:
                    if self.commander:
                        pos = self.mission
                    else:
                        pos = self.domain.center
                    self.Objective.center[0] = pos[0] + self.xx
                    self.Objective.center[1] = pos[1] + self.yy
                    if d3:
                        self.Objective.center[2] = pos[2] + self.zz
            timer[0] -= 1
            timer[4] -= 1
Ejemplo n.º 29
0
        glMatrixMode(GL_MODELVIEW)
        glLoadIdentity()

    glEnable(GL_BLEND)
    glShadeModel(GL_SMOOTH)
    glBlendFunc(GL_SRC_ALPHA, GL_ONE)
    glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST)
    glDisable(GL_DEPTH_TEST)

    comet = StaticEmitter(
        rate=150,
        template=Particle(
            size=(10, 10, 0),
            color=(1, 1, 0)
        ),
        deviation=Particle(
            position=(0.1, 0.1, 0),
            velocity=(10, 10, 0.7),
            up=(0, 0, math.pi),
            rotation=(0, 0, math.pi),
            color=(0.5, 0.5, 0.5))
    )
    # Add group to ball
    ball.add_particle_group(comet)
    default_system.add_global_controller(
        Lifetime(1.75),
        # Gravity((0,-20,0)),
        Movement(min_velocity=20),
        Fader(max_alpha=0.7, fade_out_start=1, fade_out_end=1.75),
    )
Ejemplo n.º 30
0

win.on_resize = on_resize

glEnable(GL_BLEND)
glShadeModel(GL_SMOOTH)
glBlendFunc(GL_SRC_ALPHA, GL_ONE)
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST)
glDisable(GL_DEPTH_TEST)

disc = domain.Disc((0, 0, -50), (0, 0, 1), 1.5, 1.5)
viewer_plane = domain.Plane((0, 0, 0), (0, 0, -1))

jet = StaticEmitter(rate=2000,
                    position=disc,
                    template=Particle(color=(1, 1, 0), ),
                    deviation=Particle(velocity=(0, 0, 15),
                                       up=(0, 0, math.pi),
                                       color=(0.1, 0.1, 0.1)))

default_system.add_global_controller(
    Movement(max_velocity=10),
    Collector(viewer_plane),
    Gravity((0, 0, 15)),
    Growth(0.17),
    Fader(fade_in_end=0, max_alpha=0.3, fade_out_start=0, fade_out_end=8.0),
)

texture = image.load(os.path.join(os.path.dirname(__file__),
                                  'Particle.bmp')).get_texture()
group = ParticleGroup(controllers=[jet],
                      renderer=BillboardRenderer(SpriteTexturizer(texture.id)))
Ejemplo n.º 31
0
spark_tex = image.load(os.path.join(os.path.dirname(__file__),
                                    'flare3.png')).get_texture()

sparks = ParticleGroup(controllers=[
    Lifetime(3),
    Movement(damping=0.93),
    Fader(fade_out_start=0.75, fade_out_end=3.0),
],
                       renderer=BillboardRenderer(
                           SpriteTexturizer(spark_tex.id)))

spark_emitter = StaticEmitter(template=Particle(position=(win.width / 2,
                                                          win.height / 2, 0),
                                                color=(1, 1, 1)),
                              deviation=Particle(position=(1, 1, 0),
                                                 velocity=(300, 300, 0),
                                                 age=1.5),
                              size=[(3, 3, 0), (4, 4, 0), (5, 5, 0), (5, 5, 0),
                                    (6, 6, 0), (7, 7, 0)])
spark_emitter.emit(400, sparks)

fire_tex = image.load(os.path.join(os.path.dirname(__file__),
                                   'puff.png')).get_texture()

fire = ParticleGroup(controllers=[
    Lifetime(4),
    Movement(damping=0.95),
    Growth(30),
    Fader(fade_in_start=0,
          start_alpha=0,
          fade_in_end=0.5,
Ejemplo n.º 32
0
from lepton import Particle, ParticleGroup, default_system, domain
from lepton.pygame_renderer import BlitRenderer
from lepton.emitter import StaticEmitter
from lepton.controller import Gravity, Lifetime, Movement, Growth

if __name__ == '__main__':
    pygame.init()
    width, height = 800, 600
    display = pygame.display.set_mode((width, height))
    pygame.display.set_caption('Lepton pygame BlitRenderer example', 'Lepton')
    clock = pygame.time.Clock()

    bubbler = StaticEmitter(rate=80,
                            template=Particle(position=(width / 2, height - 50,
                                                        0)),
                            deviation=Particle(velocity=(5, 15, 0),
                                               size=(5, 5, 0)),
                            position=[((width * i / 4), height, 0)
                                      for i in range(5)])

    bubble = pygame.image.load(
        os.path.join(os.path.dirname(__file__), 'bubble.png'))

    water = ParticleGroup(controllers=[bubbler],
                          renderer=BlitRenderer(display,
                                                bubble,
                                                rotate_and_scale=True))

    default_system.add_global_controller(
        Lifetime(7),
        Gravity((0, -30, 0)),
Ejemplo n.º 33
0
	Movement(max_velocity=250), 
	Drag(0.0, 0.0001, (0, 800, 0), domain=up_fan),
	Drag(0.0, 0.0001, (-200, 400, 0), domain=left_fan),
	Drag(0.0, 0.0001, (200, 400, 0), domain=right_fan),
	*[bumper.controller for bumper in bumpers]
)
# Make the bounce controller for the screen boundary run last 
# to ensure no particles can "escape"
default_system.add_global_controller(
	Bounce(screen_domain, friction=0.01)
)
group = ParticleGroup(renderer=PointRenderer(point_size=ball_size))

ball_emitter = StaticEmitter(
	position=screen_domain,
	deviation=Particle(velocity=(60,60,0), color=(0.3,0.3,0.3,0)),
	color=[(1,0,0,1), (0,1,0,1), (0,0,1,1), (1,1,0,1), (0,1,1,1), (1,1,1,1)],
	mass=[1],
)
ball_emitter.emit(ball_count, group)
group.update(0)
# Kill particles inside the bumpers
for p in group:
	for bumper in bumpers:
		if p.position in bumper.domain:
			group.kill(p)

win.resize = resize
win.set_visible(True)
win.resize(win.width, win.height)
pyglet.clock.schedule_interval(default_system.update, 1.0/30.0)
#pyglet.clock.schedule_interval(lambda x: default_system.update(0.05), (1.0/5.0))
Ejemplo n.º 34
0
from lepton.controller import Gravity, Lifetime, Movement, Fader, ColorBlender

win = pyglet.window.Window(resizable=True, visible=False)
win.clear()

glEnable(GL_BLEND)
glShadeModel(GL_SMOOTH)
glBlendFunc(GL_SRC_ALPHA, GL_ONE)
glDisable(GL_DEPTH_TEST)

flame = StaticEmitter(rate=500,
                      template=Particle(
                          position=(300, 25, 0),
                          velocity=(0, 0, 0),
                          color=(1, 1, 1, 1),
                      ),
                      position=Line((win.width / 2 - 85, -15, 0),
                                    (win.width / 2 + 85, -15, 0)),
                      deviation=Particle(position=(10, 0, 0),
                                         velocity=(7, 50, 0),
                                         age=0.75))

default_system.add_global_controller(
    Lifetime(6),
    Gravity((0, 20, 0)),
    Movement(),
    ColorBlender([
        (0, (0, 0, 0.5, 0)),
        (0.5, (0, 0, 0.5, 0.2)),
        (0.75, (0, 0.5, 1, 0.6)),
        (1.5, (1, 1, 0, 0.2)),
Ejemplo n.º 35
0
spark_tex = image.load(os.path.join(os.path.dirname(__file__), 'flare3.png')).get_texture()

sparks = ParticleGroup(
	controllers=[
		Lifetime(3),
		Movement(damping=0.93),
		Fader(fade_out_start=0.75, fade_out_end=3.0),
	],
	renderer=BillboardRenderer(SpriteTexturizer(spark_tex.id)))

spark_emitter = StaticEmitter(
	template=Particle(
		position=(win.width/2,win.height/2,0), 
		color=(1,1,1)), 
	deviation=Particle(
		position=(1,1,0), 
		velocity=(300,300,0), 
		age=1.5),
	size=[(3,3,0), (4,4,0), (5,5,0), (5,5,0), (6,6,0), (7,7,0)])
spark_emitter.emit(400, sparks)

fire_tex = image.load(os.path.join(os.path.dirname(__file__), 'puff.png')).get_texture()

fire = ParticleGroup(
	controllers=[
		Lifetime(4),
		Movement(damping=0.95),
		Growth(30),
		Fader(fade_in_start=0, start_alpha=0, fade_in_end=0.5, max_alpha=0.4, 
			fade_out_start=1.0, fade_out_end=4.0)
Ejemplo n.º 36
0
    glLoadIdentity()


win.on_resize = on_resize

glEnable(GL_BLEND)
glShadeModel(GL_SMOOTH)
glBlendFunc(GL_SRC_ALPHA, GL_ONE)
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST)
glDisable(GL_DEPTH_TEST)

comet = StaticEmitter(rate=600,
                      template=Particle(
                          size=(2, 2, 0),
                          color=(1, 1, 0),
                      ),
                      deviation=Particle(velocity=(0.7, 0.7, 0.7),
                                         up=(0, 0, math.pi),
                                         rotation=(0, 0, math.pi),
                                         color=(0.5, 0.5, 0.5)))

default_system.add_global_controller(
    Lifetime(3.0),
    Movement(min_velocity=5),
    Fader(max_alpha=0.7, fade_out_start=1, fade_out_end=3.0),
)

images = [
    image.load(os.path.join(os.path.dirname(__file__),
                            'flare%s.png' % (i + 1))) for i in range(4)
]