[英]Pygame RogueLike window not launching when running function
当我尝试运行这段代码时,在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()
首先,可以统一您的评论,选择#或'''。
其次,屏幕可能永远不会被初始化,因为它不包含整个文件。 也许删除game_start
并在import语句后使用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 ,它可能会有所帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.