Bonjour, j'ai un problème au niveau de mon menu avec pygame, en effet lorsque je vais sur la page 2 de mon jeu les boutons menu de la page 1 reste sur la page 2 ce qui est génant, je voulais savoir si vous pouviez m'aider rapidement. Voici mon code:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
import pygame
from pygame.locals import *
 
 
pygame.init()
fenetre = pygame.display.set_mode((640, 480))
pygame.display.set_caption("Old Memories")
 
fond = pygame.image.load("lycee.jpg")
fond = pygame.image.load("lycee.jpg").convert()
fenetre.blit(fond, (0,0))
pygame.display.flip()
 
 
son = pygame.mixer.Sound('Requiem_For_A_Dream_Full_Song_HD.wav')
son.play(loops=-1, maxtime=0, fade_ms=0)
 
Music=pygame.image.load("son.png").convert()
Music.set_colorkey((255,255,255))
fenetre.blit(Music, (10,10))
pygame.display.flip()
 
Music_rect=Music.get_rect()
Music_rect.move_ip(10,10)
 
Mute=pygame.image.load("mute.png").convert()
Mute.set_colorkey((255,255,255))
fenetre.blit(Mute, (10,50))
pygame.display.flip()
 
Mute_rect=Mute.get_rect()
Mute_rect.move_ip(10,50)
 
 
play=pygame.image.load("play.png").convert_alpha()
fenetre.blit(play, (180,150))
pygame.display.flip()
 
play_rect=play.get_rect()
play_rect.move_ip(180,150)
 
 
Exit=pygame.image.load("exit.png").convert_alpha()
fenetre.blit(Exit, (180,250))
pygame.display.flip()
 
 
Exit_rect=Exit.get_rect()
Exit_rect.move_ip(180,250)
 
 
 
old=pygame.image.load("om.png").convert_alpha()
 
fenetre.blit(old, (95,20))
pygame.display.flip()
 
mousepress=pygame.MOUSEBUTTONDOWN
continuer = 1
joue = 0
while continuer:
    for event in pygame.event.get():
                #Quitter
        if event.type == pygame.QUIT:
            pygame.quit()
            continuer = 0
        elif (Exit_rect.collidepoint(pygame.mouse.get_pos()) and pygame.mouse.get_pressed()[0]):
            pygame.quit()
 
        #Stopper
        if event.type == pygame.MOUSEBUTTONDOWN :
 
            if (Mute_rect.collidepoint(pygame.mouse.get_pos()) and pygame.mouse.get_pressed()[0]):
                    pygame.mixer.stop()
                    joue = 0
 
            elif (Music_rect.collidepoint(pygame.mouse.get_pos()) and pygame.mouse.get_pressed()[0]):
                 son.play()
                 joue = 1
 
 
        if (play_rect.collidepoint(pygame.mouse.get_pos()) and pygame.mouse.get_pressed()[0]):
                 pygame.display.update(fenetre.fill(0))            
                 fond2=pygame.image.load("noir.jpg").convert()
                 fenetre.blit(fond2, (0,0))
                 pygame.display.flip()
 
 
 
                 son = pygame.mixer.Sound('Requiem_For_A_Dream_Full_Song_HD.wav')
                 son.play(loops=-1, maxtime=0, fade_ms=0)
 
                 Music=pygame.image.load("son.png").convert()
                 Music.set_colorkey((255,255,255))
                 fenetre.blit(Music, (10,10))
                 pygame.display.flip()
 
                 Music_rect=Music.get_rect()
                 Music_rect.move_ip(10,10)
 
                 Mute=pygame.image.load("mute.png").convert()
                 Mute.set_colorkey((255,255,255))
                 fenetre.blit(Mute, (10,50))
                 pygame.display.flip()
 
                 Mute_rect=Mute.get_rect()
                 Mute_rect.move_ip(10,50)
                 font = pygame.font.SysFont("arial", 25)
 
 
                 pygame.font.init()
                 text = font.render("Hmm, ou suis-je", False,(255,255,255))
                 fenetre.blit(text, (230, 200))
                 pygame.display.flip()
J'ai essayé une version avec des fonction mais elle ne fait que charger:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import pygame
pygame.init()
fenetre = pygame.display.set_mode((640, 480))
pygame.display.set_caption("Old Memories")
black = (0,0,0)
white = (255,255,255)
def fond1():
     fond1 = True
     while fond1:
             fond = pygame.image.load("lycee.jpg")
             fond = pygame.image.load("lycee.jpg").convert()
             fenetre.blit(fond, (0,0))
             pygame.display.flip()
 
 
 
def intro():
    intro = True
    while intro:
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                pygame.quit()
                quit()
def music():
    music = True
    while music:
        for event in pygame.event.get():
 
            son = pygame.mixer.Sound('Requiem_For_A_Dream_Full_Song_HD.wav')
            son.play(loops=-1, maxtime=0, fade_ms=0)
 
            Music=pygame.image.load("son.png").convert()
            Music.set_colorkey((255,255,255))
            fenetre.blit(Music, (10,10))
            pygame.display.flip()
 
            Music_rect=Music.get_rect()
            Music_rect.move_ip(10,10)
 
            Mute=pygame.image.load("mute.png").convert()
            Mute.set_colorkey((255,255,255))
            fenetre.blit(Mute, (10,50))
            pygame.display.flip()
 
            Mute_rect=Mute.get_rect()
            Mute_rect.move_ip(10,50)
            if event.type == pygame.MOUSEBUTTONDOWN :
 
                if (Mute_rect.collidepoint(pygame.mouse.get_pos()) and pygame.mouse.get_pressed()[0]):
                        pygame.mixer.stop()
                        music = False
 
                elif (Music_rect.collidepoint(pygame.mouse.get_pos()) and pygame.mouse.get_pressed()[0]):
                     son.play()
                     music = True