Bonjour,
j'ai commencé à créer un jeu similaire à pong en python avec pygame. J'ai donc d'abord fait un menu très simple pendant lequel un boucle while tourne en attendant l'appui d'une touche. Puis, lorsque j'appuie sur la touche qui permet de sortir de la boucle pour pouvoir passer à la phase de gameplay, qui va être gérée par une autre boucle while, le jeu crash mais je n'arrive pas à savoir pourquoi. Ce sera plus compréhensible avec le 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
 
import pygame
import sys
 
#Couleurs
red = (255,0,0)
green = (0,255,0)
blue = (0,0,255)
darkBlue = (0,0,128)
white = (255,255,255)
black = (0,0,0)
pink = (255,200,200)
grey = (127,127,127)
 
#Initialisation
pygame.init()
#Souris invisible
pygame.mouse.set_visible(0)
#Timer
clock = pygame.time.Clock()
#Récupération des infos de l'écran
infoObject = pygame.display.Info()
width = infoObject.current_w
height = infoObject.current_h
#Ouverture d'une fenêtre
screen = pygame.display.set_mode((width, height), pygame.FULLSCREEN)
#Fond Gris
screen.fill(grey)
#Nom de la fenêtre
pygame.display.set_caption("Pong Remastered")
#Définition et affichage des textes
fontTitle = pygame.font.SysFont("monospace", 100)
fontSub = pygame.font.SysFont("monospace", 50)
title = fontTitle.render("Pong Remastered", 1, (255,255,255))
sub = fontSub.render("Press P to Play", 1, (255,255,255))
screen.blit(title, (width/3.9, height/3.5))
screen.blit(sub, (width/2.9, height/2.25))
#Update de l'écran
pygame.display.update()
#Définition de plusieurs loop
gamePlaying = False
menuPlaying = True
#Dans le menu
while menuPlaying:
    pygame.display.update()
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
             pygame.quit()
             sys.exit()
        if event.type == pygame.KEYDOWN:
            if event.key == pygame.K_p:
                screen.fill(grey)
                pygame.display.flip()
                pygame.time.delay(1000)
                gamePlaying = True
                menuPlaying = False                
#Quand on joue
while gamePlaying:
    pygame.draw.rect(screen, white, (width/2-25,height/2+25,50,50))
Merci d'avance.