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


Python Level.load_file方法代码示例

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


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

示例1: main

# 需要导入模块: from level import Level [as 别名]
# 或者: from level.Level import load_file [as 别名]
def main():
    pygame.init()
    edit_mode = False
    width = 800
    height = 600
    screen = pygame.display.set_mode((width, height), pygame.OPENGL|pygame.DOUBLEBUF)
    vertex_circle = GLSolidCircle(4)
    fp_circle = GLCircle(10)
    marker_circle = GLSolidCircle(3)

    glClearColor(*background_color)

    glMatrixMode(GL_PROJECTION)
    glLoadIdentity()
    gluOrtho2D(0.0, width, height, 0.0)

    level = Level()
    groups = [
        { 'dudes': [Dude( 250, 250, 1 ), Dude( 275, 250, 1 ),
                    Dude( 250, 275, 1 ), Dude( 275, 275, 1 ) ]},
        { 'dudes': [Dude( 500, 250, 0 ), Dude( 525, 250, 0 ),
                    Dude( 500, 275, 0 ), Dude( 525, 275, 0 ) ]},
    ]

    sel_group = 0
    sel_dude = 0
    mx, my = 0, 0

    def validate_sel_dude(x,z):
        n = len( groups[ sel_group ][ 'dudes' ] )
        return x if x < n else z

    while True:
    	global poly
        glClear(GL_COLOR_BUFFER_BIT)
        glMatrixMode(GL_MODELVIEW)
        glLoadIdentity()

        for event in pygame.event.get():
            if event.type == QUIT:
                return
            if event.type == KEYDOWN:
                if event.key == K_e:
                    edit_mode = not edit_mode
                    if poly != None and len(level.polys[poly]) < 3:
                    	level.del_poly(poly)
                    	poly = None

                elif event.key == K_TAB:
                    sel_group = (sel_group + 1) % len(groups)
                    # don't let the dindex point to an invalid dude.
                    sel_dude = validate_sel_dude( sel_dude, 0 )

                elif edit_mode:
                    if event.key == K_s:
                        level.save_file( 'level.dat' )
                    if event.key == K_l:
                        poly = None
                        level.load_file('level.dat')

                elif event.key == K_w:
                    sel_dude = validate_sel_dude( 0, sel_dude )
                elif event.key == K_a:
                    sel_dude = validate_sel_dude( 1, sel_dude )
                elif event.key == K_s:
                    sel_dude = validate_sel_dude( 2, sel_dude )
                elif event.key == K_d:
                    sel_dude = validate_sel_dude( 3, sel_dude )

            if event.type == MOUSEBUTTONDOWN:      
                if edit_mode:
                    do_edit_action( level, event )
                elif event.button == 1:
                    for dude in groups[sel_group]['dudes']:
                        dude.issue_orders()
            if event.type == MOUSEMOTION:
                mx, my = event.pos

        if edit_mode:
            pass
            #screen.blit(text, text.get_rect())

        # draw
        level.draw( screen, edit_mode )
        for index,group in enumerate(groups):
            for dindex, dude in enumerate(group['dudes']):
                sel_level = 0
                if sel_group == index:
                    sel_level = 2 if dindex == sel_dude else 1
                dude.draw( screen, sel_level )

        if edit_mode:
        	level.draw_vertex_circle( mx, my , vertex_circle)
        	level.draw_poly_vertex( poly, marker_circle )
        	level.draw_guide_line( poly, mx, my )
            	
        else:
            # show movement plan
            # todo: get this crap out of the renderer
            fp = level.get_firing_position_near( mx, my )
#.........这里部分代码省略.........
开发者ID:chrisforbes,项目名称:navmeshgame,代码行数:103,代码来源:main.py


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