Ejemplo n.º 1
0
    def test_artist_draw_center(self):
        block = pygame.surface.Surface((2, 2))
        block.fill((255, 0, 0), pygame.Rect(0, 0, 2, 2))

        ps = particle.ParticleSystem(
            particle.Particle(0, 1, 1, 0, 3, 'pixel'),
            particle.EmitterBurst.single(1),
            artist=particle.ArtistFadeOverlay(block, particle.CENTER,
                                              [(255, 255, 255, 255),
                                               (255, 255, 255, 255)]),
        )
        world = pygame.surface.Surface((4, 4))
        world.fill((0, 255, 0), pygame.Rect(0, 0, 4, 4))

        desired_world = pygame.surface.Surface((4, 4))
        desired_world.fill((0, 255, 0), pygame.Rect(0, 0, 4, 4))
        for x in (0, 1):
            for y in (0, 1):
                # Ugh this is only 254 for some reason
                # get it together pygame
                desired_world.set_at((x, y), (254, 0, 0))

        ps.update_state(1)
        ps.draw_on(world)

        print(world.get_at((1, 1)))
        assert (compare_surfaces(desired_world, world))
Ejemplo n.º 2
0
    def test_draw_three_particles(self):
        # start it
        artist = ArtistNull()
        ps = particle.ParticleSystem(
            particle.Particle(0, -1, 1, 0, 3, 'giblet'),
            particle.EmitterBurst.single(3),
            artist=artist,
        )
        # advance 1 second
        ps.update_state(1)
        ps.draw_on(None)

        self.assertEquals(artist.count, 3)
        self.assertEquals(artist.last_particle, ps.particles[-1])
Ejemplo n.º 3
0
 def test_particle_death(self):
     # start it
     # Particles alive for 3 seconds, one generated every two seconds
     ps = particle.ParticleSystem(
         particle.Particle(0, -1, 1, 0, 3, 'giblet'),
         particle.EmitterBurst.repeat(1, 2))
     ps.update_state(1)
     self.assertEquals(len(ps.particles), 1)
     print(ps.particles)
     ps.update_state(1)
     self.assertEquals(len(ps.particles), 2)
     print(ps.particles)
     p1, p2 = ps.particles
     ps.update_state(1)
     self.assertEquals(len(ps.particles), 1)
     print(ps.particles)
     self.assertIs(p2, ps.particles[0])
Ejemplo n.º 4
0
    def test_one_particle(self):
        # start it
        ps = particle.ParticleSystem(
            particle.Particle(0, -1, 1, 0, 3, 'giblet'),
            particle.EmitterBurst.single(1))
        self.assertEquals(len(ps.particles), 0)
        self.assertTrue(ps.is_alive())

        # advance 1 second
        ps.update_state(1)
        self.assertEquals(len(ps.particles), 1, 'Particle not created')
        self.assertTrue(ps.is_alive())
        p = ps.particles[0]
        self.assertEquals(p.x, 1)  # Moved one unit in +x direction
        self.assertEquals(p.y, -1)  # unchanged
        self.assertEquals(p.dx, 1)
        self.assertEquals(p.dy, 0)
        self.assertEquals(p.life, 2)  # Lost one second of life
        self.assertEquals(p.species, 'giblet')

        # advance another second to t=2
        ps.update_state(1)
        self.assertEquals(len(ps.particles), 1, 'Particle killed too early')
        self.assertTrue(ps.is_alive())
        p = ps.particles[0]
        self.assertEquals(p.x, 2)  # Moved another unit in +x direction
        self.assertEquals(p.y, -1)  # unchanged
        self.assertEquals(p.dx, 1)
        self.assertEquals(p.dy, 0)
        self.assertEquals(p.life, 1)  # Lost another second of life
        self.assertEquals(p.species, 'giblet')

        # advance another second to t=3
        ps.update_state(1)
        self.assertEquals(len(ps.particles), 0,
                          'Particle not destroyed when life=0')
        self.assertFalse(ps.is_alive())
        # Keep `p` from previous call
        self.assertEquals(p.x, 3)  # Moved yet another unit in +x direction
        self.assertEquals(p.y, -1)  # still unchanged
        self.assertEquals(p.dx, 1)
        self.assertEquals(p.dy, 0)
        self.assertEquals(p.life, 0)  # Lost all life
        self.assertEquals(p.species, 'giblet')
Ejemplo n.º 5
0
    def test_artist_draw_center(self):
        block = pygame.surface.Surface((2, 2))
        block.fill((255, 0, 0), pygame.Rect(0, 0, 2, 2))

        ps = particle.ParticleSystem(
            particle.Particle(0, 1, 1, 0, 3, 'pixel'),
            particle.EmitterBurst.single(1),
            artist=particle.ArtistSimple(block, particle.CENTER),
        )
        world = pygame.surface.Surface((4, 4))
        world.fill((0, 255, 0), pygame.Rect(0, 0, 4, 4))

        desired_world = pygame.surface.Surface((4, 4))
        desired_world.fill((0, 255, 0), pygame.Rect(0, 0, 4, 4))
        for x in (0, 1):
            for y in (0, 1):
                desired_world.set_at((x, y), (255, 0, 0))

        ps.update_state(1)
        ps.draw_on(world)
        assert (compare_surfaces(desired_world, world))