当前位置: 首页>>代码示例>>Python>>正文


Python Engine.wrap_entity_in_game_object方法代码示例

本文整理汇总了Python中engine.Engine.wrap_entity_in_game_object方法的典型用法代码示例。如果您正苦于以下问题:Python Engine.wrap_entity_in_game_object方法的具体用法?Python Engine.wrap_entity_in_game_object怎么用?Python Engine.wrap_entity_in_game_object使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在engine.Engine的用法示例。


在下文中一共展示了Engine.wrap_entity_in_game_object方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: start

# 需要导入模块: from engine import Engine [as 别名]
# 或者: from engine.Engine import wrap_entity_in_game_object [as 别名]
def start(entities, cpp_engine, RESTART, STOP, KILL, waiting):
    try:
        while waiting: #TODO: Work out why this waiting thing is here and in EntityThread: Ask Alex!!!
            # Smallest reasonable wait while
            # allowing fast interrupts.
            #
            # Could later be replaced with locking
            # for proper interrupts.
            time.sleep(0.05)

        engine = Engine(cpp_engine)	#wrap the cpp engine in the python engine wrapper
        """
        Run the main bootstrapper loop! It's fun!
        """
        engine.print_debug("Started bootstrapper")
        game_objects = list()

        engine.print_debug(entities)

        """Grab each entity in the entities list. Wrap them in the approperiate class :D (the classes defined in game)"""
        for entity in entities:
            game_object = engine.wrap_entity_in_game_object(entity)
            game_object.initialise() #run the initialisation script on the object if anything needs to be initialised
            game_objects.append(game_object)
            engine.print_debug("Converted entity {} to game_object {}".format(entity, game_object))
            engine.print_debug("whose name is {}".format(game_object.get_name()))

        ScopedInterpreter = create_execution_scope(game_objects, engine, RESTART, STOP, KILL)
        scoped_interpreter = ScopedInterpreter()

        while True:
            try:
                script_filename = os.path.dirname(os.path.realpath(__file__)) + "/levels/{}/script.py".format(engine.get_level_location()); #TODO: grab this stuff form the config
                engine.print_debug("Reading from file: {}".format(script_filename))
                with open(script_filename, encoding="utf8") as script_file:
                    script = script_file.read()
                    #engine.print_debug(script)

                scoped_interpreter.runcode(script)

            except RESTART:
                engine.print_debug("restarting")

                waiting = False
                continue

            except STOP:
                engine.print_debug("STOPPING")
                #entity.update_status("stopped")
                waiting = True
                continue

            except KILL:
                engine.print_debug("KILLED")
                # Printing from Python when the game is dead hangs
                # everything, so don't do it.
                # TODO (Joshua): Fix this problem
                raise

            # For all other errors, output and stop
            except:
                waiting = True
                engine.print_terminal(str(traceback.format_exc()),True);

            else:
                break
    except:
        cpp_engine.print_debug(str(traceback.format_exc()))
        raise
开发者ID:ALEXLCC,项目名称:pyland,代码行数:71,代码来源:bootstrapper.py


注:本文中的engine.Engine.wrap_entity_in_game_object方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。