Problème de boucles while

Bonjour,

Actuellement en train de travailler sur un projet de mini-jeu sous python j'ai un problème avec mes différentes boucles while. En effet j'ai une boucle principale qui est toujours active et des boucles "secondaire" que j'active quand j'en ai besoin. J'ai une boucle pour le menu, une pour le jeu et une pour la défaite. Le problème étant que j'ai une erreur quand j'ai voulu rajouter ma boucle gameover.. je vous laisse ci-dessous mon programme :
"""BOUCLES"""
gameover = 0
menu = 1
jeu = 0
#BOUCLE PRINCIPALE :
continuer = 1
while continuer:
    #BOUCLE MENU
    while menu:
        fen.blit(accueil,(-2,0))
        pygame.display.flip()
        for event in pygame.event.get():
            if event.type == QUIT:
                pygame.quit()
                sys.exit()
                continuer = 0
            if event.type == KEYDOWN:
                listeTouche = pygame.key.get_pressed()
                if listeTouche[K_ESCAPE]:
                    pygame.quit()
                    sys.exit()
                    continuer = 0
            elif event.type == MOUSEBUTTONUP:
                if event.button == 1:
                    if clickable_area.collidepoint(event.pos):
                        coin_song.play()
                        menu = 0
                        jeu = 1
                        fen.blit
            pygame.mouse.set_visible(True)
            pygame.mixer.music.pause()

    while gameover:
        fen.blit(gameover,(0,0))
        pygame.display.flip()

    #BOUCLE JEU
    while jeu:
        pygame.mixer.music.unpause()
        pygame.mouse.set_visible(False)
        for evenement in pygame.event.get():
            if evenement.type == QUIT:
                pygame.quit()
                sys.exit()
            if evenement.type == KEYDOWN:
                listeTouche = pygame.key.get_pressed()
                if listeTouche[K_ESCAPE]:
                    coin_song.play()
                    jeu = 0
                    menu = 1
                if listeTouche[K_RIGHT]:
                    dirX,dirY = 1,0
                    if xMario == 26:
                        for k in range(len(passage)):
                            if xMario == passage[k][0] and yMario == passage[k][1]:
                                xMario = 1
                                yMario = 8

                if listeTouche[K_LEFT]:
                    dirX,dirY = -1,0
                    if xMario == 0:
                        for k in range(len(passage)):
                            if xMario == passage[k][0] and yMario == passage[k][1]:
                                xMario = 25
                                yMario = 8

                if listeTouche[K_UP]:
                    dirX,dirY = 0,-1
                    if yMario == 0:
                        for k in range(len(passage)):
                            if xMario == passage[k][0] and yMario == passage[k][1]:
                                xMario = 13
                                yMario = 16

                if listeTouche[K_DOWN]:
                    dirX,dirY = 0,1
                    if yMario == 16:
                        for k in range(len(passage)):
                            if xMario == passage[k][0] and yMario == passage[k][1]:
                                xMario = 13
                                yMario = 0
                if(plan[yMario+dirY][xMario+dirX]) in casesAutorisées:
                    xMario = xMario+dirX
                    yMario = yMario+dirY
                if listeTouche[K_SPACE]:
                    listeLives.pop()
        deplacement = []
        for i,j in((0,1),(0,-1),(1,0),(-1,0)):
            if (plan[yEnnemi+j][xEnnemi+i]) ==0:
                deplacement.append((i,j))
        depl=random.randint(0,len(deplacement)-1)
        xEnnemi = xEnnemi+deplacement[depl][0]
        yEnnemi = yEnnemi+deplacement[depl][1]

        if xMario == xEnnemi and yMario == yEnnemi:
            print("touché")

        if len(listeLives) == 0:
            jeu = 0
            menu = 0
            gameover = 1

        fen.blit(fond,(0,0))
        fen.blit(cote_droit,(1082,0))
        AfficheMario(xMario,yMario,dirX,dirY)
        dessineFond(fen,plan)
        AfficheEnnemi(xEnnemi,yEnnemi)
        for u in range(len(listeLives)):
            fen.blit(live,listeLives[u])

            #Pièces
        fen.blit(coin1[nb],(200,320))
        nb = nb+1
        pygame.time.wait(20)
        if nb == 4:
            nb = 0


        pygame.draw.line(fen,couleur,(1080,0),(1080,680),5) #ligne separation

        pygame.display.update() #rafraichissement de la fenêtre
        fpsClock.tick(FPS)


Merci d'avance pour votre aide !

1 réponse

  • Votes
  • Date
  • Date décroissante
  1. Bonjour

    Je ne connais pas pygame ni python, mais je trouve bizarre dans ta ligne
    fen.blit(gameover,(0,0))
    la variable gameover (qui vaut 1) alors que ce devrait être une image.
    1. Oui c'est justement à cette ligne que j'ai une erreur et je ne sais pas d'où elle vient ;/