示例#1
0
def make_engine(setup: Callable[[BaseScene], None] = None,
                *,
                starting_scene=BaseScene,
                title="PursedPyBear",
                **engine_opts):
    """
    Setup a :class:`GameEngine`.

    This function exists for third party modules to use the same code paths
    as :func:`run` for setting up their engine. If you want to instantiate
    your own engine, you can do so directly using the
    :class:`constructor <GameEngine>`.

    :param setup: Called with the first scene to allow initialization of
       your game.
    :type setup: Callable[[BaseScene], None]
    :param starting_scene: A scene class to use. Defaults to
       :class:`~ppb.scenes.BaseScene`
    :type starting_scene: type
    :param title: The title of the rendered window.
    :type title: str
    :param engine_opts: Additional keyword arguments passed to the
       :class:`~ppb.engine.GameEngine`
    :return: A GameEngine instance.
    """
    return GameEngine(starting_scene, **_make_kwargs(setup, title,
                                                     engine_opts))
示例#2
0
def run(setup: Callable[[BaseScene], None]=None, *, log_level=logging.WARNING,
        starting_scene=BaseScene):
    """
    Run a small game.

    The resolution will 800 pixels wide by 600 pixels tall.

    setup is a callable that accepts a scene and returns None.

    log_level let's you set the expected log level. Consider logging.DEBUG if
    something is behaving oddly.

    starting_scene let's you change the scene used by the engine.
    """
    logging.basicConfig(level=log_level)

    kwargs = {
        "resolution": (800, 600),
        "scene_kwargs": {
            "set_up": setup,
        }
    }

    with GameEngine(starting_scene, **kwargs) as eng:
        eng.run()
示例#3
0
def run(setup: Callable[[BaseScene], None] = None,
        *,
        log_level=logging.WARNING,
        starting_scene=BaseScene,
        title="PursuedPyBear"):
    """
    Run a small game.

    The resolution will 800 pixels wide by 600 pixels tall.

    setup is a callable that accepts a scene and returns None.

    log_level let's you set the expected log level. Consider logging.DEBUG if
    something is behaving oddly.

    starting_scene let's you change the scene used by the engine.
    """
    logging.basicConfig(level=log_level)

    with GameEngine(starting_scene, **_make_kwargs(setup, title)) as eng:
        eng.run()
示例#4
0
def make_engine(setup: Callable[[BaseScene], None] = None, *,
                starting_scene=BaseScene, title="PursedPyBear",
                **engine_opts):
    return GameEngine(starting_scene, **_make_kwargs(setup, title, engine_opts))
示例#5
0
def run(starting_scene=BaseScene, **kwargs):
    with GameEngine(starting_scene, **kwargs) as eng:
        eng.run()
 def __init__(self, *, engine: GameEngine, **kwargs):
     super().__init__(**kwargs)
     engine.register(..., self.add_controls)