我目前正在尝试学习在业余时间制作类似rogue的游戏。每当我尝试调用程序在两者之间创建一个窗口时,都会发生某些事情。我正在看教程(https://www.youtube.com/playlist?list=PLKUel_nHsTQ1yX7tQxR_SQRdcOFyXfNAb),但我不知道第3部分发生了什么,因为代码在第2部分中运行了窗口。它不会给我一个错误,只是在以下情况下不运行该窗口有人知道怎么了,那太好了,谢谢。
我尝试重新观看教程,看看是否错过了键入或删除的内容,但没有任何反应。 main_game.py
import libtcodpy as libtcod
import pygame
#GAME FILES
import constance
## pseudo programming ##
class struct_tiles:
def __init__(self, block_path):
self.block_path = block_path
def map_create():
new_map = [[ struct_tiles(False) for y in range(0, constance.MAP_HEIGHT)] for x in range(0, constance.MAP_WIDTH)]
new_map[10][10].block_path = True
new_map[10][15].block_path = True
return new_map
def draw_game():
## CLEAR SURFACE
SURFACE_MAIN.fill(constance.COLOR_DEFAULT_BACKGROUND)
## DRAW MAP
draw_map(GAME_MAP)
## DRAW PLAYER
SURFACE_MAIN.blit(constance.S_PLAYER, ( 200, 200 ))
## UPDATE DISPLAY
pygame.display.flip()
def draw_map(map_to_draw):
for x in range(0, constance.MAP_WIDTH):
for y in range(0, constance.MAP_HEIGHT):
if map_to_draw[x][y].block_path == True:
#draw wall
SURFACE_MAIN.blit(constance.S_WALL, ( x*constance.CELL_WIDTH, y*constance.CELL_HEIGHT))
else:
#draw floor
SURFACE_MAIN.blit(constance.S_FLOOR, ( x*constance.CELL_WIDTH, y*constance.CELL_HEIGHT))
def game_main_loop():
''' IN THIS FUNCTION WE LOOP THE MAIN GAME'''
game_quit = False
while not game_quit:
#TODO get player input
events_list = pygame.event.get()
#PROCESS PLAYER INPUT
for event in events_list:
if event.type == pygame.QUIT:
game_quit = True
#DRAW THE GAME
draw_game()
#QUIT GAME
pygame.quit()
exit()
def game_initialize():
'''THIS FUNCTION INITIALIZES THE MAIN WINDOW AND PYGAME'''
global SURFACE_MAIN, GAME_MAP
#initialize pygame
pygame.init()
SURFACE_MAIN = pygame.display.set_mode( (constance.GAME_WIDTH,constance.GAME_HEIGHT) )
GAME_MAP = map_create()
if __name__ == '__main_game__':
game_initialize()
game_main_loop()
##constance.py##
import pygame
pygame.init()
## GAME SIZES
GAME_WIDTH = 800
GAME_HEIGHT = 600
CELL_WIDTH = 32
CELL_HEIGHT = 32
## COLOR DEF
COLOR_BLACK = (0, 0, 0)
COLOR_WHITE = (255, 255, 255)
COLOR_GREY = (100, 100, 100)
## GAME COLORS
COLOR_DEFAULT_BACKGROUND = COLOR_GREY
## SPRITES
S_PLAYER = pygame.image.load("data/cobra1.png")
S_WALL = pygame.image.load("data/wall1.png")
S_FLOOR = pygame.image.load("data/floor1.png")
## MAP VARS
MAP_WIDTH = 30
MAP_HEIGHT = 30