MCPcopy Index your code
hub / github.com/geekcomputers/Python / game_loop

Function game_loop

Snake Game Using Turtle/main.py:169–189  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

167
168# --- MAIN GAME LOOP ---
169def game_loop():
170 global game_state
171 if game_state == "playing":
172 snake.move()
173 # Collision with food
174 if snake.head.distance(food) < 20:
175 food.refresh(LEFT_WALL, RIGHT_WALL, BOTTOM_WALL, TOP_WALL)
176 snake.extend()
177 scoreboard.increase_score()
178 # Collision with wall
179 if not (LEFT_WALL < snake.head.xcor() < RIGHT_WALL and BOTTOM_WALL < snake.head.ycor() < TOP_WALL):
180 game_state = "game_over"
181 scoreboard.game_over()
182 # Collision with tail
183 for segment in snake.segments[1:]:
184 if snake.head.distance(segment) < 10:
185 game_state = "game_over"
186 scoreboard.game_over()
187 manage_buttons()
188 screen.update()
189 screen.ontimer(game_loop, MOVE_DELAY_MS)
190
191# --- INITIALIZE GAME ---
192scoreboard.display_start_message()

Callers 1

main.pyFile · 0.70

Calls 7

manage_buttonsFunction · 0.85
refreshMethod · 0.80
extendMethod · 0.80
increase_scoreMethod · 0.80
game_overMethod · 0.80
moveMethod · 0.45
updateMethod · 0.45

Tested by

no test coverage detected