My problem is the menu, It shows "Press space to play!" But when i press it, it doesn't work! I think its a problem with the while loops I can't display code correctly so here's a link to my code https://github.com/Donutoftime44/nheon-shooter I tried putting if statements in my code like
while not done:
if menu:
...
elif not menu:
...
But it still does'nt work! Can someone help me?
You have
while menu:
for event in pg.event.get():
if event.type == QUIT:
pg.quit()
sys.exit()
if event.type == KEYUP:
if event.key == K_SPACE:
print "playing"
done = True
Because you never change menu the loop never breaks, I believe you may want to add menu = False
in if event.key == K_SPACE:
Assuming you're talking about this portion of the code:
while menu:
for event in pg.event.get():
if event.type == QUIT:
pg.quit()
sys.exit()
if event.type == KEYUP:
if event.key == K_SPACE:
print "playing"
done = True
windowdisplay.fill(colors["gray"])
windowdisplay.blit(label, ((maxx / 2) - 100, maxy - 25))
pg.display.update()
It seems like you want to end the loop when the user presses space. In which case, you need:
if event.key == K_SPACE:
menu = False
Setting done
equal to True
does nothing, since done
doesn't appear anywhere else in your code.
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.