MCPcopy Create free account
hub / github.com/ActiveState/code / gameLoop

Function gameLoop

recipes/Python/578996_Snake_the_game/recipe-578996.py:138–243  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

136
137
138def gameLoop():
139
140 global direction
141
142 direction="right"
143 running = True
144 gameOver= False
145
146 lead_x = display_width/2
147 lead_y = display_height/2
148
149 lead_x_change = 10
150 lead_y_change = 0
151
152 snakeList=[]
153 snakeLength=1
154
155 randApplex,randAppley=randAppleGen()
156
157 while running:
158 if gameOver==True:
159 message_to_screen("Game over",red,-50,size="large")
160 message_to_screen("Press C to play again or Q to quit",black,50,size="medium")
161 pygame.display.update()
162
163 while gameOver == True:
164 #gameDisplay.fill(white)
165
166 for event in pygame.event.get():
167 if event.type==pygame.QUIT:
168 gameOver=False
169 running=False
170 if event.type==pygame.KEYDOWN:
171 if event.key==pygame.K_q:
172 running=False
173 gameOver=False
174 if event.key==pygame.K_c:
175 gameLoop()
176
177 for event in pygame.event.get():
178 if event.type == pygame.QUIT:
179 running = False
180 if event.type == pygame.KEYDOWN:
181 if event.key == pygame.K_LEFT:
182 direction="left"
183 lead_x_change = -block_size
184 lead_y_change = 0
185 elif event.key == pygame.K_RIGHT:
186 direction="right"
187 lead_x_change = block_size
188 lead_y_change = 0
189 elif event.key == pygame.K_UP:
190 direction="up"
191 lead_y_change = -block_size
192 lead_x_change = 0
193 elif event.key == pygame.K_DOWN:
194 direction="down"
195 lead_y_change = block_size

Callers 1

recipe-578996.pyFile · 0.85

Calls 13

randAppleGenFunction · 0.85
message_to_screenFunction · 0.85
snakeFunction · 0.85
scoreFunction · 0.85
fillMethod · 0.80
pauseFunction · 0.70
quitFunction · 0.50
updateMethod · 0.45
getMethod · 0.45
playMethod · 0.45
appendMethod · 0.45
tickMethod · 0.45

Tested by

no test coverage detected