コード例 #1
0
ファイル: test_pyglet.py プロジェクト: dragonfi/pycomponents
    def test_pyglet_game_on_draw_calls_rendering_systems(self):
        game = PygletGame()

        drawer = mock.Mock(RenderingSystem, components=[])
        game.add(drawer)

        self.assertFalse(drawer.draw_all.called)

        game.on_draw()
        self.assertTrue(drawer.draw_all.called)
コード例 #2
0
ファイル: test_pyglet.py プロジェクト: dragonfi/pycomponents
    def test_pyglet_game_wraps_world_properly(self):
        world = World()
        entity = Entity()

        game = PygletGame(world)
        self.assertEqual(game.world, world)

        game.add(entity)
        self.assertIn(entity, world.entities())

        game.remove(entity)
        self.assertNotIn(entity, world.entities())
コード例 #3
0
ファイル: test_pyglet.py プロジェクト: dragonfi/pycomponents
    def test_pyglet_game_on_draw_calls_rendering_systems(self):
        game = PygletGame()

        drawer = mock.Mock(RenderingSystem, components=[])
        game.add(drawer)

        self.assertFalse(drawer.draw_all.called)

        game.on_draw()
        self.assertTrue(drawer.draw_all.called)
コード例 #4
0
ファイル: test_pyglet.py プロジェクト: dragonfi/pycomponents
    def test_pyglet_game_wraps_world_properly(self):
        world = World()
        entity = Entity()

        game = PygletGame(world)
        self.assertEqual(game.world, world)

        game.add(entity)
        self.assertIn(entity, world.entities())

        game.remove(entity)
        self.assertNotIn(entity, world.entities())
コード例 #5
0
        pyglet.gl.glPointSize(5)
        v2f = [(e.point.x, e.point.y) for e in entities]
        v2f = tuple(itertools.chain.from_iterable(v2f))
        c4B = [(e.color.r, e.color.g, e.color.b, e.color.a) for e in entities]
        c4B = tuple(itertools.chain.from_iterable(c4B))
        points = pyglet.graphics.vertex_list(len(entities), ('v2f', v2f),
                                             ('c4B', c4B))
        points.draw(pyglet.gl.GL_POINTS)


class KeyboardControl(System):
    components = [Point]

    def update(self, entity, world):
        pass


if __name__ == "__main__":
    game = PygletGame()
    game.add(FPSDisplay(), DebugDraw(), RandomImpulse(), Integrator(),
             BorderBouncer(width=game.width, height=game.height))

    border = 100
    for i in range(border, game.width - border, 10):
        for j in range(border, game.height - border, 10):
            game.add(
                Entity(Point(x=i, y=j), Velocity(x=0, y=0),
                       Color(r=i + j, g=i - j, b=i * j, a=255)))

    game.run()