示例#1
0
    def explode_ringed_firework(self, prev_emitter):
        """Actions that happen when a firework shell explodes, resulting in a ringed firework"""
        self.emitters.append(make_puff(prev_emitter))
        self.emitters.append(make_flash(prev_emitter))

        spark_texture, ring_texture = random.choice(SPARK_PAIRS)
        sparks = arcadeplus.Emitter(
            center_xy=prev_emitter.get_pos(),
            emit_controller=arcadeplus.EmitBurst(25),
            particle_factory=lambda emitter: arcadeplus.FadeParticle(
                filename_or_texture=spark_texture,
                change_xy=arcadeplus.rand_in_circle((0.0, 0.0), 8.0),
                lifetime=random.uniform(0.55, 0.8),
                mutation_callback=firework_spark_mutator))
        self.emitters.append(sparks)

        ring = arcadeplus.Emitter(
            center_xy=prev_emitter.get_pos(),
            emit_controller=arcadeplus.EmitBurst(20),
            particle_factory=lambda emitter: arcadeplus.FadeParticle(
                filename_or_texture=ring_texture,
                change_xy=arcadeplus.rand_on_circle(
                    (0.0, 0.0), 5.0) + arcadeplus.rand_in_circle(
                        (0.0, 0.0), 0.25),
                lifetime=random.uniform(1.0, 1.6),
                mutation_callback=firework_spark_mutator))
        self.emitters.append(ring)
示例#2
0
def make_flash(prev_emitter):
    """Return emitter that displays the brief flash when a firework shell explodes"""
    return arcadeplus.Emitter(center_xy=prev_emitter.get_pos(),
                              emit_controller=arcadeplus.EmitBurst(3),
                              particle_factory=lambda emitter: arcadeplus.
                              FadeParticle(filename_or_texture=FLASH_TEXTURE,
                                           change_xy=arcadeplus.rand_in_circle(
                                               (0.0, 0.0), 3.5),
                                           lifetime=0.15))
示例#3
0
def make_puff(prev_emitter):
    """Return emitter that generates the subtle smoke cloud left after a firework shell explodes"""
    return arcadeplus.Emitter(
        center_xy=prev_emitter.get_pos(),
        emit_controller=arcadeplus.EmitBurst(4),
        particle_factory=lambda emitter: arcadeplus.FadeParticle(
            filename_or_texture=PUFF_TEXTURE,
            change_xy=(_Vec2(arcadeplus.rand_in_circle(
                (0.0, 0.0), 0.4)) + _Vec2(0.3, 0.0)).as_tuple(),
            lifetime=4.0))
示例#4
0
def emitter_10():
    """Burst, emit from center, velocity from angle with spread"""
    e = arcadeplus.Emitter(
        center_xy=CENTER_POS,
        emit_controller=arcadeplus.EmitBurst(BURST_PARTICLE_COUNT // 4),
        particle_factory=lambda emitter: arcadeplus.LifetimeParticle(
            filename_or_texture=TEXTURE,
            change_xy=arcadeplus.rand_vec_spread_deg(90, 45, 2.0),
            lifetime=DEFAULT_PARTICLE_LIFETIME,
            scale=DEFAULT_SCALE,
            alpha=DEFAULT_ALPHA))
    return emitter_10.__doc__, e
示例#5
0
def emitter_11():
    """Burst, emit from center, velocity along a line"""
    e = arcadeplus.Emitter(
        center_xy=CENTER_POS,
        emit_controller=arcadeplus.EmitBurst(BURST_PARTICLE_COUNT // 4),
        particle_factory=lambda emitter: arcadeplus.LifetimeParticle(
            filename_or_texture=TEXTURE,
            change_xy=arcadeplus.rand_on_line((-2, 1), (2, 1)),
            lifetime=DEFAULT_PARTICLE_LIFETIME,
            scale=DEFAULT_SCALE,
            alpha=DEFAULT_ALPHA))
    return emitter_11.__doc__, e
示例#6
0
def emitter_9():
    """Burst, emit from center, velocity in fixed angle and random speed"""
    e = arcadeplus.Emitter(
        center_xy=CENTER_POS,
        emit_controller=arcadeplus.EmitBurst(BURST_PARTICLE_COUNT // 4),
        particle_factory=lambda emitter: arcadeplus.LifetimeParticle(
            filename_or_texture=TEXTURE,
            change_xy=arcadeplus.rand_vec_magnitude(45, 1.0, 4.0),
            lifetime=DEFAULT_PARTICLE_LIFETIME,
            scale=DEFAULT_SCALE,
            alpha=DEFAULT_ALPHA))
    return emitter_9.__doc__, e
示例#7
0
def emitter_8():
    """Burst, emit from center, velocity in rectangle"""
    e = arcadeplus.Emitter(
        center_xy=CENTER_POS,
        emit_controller=arcadeplus.EmitBurst(BURST_PARTICLE_COUNT),
        particle_factory=lambda emitter: arcadeplus.LifetimeParticle(
            filename_or_texture=TEXTURE,
            change_xy=arcadeplus.rand_in_rect((-2.0, -2.0), 4.0, 4.0),
            lifetime=DEFAULT_PARTICLE_LIFETIME,
            scale=DEFAULT_SCALE,
            alpha=DEFAULT_ALPHA))
    return emitter_8.__doc__, e
示例#8
0
def emitter_1():
    """Burst, emit from center, particle lifetime 1.0 seconds"""
    e = arcadeplus.Emitter(
        center_xy=CENTER_POS,
        emit_controller=arcadeplus.EmitBurst(BURST_PARTICLE_COUNT),
        particle_factory=lambda emitter: arcadeplus.LifetimeParticle(
            filename_or_texture=TEXTURE,
            change_xy=arcadeplus.rand_in_circle(
                (0.0, 0.0), PARTICLE_SPEED_FAST),
            lifetime=1.0,
            scale=DEFAULT_SCALE,
            alpha=DEFAULT_ALPHA))
    return emitter_1.__doc__, e
示例#9
0
def emitter_7():
    """Burst, emit from center, velocity fixed speed around 360 degrees"""
    e = arcadeplus.Emitter(
        center_xy=CENTER_POS,
        emit_controller=arcadeplus.EmitBurst(BURST_PARTICLE_COUNT // 4),
        particle_factory=lambda emitter: arcadeplus.LifetimeParticle(
            filename_or_texture=TEXTURE,
            change_xy=arcadeplus.rand_on_circle(
                (0.0, 0.0), PARTICLE_SPEED_FAST),
            lifetime=DEFAULT_PARTICLE_LIFETIME,
            scale=DEFAULT_SCALE,
            alpha=DEFAULT_ALPHA))
    return emitter_7.__doc__, e
示例#10
0
def emitter_3():
    """Burst, emit in circle"""
    e = arcadeplus.Emitter(
        center_xy=CENTER_POS,
        emit_controller=arcadeplus.EmitBurst(BURST_PARTICLE_COUNT),
        particle_factory=lambda emitter: arcadeplus.LifetimeParticle(
            filename_or_texture=TEXTURE,
            change_xy=arcadeplus.rand_in_circle(
                (0.0, 0.0), PARTICLE_SPEED_SLOW),
            lifetime=DEFAULT_PARTICLE_LIFETIME,
            center_xy=arcadeplus.rand_in_circle((0.0, 0.0), 100),
            scale=DEFAULT_SCALE,
            alpha=DEFAULT_ALPHA))
    return emitter_3.__doc__, e
示例#11
0
    def explode_firework(self, prev_emitter):
        """Actions that happen when a firework shell explodes, resulting in a typical firework"""
        self.emitters.append(make_puff(prev_emitter))
        self.emitters.append(make_flash(prev_emitter))

        spark_texture = random.choice(SPARK_TEXTURES)
        sparks = arcadeplus.Emitter(
            center_xy=prev_emitter.get_pos(),
            emit_controller=arcadeplus.EmitBurst(random.randint(30, 40)),
            particle_factory=lambda emitter: arcadeplus.FadeParticle(
                filename_or_texture=spark_texture,
                change_xy=arcadeplus.rand_in_circle((0.0, 0.0), 9.0),
                lifetime=random.uniform(0.5, 1.2),
                mutation_callback=firework_spark_mutator))
        self.emitters.append(sparks)
示例#12
0
def emitter_34():
    """Dynamically generated textures, burst emitting, fading particles"""
    textures = [
        arcadeplus.make_soft_circle_texture(48, p)
        for p in (arcadeplus.color.GREEN, arcadeplus.color.BLUE_GREEN)
    ]
    e = arcadeplus.Emitter(
        center_xy=CENTER_POS,
        emit_controller=arcadeplus.EmitBurst(BURST_PARTICLE_COUNT),
        particle_factory=lambda emitter: arcadeplus.FadeParticle(
            filename_or_texture=random.choice(textures),
            change_xy=arcadeplus.rand_in_circle(
                (0.0, 0.0), PARTICLE_SPEED_FAST),
            lifetime=DEFAULT_PARTICLE_LIFETIME,
            scale=DEFAULT_SCALE))
    return emitter_34.__doc__, e
示例#13
0
def emitter_5():
    """Burst, emit in rectangle"""
    width, height = 200, 100
    centering_offset = (-width / 2, -height / 2)
    e = arcadeplus.Emitter(
        center_xy=CENTER_POS,
        emit_controller=arcadeplus.EmitBurst(BURST_PARTICLE_COUNT),
        particle_factory=lambda emitter: arcadeplus.LifetimeParticle(
            filename_or_texture=TEXTURE,
            change_xy=arcadeplus.rand_in_circle(
                (0.0, 0.0), PARTICLE_SPEED_SLOW),
            lifetime=DEFAULT_PARTICLE_LIFETIME,
            center_xy=arcadeplus.rand_in_rect(centering_offset, width, height),
            scale=DEFAULT_SCALE,
            alpha=DEFAULT_ALPHA))
    return emitter_5.__doc__, e
示例#14
0
    def explode_sparkle_firework(self, prev_emitter):
        """Actions that happen when a firework shell explodes, resulting in a sparkling firework"""
        self.emitters.append(make_puff(prev_emitter))
        self.emitters.append(make_flash(prev_emitter))

        spark_texture = random.choice(SPARK_TEXTURES)
        sparks = arcadeplus.Emitter(
            center_xy=prev_emitter.get_pos(),
            emit_controller=arcadeplus.EmitBurst(random.randint(30, 40)),
            particle_factory=lambda emitter: AnimatedAlphaParticle(
                filename_or_texture=spark_texture,
                change_xy=arcadeplus.rand_in_circle((0.0, 0.0), 9.0),
                start_alpha=255,
                duration1=random.uniform(0.6, 1.0),
                mid_alpha=0,
                duration2=random.uniform(0.1, 0.2),
                end_alpha=255,
                mutation_callback=firework_spark_mutator))
        self.emitters.append(sparks)
示例#15
0
def make_burst_emitter(center_xy: Point,
                       filenames_and_textures: Sequence[FilenameOrTexture],
                       particle_count: int,
                       particle_speed: float,
                       particle_lifetime_min: float,
                       particle_lifetime_max: float,
                       particle_scale: float = 1.0,
                       fade_particles: bool = True):
    """Returns an emitter that emits all of its particles at once"""
    particle_factory: Type[
        arcadeplus.LifetimeParticle] = arcadeplus.LifetimeParticle
    if fade_particles:
        particle_factory = arcadeplus.FadeParticle
    return arcadeplus.Emitter(
        center_xy=center_xy,
        emit_controller=arcadeplus.EmitBurst(particle_count),
        particle_factory=lambda emitter: particle_factory(
            filename_or_texture=random.choice(filenames_and_textures),
            change_xy=arcadeplus.rand_in_circle((0.0, 0.0), particle_speed),
            lifetime=random.uniform(particle_lifetime_min,
                                    particle_lifetime_max),
            scale=particle_scale))