整个夏天,我决定使用Python中的pygame模块制作一个pong版本。我已经有了游戏逻辑,现在我只是在标题画面上进行了一些额外的操作。这个特定功能的主要目标是能够在屏幕上选择一个选项并使其变为橙色突出显示。但是,每次我尝试通过向下按钮向下滚动程序结束并显示此错误时,我一直收到这个奇怪的错误错误:
error: display Surface quit
从我所读到的内容来看,这是在pygame.quit()启动之后声明的事情,所以我暂时把它从我的代码中删除了,但没有它就发生了同样的事情。 WTF?
我的代码(它有一些未使用的变量,因为我只是复制并粘贴到另一个python doc):
import pygame,random, time
pygame.init()
#GLOBAL VARIABLES
mode='normal'#Sets game theme
playerx=0 #Paddle x for gamer
playery=0 #paddle y for gamer
aix=0 #paddle x for computer
aiy=0 #paddle y form computer
x=400 #ball x coord
y=300 #ball y coord
speed_ballx=0 #xball pixel change during post blit
speed_bally=0 #yball pixel change during post blit
r=0 #redval
g=0 #greval
b=0 #blueval
#GRAPHIC ART
paddle=pygame.image.load('paddle.PNG')
ball=pygame.image.load('ball.PNG')
logo=pygame.image.load('logo.PNG')
comicsans = pygame.font.SysFont("comicsansms", 22) #comicsans font initialization
startoption = comicsans.render("START", True, (255,255,255))
instructionoption = comicsans.render("HELP", True, (255,255,255))
select=pygame.image.load('optionselect.PNG')
def pong():
main_surface.blit(ball, (x,y))#prints ball
def intsructions():
pygame.quit()
def menu():
end=False #will end while loop and end menu
opt=1 #used to decide what option the player is selecting
main_surface = pygame.display.set_mode((815,615))#creates new window
while end==False:
main_surface.blit(logo, (15,15))
pygame.display.flip()#renders all blitted objects
#The following if statements blit orange highlight on to the selected option
if opt==1:
main_surface.blit(select,(12,140))
if opt==2:
main_surface.blit(select,(12,170))
main_surface.blit(startoption, (15,140))
main_surface.blit(instructionoption, (15,170))
pygame.display.flip()#renders all blitted objects
for ev in pygame.event.get():
if ev.type == pygame.QUIT: # Window close button clicked?
end=True
if ev.type == pygame.KEYDOWN:
if ev.key == pygame.K_DOWN and opt==1: #moving down an option
opt=opt+1
print 2
if ev.key == pygame.K_DOWN and opt==2: #moving from last option (selection restarts at top)
opt=1
if ev.key == pygame.K_KP_ENTER and opt==1: #selecting START
pong()
if ev.key == pygame.K_DOWN and opt==1: #selecting INSTRUCTIONS
intsructions()
pygame.quit()
menu()
答案 0 :(得分:0)
我没有看到你在任何地方定义你的表面。 只需定义它。