Over the summer I decided to make a version of pong using the pygame module in Python. I already have the game logic and now I am just working on a title screen for some added touch. My main goal for this specific function is to be able to select an option on the screen and have it become highlighted orange. However, I keep getting this weird error error every time I try to scroll down via downward button the program ends and displays this error:
error: display Surface quit
From what I've read this comes from declaring things after pygame.quit() has been initiated so I took it out of my code temporarily, yet the same thing happened without it. WTF?
My code (It has a few unused variable due to the fact that I just copied and pasted it to another 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()
I don't see you defining your surface anywhere. Just define it.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.