Example #1
0
    def test_position_read_from_body(self):
        chunk = Chunk()
        self.assertNone(chunk.position, "bad initial position")
        self.assertNone(chunk.angle, "bad initial angle")

        space = Space()

        chunk.add_to_space(space, (11, 22), 0.456)
        self.assertEquals(chunk.position, Vec2d(11, 22), "bad position")
        self.assertAlmostEquals(chunk.angle, 0.456, places=7,
            msg="bad angle")
Example #2
0
    def test_add_chunk(self):
        world = World()
        chunk = Chunk(Disc(Material.gold, 1))
        chunk.add_to_space = Listener()

        world.add_chunk(chunk, (1, 2), 0.5)

        self.assertEquals(world.chunks, set([chunk]), "chunk not added")
        self.assertEquals(
            chunk.add_to_space.args,
            (world.space, (1, 2), 0.5),
            "chunk not added to space")
Example #3
0
    def test_add_to_space_discs(self):
        disc1 = Disc(gold, 1)
        disc2 = Disc(gold, 2)
        disc3 = Disc(gold, 3)
        space = Space()
        chunk = Chunk(disc1, disc2, disc3)

        chunk.add_to_space(space, (1, 2), 0.75)

        self.assertEquals(type(chunk.body), Body, "didnt create body")
        self.assertEquals(chunk.body.position, Vec2d(1, 2), "bad position")
        self.assertEquals(chunk.body.angle, 0.75, "bad angle")

        self.assertEquals(space.bodies, set([chunk.body]),
            "body not added to space")

        self.assertEquals(len(space.shapes), 3, "shapes not added to space")
        radii = set()
        for circle in space.shapes:
            self.assertEquals(circle.body, chunk.body, "bad Circle body")
            self.assertEquals(circle.friction, 0.5, "bad friction")
            self.assertEquals(circle.elasticity, 0.5, "bad elasticity")
            radii.add(circle.radius)
        self.assertEquals(radii, set([1, 2, 3]), "bad radii")
Example #4
0
    def DONTtest_add_to_space_blocks(self):
        verts1 = [(0, 0), (0, 12), (12, 12), (12, 0)]
        block1 = Block(gold, verts1, (0, +12))
        verts2 = [(0, 0), (0, 12), (24, 12), (24, 0)]
        block2 = Block(gold, verts2)
        chunk = Chunk(block1, block2)
        space = Space()

        chunk.add_to_space((100, 200), 0)

        self.assertEquals(chunk.shards, (block1, block2,), "shards not added")

        poly1 = chunk.shards[0].shard.get_points()
        expected = [
            Vec2d(92, 104), Vec2d(92, 116),
            Vec2d(104, 116), Vec2d(104, 104)]
        self.assertEquals(poly1, expected, "bad poly1 verts")

        poly2 = chunk.shards[1].shard.get_points()
        expected = [
            Vec2d(92, 92), Vec2d(92, 104),
            Vec2d(116, 104), Vec2d(116, 92),
        ]
        self.assertEquals(poly2, expected, "bad poly2 verts")