Commit e4e6005c26cdb825c410e9c8f0ba9869ef1ed937

Authored by Jourlin Pierre
1 parent a55d5ff8be
Exists in master

+can change bloc size

Showing 2 changed files with 13 additions and 13 deletions Side-by-side Diff

675 KB

... ... @@ -20,7 +20,7 @@
20 20  
21 21 horloge = pygame.time.Clock()
22 22  
23   -bloc_serpent = 10
  23 +taille_bloc = 20
24 24 vitesse_serpent = 5
25 25  
26 26 style_caractères = pygame.font.SysFont("bahnschrift", 25)
27 27  
... ... @@ -31,9 +31,9 @@
31 31 valeur = style_scores.render("Votre Score: " + str(score), True, jaune)
32 32 plateau.blit(valeur, [0, 0])
33 33  
34   -def notre_serpent(bloc_serpent, corps_serpent):
  34 +def notre_serpent(taille_bloc, corps_serpent):
35 35 for x in corps_serpent:
36   - pygame.draw.rect(plateau, noir, [x[0], x[1], bloc_serpent, bloc_serpent])
  36 + pygame.draw.rect(plateau, noir, [x[0], x[1], taille_bloc, taille_bloc])
37 37  
38 38 def message(msg, color, décalage=0):
39 39 mesg = style_caractères.render(msg, True, color)
... ... @@ -52,8 +52,8 @@
52 52 corps_serpent = []
53 53 longueur_serpent = 1
54 54  
55   - repas_x = round(random.randrange(0, largeur_plateau - bloc_serpent) / 10.0) * 10.0
56   - repas_y = round(random.randrange(0, hauteur_plateau - bloc_serpent) / 10.0) * 10.0
  55 + repas_x = round(random.randrange(0, largeur_plateau - taille_bloc) / taille_bloc) * taille_bloc
  56 + repas_y = round(random.randrange(0, hauteur_plateau - taille_bloc) / taille_bloc) * taille_bloc
57 57  
58 58 while not fin_jeu:
59 59  
60 60  
61 61  
62 62  
... ... @@ -78,16 +78,16 @@
78 78 fin_jeu = True
79 79 if évènement.type == pygame.KEYDOWN:
80 80 if évènement.key == pygame.K_LEFT:
81   - x1_change = -bloc_serpent
  81 + x1_change = -taille_bloc
82 82 y1_change = 0
83 83 elif évènement.key == pygame.K_RIGHT:
84   - x1_change = bloc_serpent
  84 + x1_change = taille_bloc
85 85 y1_change = 0
86 86 elif évènement.key == pygame.K_UP:
87   - y1_change = -bloc_serpent
  87 + y1_change = -taille_bloc
88 88 x1_change = 0
89 89 elif évènement.key == pygame.K_DOWN:
90   - y1_change = bloc_serpent
  90 + y1_change = taille_bloc
91 91 x1_change = 0
92 92  
93 93 if x1 >= largeur_plateau or x1 < 0 or y1 >= hauteur_plateau or y1 < 0:
... ... @@ -95,7 +95,7 @@
95 95 x1 += x1_change
96 96 y1 += y1_change
97 97 plateau.fill(bleu)
98   - pygame.draw.rect(plateau, vert, [repas_x, repas_y, bloc_serpent, bloc_serpent])
  98 + pygame.draw.rect(plateau, vert, [repas_x, repas_y, taille_bloc, taille_bloc])
99 99 tête_serpent = []
100 100 tête_serpent.append(x1)
101 101 tête_serpent.append(y1)
102 102  
... ... @@ -107,14 +107,14 @@
107 107 if x == tête_serpent:
108 108 ferme_jeu = True
109 109  
110   - notre_serpent(bloc_serpent, corps_serpent)
  110 + notre_serpent(taille_bloc, corps_serpent)
111 111 votre_score(longueur_serpent - 1)
112 112  
113 113 pygame.display.update()
114 114  
115 115 if x1 == repas_x and y1 == repas_y:
116   - repas_x = round(random.randrange(0, largeur_plateau - bloc_serpent) / 10.0) * 10.0
117   - repas_y = round(random.randrange(0, hauteur_plateau - bloc_serpent) / 10.0) * 10.0
  116 + repas_x = round(random.randrange(0, largeur_plateau - taille_bloc) / taille_bloc) * taille_bloc
  117 + repas_y = round(random.randrange(0, hauteur_plateau - taille_bloc) / taille_bloc) * taille_bloc
118 118 longueur_serpent += 1
119 119  
120 120 horloge.tick(vitesse_serpent)