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 = arcade.Emitter(
            center_xy=prev_emitter.get_pos(),
            emit_controller=arcade.EmitBurst(25),
            particle_factory=lambda emitter: arcade.FadeParticle(
                filename_or_texture=spark_texture,
                change_xy=arcade.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 = arcade.Emitter(
            center_xy=prev_emitter.get_pos(),
            emit_controller=arcade.EmitBurst(20),
            particle_factory=lambda emitter: arcade.FadeParticle(
                filename_or_texture=ring_texture,
                change_xy=arcade.rand_on_circle(
                    (0.0, 0.0), 5.0) + arcade.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 createParticleBurst(x0,
                        y0,
                        partInterval,
                        totalDuration,
                        partSize,
                        partScale,
                        partSpeed,
                        color,
                        startAlpha,
                        endAlpha,
                        imagePath=None):
    e = arcade.Emitter(
        center_xy=(x0, y0),
        emit_controller=arcade.EmitterIntervalWithTime(partInterval,
                                                       totalDuration),
        particle_factory=lambda emitter: arcade.FadeParticle(
            filename_or_texture=imagePath
            if imagePath is not None else arcade.make_circle_texture(
                partSize, color),
            change_xy=arcade.rand_in_circle((0.0, 0.0), partSpeed),
            scale=partScale,
            lifetime=uniform(totalDuration / 4, totalDuration),
            start_alpha=startAlpha,
            end_alpha=endAlpha,
        ),
    )
    return e
Пример #3
0
def emitter_36():
    """Moving emitter. Particles spawn relative to emitter."""

    class MovingEmitter(arcade.Emitter):
        def __init__(self, *args, **kwargs):
            super().__init__(*args, **kwargs)
            self.elapsed = 0.0

        def update(self):
            super().update()
            self.elapsed += 1 / 60
            self.center_x = sine_wave(self.elapsed, 0, SCREEN_WIDTH, SCREEN_WIDTH / 100)
            self.center_y = sine_wave(self.elapsed, 0, SCREEN_HEIGHT, SCREEN_HEIGHT / 100)

    e = MovingEmitter(
        center_xy=CENTER_POS,
        emit_controller=arcade.EmitInterval(0.005),
        particle_factory=lambda emitter: arcade.FadeParticle(
            filename_or_texture=TEXTURE,
            change_xy=arcade.rand_in_circle((0.0, 0.0), 0.1),
            lifetime=random.uniform(1.5, 5.5),
            scale=random.uniform(0.05, 0.2)
        )
    )
    return emitter_36.__doc__, e
Пример #4
0
    def make_gun_fire_emitter(self):
        """
        Function to create a firing particle effect for when the tank fires.
        Currently is set to match the location and orientation of the tank.
        If the tank is moving rapidly, it looks a little silly at the moment,
        but to fix that I'd have to update the emitter position on update and
        I'm not sure that is worth it.

        Inputs:
            None
        Outputs:
            (emitter obj): tank tread particle
        """
        front_x = self.player.center_x + (
            self.player.width / 2 + self.t_shot.height / 2 + 5
        ) * np.cos(self.player.radians)
        front_y = self.player.center_y + (
            self.player.height / 2 + self.t_shot.height / 2 + 5
        ) * np.sin(self.player.radians)
        return arcade.Emitter(
            center_xy=(front_x, front_y),
            emit_controller=arcade.EmitBurst(1),
            particle_factory=lambda emitter: arcade.FadeParticle(
                filename_or_texture=self.t_shot,
                angle=self.player.angle + 90,  # correcting for texture orientation
                change_xy=(0, 0),
                lifetime=0.4,
                scale=1,
            ),
        )
def make_flash(prev_emitter):
    """Return emitter that displays the brief flash when a firework shell explodes"""
    return arcade.Emitter(center_xy=prev_emitter.get_pos(),
                          emit_controller=arcade.EmitBurst(3),
                          particle_factory=lambda emitter: arcade.FadeParticle(
                              filename_or_texture=FLASH_TEXTURE,
                              change_xy=arcade.rand_in_circle((0.0, 0.0), 3.5),
                              lifetime=0.15))
Пример #6
0
def make_puff(prev_emitter):
    """Return emitter that generates the subtle smoke cloud left after a firework shell explodes"""
    return arcade.Emitter(
        pos=prev_emitter.get_pos(),
        emit_controller=arcade.EmitBurst(4),
        particle_factory=lambda emitter: arcade.FadeParticle(
            filename_or_texture=PUFF_TEXTURE,
            vel=arcade.rand_in_circle(Vec2d.zero(), 0.4) + Vec2d(0.3, 0.0),
            lifetime=4.0))
def make_spinner():
    spinner = arcade.Emitter(
        center_xy=(SCREEN_WIDTH / 2, SPINNER_HEIGHT - 5),
        emit_controller=arcade.EmitterIntervalWithTime(0.025, 2.0),
        particle_factory=lambda emitter: arcade.FadeParticle(
            filename_or_texture=random.choice(STAR_TEXTURES),
            change_xy=(0, 6.0),
            lifetime=0.2))
    spinner.change_angle = 16.28
    return spinner
def make_puff(prev_emitter):
    """Return emitter that generates the subtle smoke cloud left after a firework shell explodes"""
    return arcade.Emitter(
        center_xy=prev_emitter.get_pos(),
        emit_controller=arcade.EmitBurst(4),
        particle_factory=lambda emitter: arcade.FadeParticle(
            filename_or_texture=PUFF_TEXTURE,
            change_xy=(_Vec2(arcade.rand_in_circle(
                (0.0, 0.0), 0.4)) + _Vec2(0.3, 0.0)).as_tuple(),
            lifetime=4.0))
Пример #9
0
def heart_poof(position):
    return arcade.Emitter(
        center_xy=(position.x, position.y),
        emit_controller=arcade.EmitBurst(50),
        particle_factory=lambda emitter: arcade.FadeParticle(
            filename_or_texture=arcade.load_texture(HEART_FULL),
            change_xy=arcade.rand_in_circle((0.0, 0.0), 1.0),
            lifetime=1.5,
            scale=0.1 * random.random(),
        ),
    )
Пример #10
0
 def create_emitter(self):
     spark_texture = random.choice(SPARK_TEXTURES)
     self.emitter = arcade.Emitter(
         #center_xy=prev_emitter.get_pos(),
         center_xy=(500, 500),
         emit_controller=arcade.EmitBurst(random.randint(30, 40)),
         particle_factory=lambda emitter: arcade.FadeParticle(
             filename_or_texture=spark_texture,
             change_xy=arcade.rand_in_circle((0.0, 0.0), 9.0),
             lifetime=random.uniform(0.5, 1.2),
             mutation_callback=firework_spark_mutator))
def emitter_33():
    """Particles that fade over time"""
    e = arcade.Emitter(
        pos=CENTER_POS,
        emit_controller=arcade.EmitterIntervalWithTime(DEFAULT_EMIT_INTERVAL,
                                                       DEFAULT_EMIT_DURATION),
        particle_factory=lambda emitter: arcade.FadeParticle(
            filename_or_texture=TEXTURE,
            vel=arcade.rand_in_circle(Vec2d.zero(), PARTICLE_SPEED_FAST),
            lifetime=DEFAULT_PARTICLE_LIFETIME,
            scale=DEFAULT_SCALE))
    return emitter_33.__doc__, e
Пример #12
0
def emitter_34():
    """Dynamically generated textures, burst emitting, fading particles"""
    textures = [arcade.make_soft_circle_texture(48, p) for p in (arcade.color.GREEN, arcade.color.BLUE_GREEN)]
    e = arcade.Emitter(
        center_xy=CENTER_POS,
        emit_controller=arcade.EmitBurst(BURST_PARTICLE_COUNT),
        particle_factory=lambda emitter: arcade.FadeParticle(
            filename_or_texture=random.choice(textures),
            change_xy=arcade.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 firework(position):
    x = position.x
    y = position.y

    return arcade.Emitter(
        center_xy=(x, y),
        change_xy=(0, 5),
        emit_controller=arcade.EmitterIntervalWithTime(emit_interval=0.1, lifetime=3),
        particle_factory=lambda emitter: arcade.FadeParticle(
            filename_or_texture=FIREWORK_PARTICLE,
            change_xy=arcade.rand_in_circle((0.0, 0.0), 1.0),
            lifetime=1.5,
            scale=0.5 * random.random(),
        ),
    )
    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 = arcade.Emitter(
            center_xy=prev_emitter.get_pos(),
            emit_controller=arcade.EmitBurst(random.randint(30, 40)),
            particle_factory=lambda emitter: arcade.FadeParticle(
                filename_or_texture=spark_texture,
                change_xy=arcade.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)
Пример #15
0
def createParticleEmitter(x0, y0, partNB, partSize, partScale, partSpeed,
                          color, startAlpha, endAlpha):
    e = arcade.Emitter(
        center_xy=(x0, y0),
        emit_controller=arcade.EmitMaintainCount(partNB),
        particle_factory=lambda emitter: arcade.FadeParticle(
            filename_or_texture=arcade.make_circle_texture(partSize, color),
            change_xy=arcade.rand_in_circle((0.0, 0.0), partSpeed),
            lifetime=uniform(0.01, 0.4),
            scale=partScale,
            start_alpha=startAlpha,
            end_alpha=endAlpha,
        ),
    )
    return e
Пример #16
0
 def generate_smoke(self):
     """
     Particle generator to create smoking wreck
     """
     offset = random.randint(-10, 10)
     smoke = arcade.Emitter(
         center_xy=(self.center_x + offset, self.center_y + offset),
         emit_controller=arcade.EmitMaintainCount(50),
         particle_factory=lambda emitter: arcade.FadeParticle(
             filename_or_texture=self.texture_smoke,
             change_xy=arcade.rand_vec_spread_deg(90, 20, 2),
             lifetime=random.random() * 2,
         ),
     )
     self.emitter = smoke
     return smoke
def emitter_35():
    """Use most features"""
    soft_circle = arcade.make_soft_circle_texture(80, (255, 64, 64))
    textures = (TEXTURE, TEXTURE2, TEXTURE3, TEXTURE4, TEXTURE5, TEXTURE6,
                TEXTURE7, soft_circle)
    e = arcade.Emitter(
        pos=CENTER_POS,
        emit_controller=arcade.EmitterIntervalWithTime(0.01, 1.0),
        particle_factory=lambda emitter: arcade.FadeParticle(
            filename_or_texture=random.choice(textures),
            vel=arcade.rand_in_circle(Vec2d.zero(), PARTICLE_SPEED_FAST * 2),
            lifetime=random.uniform(1.0, 3.5),
            angle=random.uniform(0, 360),
            change_angle=random.uniform(-3, 3),
            scale=random.uniform(0.1, 0.8)))
    return emitter_35.__doc__, e
Пример #18
0
def bee_poof(position):
    return arcade.Emitter(
        center_xy=(position.x, position.y),
        emit_controller=arcade.EmitBurst(50),
        particle_factory=lambda emitter: arcade.FadeParticle(
            filename_or_texture=random.choice(
                [
                    arcade.load_texture("data/kenney_particlePack_1.1/light_01.png"),
                    arcade.load_texture("data/kenney_particlePack_1.1/light_02.png"),
                    arcade.load_texture("data/kenney_particlePack_1.1/light_03.png"),
                ]
            ),
            change_xy=arcade.rand_in_circle((0.0, 0.0), 1.0),
            lifetime=1.5,
            scale=0.1 * random.random(),
        ),
    )
def make_rocket(emit_done_cb):
    """Emitter that displays the smoke trail as the firework shell climbs into the sky"""
    rocket = RocketEmitter(
        center_xy=(random.uniform(100, SCREEN_WIDTH - 100), 25),
        emit_controller=arcade.EmitterIntervalWithTime(0.04, 2.0),
        particle_factory=lambda emitter: arcade.FadeParticle(
            filename_or_texture=ROCKET_SMOKE_TEXTURE,
            change_xy=arcade.rand_in_circle((0.0, 0.0), 0.08),
            scale=0.5,
            lifetime=random.uniform(1.0, 1.5),
            start_alpha=100,
            end_alpha=0,
            mutation_callback=rocket_smoke_mutator),
        emit_done_cb=emit_done_cb)
    rocket.change_x = random.uniform(-1.0, 1.0)
    rocket.change_y = random.uniform(5.0, 7.25)
    return rocket
Пример #20
0
 def player_gets_hit(self):
     """
     Function to turn the player red when it gets hit 
     Inputs: 
         None
     Outputs:
     """
     return arcade.Emitter(
         center_xy=(self.player.center_x, self.player.center_y),
         emit_controller=arcade.EmitBurst(1),
         particle_factory=lambda emitter: arcade.FadeParticle(
             filename_or_texture=self.t_hit,
             angle=self.player.angle,
             change_xy=(0, 0),
             lifetime=0.4,
             scale=1,
         ),
     )
Пример #21
0
    def create_emitter(self):
        ww, wh = arcade.get_window().get_size()
        spark_texture = random.choice(SPARK_TEXTURES)

        def firework_spark_mutator(particle: arcade.FadeParticle):
            """mutation_callback shared by all fireworks sparks"""
            # gravity
            particle.change_y += -0.03
            # drag
            particle.change_x += self.change
            particle.change_y += self.change

        self.emitter = arcade.Emitter(
            center_xy=(ww / 2, wh / 2),
            emit_controller=arcade.EmitBurst(random.randint(30, 40)),
            particle_factory=lambda emitter: arcade.FadeParticle(
                filename_or_texture=spark_texture,
                change_xy=arcade.rand_in_circle((0.0, 0.0), 9.0),
                lifetime=random.uniform(0.5, 1.2),
                mutation_callback=firework_spark_mutator))
Пример #22
0
 def draw_treads(self):
     """
     Function to create treads particle effect for when the tank moves.
     Currently is set to match the location and orientation of the tank.
     Inputs:
         None
     Outputs:
         (emitter obj): tank tread particle
     """
     return arcade.Emitter(
         center_xy=(self.player.center_x, self.player.center_y),
         emit_controller=arcade.EmitBurst(1),
         particle_factory=lambda emitter: arcade.FadeParticle(
             filename_or_texture=self.t_tread,
             angle=self.player.angle + 90,
             change_xy=(0, 0),
             lifetime=0.4,
             scale=0.5,
         ),
     )
Пример #23
0
def smoke_poof(position):
    return arcade.Emitter(
        center_xy=(position.x, position.y),
        emit_controller=arcade.EmitBurst(25),
        particle_factory=lambda emitter: arcade.FadeParticle(
            filename_or_texture=random.choice(
                [
                    arcade.load_texture("data/kenney_particlePack_1.1/smoke_01.png"),
                    arcade.load_texture("data/kenney_particlePack_1.1/smoke_02.png"),
                    arcade.load_texture("data/kenney_particlePack_1.1/smoke_03.png"),
                    arcade.load_texture("data/kenney_particlePack_1.1/smoke_04.png"),
                    arcade.load_texture("data/kenney_particlePack_1.1/smoke_05.png"),
                    arcade.load_texture("data/kenney_particlePack_1.1/smoke_06.png"),
                    arcade.load_texture("data/kenney_particlePack_1.1/smoke_07.png"),
                    arcade.load_texture("data/kenney_particlePack_1.1/smoke_08.png"),
                ]
            ),
            change_xy=arcade.rand_in_circle((0.0, 0.0), 1.0),
            lifetime=.5,
            scale=0.1 * random.random(),
            mutation_callback=glowing_and_fade
        ),
    )
    def make_boom(self, x, y):
        """
        Function to return a shortlived burst emitter whenever we want. Potentially I
        could have had this appended directly to the emitter list, but instead I return
        the emitter itself and will have to add it to the list after that.

        Inputs:
            x (float): the center x position of the burst
            y (float): the center y position of the burst
        Outputs:
            (emitter object): circular green burst of spinning square particles
        """
        return arcade.Emitter(
            center_xy=(x, y),
            emit_controller=arcade.EmitBurst(100),
            particle_factory=lambda emitter: arcade.FadeParticle(
                filename_or_texture=self.text_green,
                change_xy=arcade.rand_in_circle((0, 0), 10),
                change_angle=10,
                lifetime=3,
                scale=0.5,
            ),
        )
Пример #25
0
def explosion_factory(pos, color):
    logging.info(f"Creating explosion emitter at {pos}")

    textures = [
        arcade.Texture(f"{time.time()}", Image.new("RGBA", (10, 10), p))
        for p in rand_color(color)
    ]

    line_e = arcade.Emitter(
        center_xy=(0.0, 0.0),
        emit_controller=arcade.EmitterIntervalWithCount(
            EXPLOSION_EMIT_INTERVAL, EXPLOSION_NUM_PARTICLE),
        particle_factory=lambda emitter: arcade.FadeParticle(
            filename_or_texture=random.choice(textures),
            change_xy=arcade.rand_in_circle((0.0, 0.0), PARTICLE_SPEED_FAST),
            lifetime=EXPLOSION_PARTICLE_LIFETIME,
            center_xy=pos,
            change_angle=random.uniform(-6, 6),
            scale=EXPLOSION_SCALE,
        ),
    )
    line_e.change_angle = 16
    return line_e
Пример #26
0
    def make_explosion(self, x, y):
        """
        Function to create an explosion particle effect for when a bullet
        strikes a tank. Will return the emitter object which should be appended
        to the emitter list.

        Inputs:
            x (float): the center x position of the explosion
            y (float): the center y position of the explosion
        Outputs:
            (emitter obj): explosion particles
        """
        return arcade.Emitter(
            center_xy=(x, y),
            emit_controller=arcade.EmitBurst(30),
            particle_factory=lambda emitter: arcade.FadeParticle(
                filename_or_texture=self.t_explosion,
                change_xy=arcade.rand_in_circle((0, 0), 2),
                change_angle=10,
                lifetime=0.4,
                scale=0.75,
            ),
        )
Пример #27
0
def dash_emitter_factory(color, pos_a, pos_b):
    """Interval, emit on line"""
    logging.info("Creating dash emitter")

    if pos_a[0] > pos_b[0]:
        angle = 0
    else:
        angle = 180
    textures = [
        arcade.Texture(f"{time.time()}", Image.new("RGBA", (10, 10), p))
        for p in rand_color(color)
    ]
    line_e = arcade.Emitter(
        center_xy=(0.0, 0.0),
        emit_controller=arcade.EmitterIntervalWithTime(LINE_EMIT_INTERVAL,
                                                       DEFAULT_EMIT_DURATION),
        particle_factory=lambda emitter: arcade.LifetimeParticle(
            filename_or_texture=random.choice(textures),
            change_xy=arcade.rand_in_circle((0.0, 0.0), PARTICLE_SPEED_SLOW),
            lifetime=DEFAULT_PARTICLE_LIFETIME,
            center_xy=arcade.rand_on_line(pos_a, pos_b),
            scale=LINE_SCALE,
            alpha=DEFAULT_ALPHA,
        ),
    )
    exhaust_plume_e = arcade.Emitter(
        center_xy=pos_a,
        emit_controller=arcade.EmitterIntervalWithTime(PLUME_EMIT_INTERVAL,
                                                       PLUME_EMIT_DURATION),
        particle_factory=lambda emitter: arcade.FadeParticle(
            filename_or_texture=random.choice(textures),
            change_xy=arcade.rand_vec_spread_deg(angle, 25, 4.0),
            lifetime=PLUME_PARTICLE_LIFETIME,
            scale=PLUME_SCALE,
        ),
    )
    return line_e, exhaust_plume_e