Pygame RogueLike窗口在运行函数时不启动

时间:2017-12-13 21:35:30

标签: python pygame

当我尝试运行这段代码时,game_start函数中创建的pygame窗口无法启动。当我删除game_main_loop函数时,它会。我无法弄清楚这个功能有什么问题,有人有什么想法吗?

#Modules
import libtcodpy as libtcod
import pygame

#Game Files
import constants

pygame.init()

def game_start():
    '''this function initialises the main window and the pygame library'''
    #initialise the game
    MAIN_SURFACE = pygame.display.set_mode((constants.WIDTH,constants.HEIGHT))


def game_main_loop():
    '''in this function the game is looped'''
    game_quit = False

    while not game_quit:
        #get player input
        event_list = pygame.event.get()

        #process player input
        for event in event_list:
            if event.type == pygame.QUIT:
                game_quit = True

        #draw the game
        #quit the game
    pygame.quit()
    exit()

1 个答案:

答案 0 :(得分:1)

首先,可以统一您的评论,选择#或'''。

其次,屏幕可能永远不会被初始化,因为它不包含整个文件。可能会在导入语句后删除game_start并使用set_mode

示例:

#Modules
import libtcodpy as libtcod
import pygame

#Game Files
import constants

pygame.init()

MAIN_SURFACE = pygame.display.set_mode((constants.WIDTH,constants.HEIGHT))


def game_main_loop():
    '''in this function the game is looped'''
    game_quit = False

    while not game_quit:
        #get player input
        event_list = pygame.event.get()

        #process player input
        for event in event_list:
            if event.type == pygame.QUIT:
                game_quit = True

        #draw the game
        #quit the game
    pygame.quit()
    exit()
    # After, just call the game function

也许在你看到PEP-8时,可能会有所帮助。