For some reason I cannot exit this loop when I change to intro = false, can anyone help as to how I'd exit this if statement. It is my menu screen, and once I click 'new game' I want it to exit the game_intro function.
This is where I define game_intro:
def game_intro():
intro = True
if intro == True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
quit()
window.fill(superlightgrey)
fontvertical = pygame.font.SysFont("comicsansms", 100)
text = fontvertical.render("Connect 4", True, skyblue)
word = (10, 1)
window.blit(text,word)
ButtonIntro("New Game", 340, 140, 200, 50, superlightgrey, superlightgrey, "Play")
This is where I created the button function:
def ButtonIntro(msg, x, y, w, h, ic, ac, action=None):
mouse = pygame.mouse.get_pos()
click = pygame.mouse.get_pressed()
if x+w > mouse[0] > x and y+h > mouse[1] > y:
pygame.draw.rect(window, ac, (x, y, w, h))
if click[0] == 1 and action != None:
pygame.draw.rect(window, lightgrey, (x, y, w, h))
if action == "Play":
intro = False
##WHAT DO I NEED HERE TO EXIT LOOP
and this is where I call on the function:
while intro == True:
game_intro()
print("loopexited")
Aucun commentaire:
Enregistrer un commentaire