Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion sucury.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@
DOWN = (0, 1)
LEFT = (-1, 0)


progress = 0 # Tracking the player progress along their playthrough

##
## Game implementation.
##
Expand Down Expand Up @@ -101,6 +104,16 @@ def center_prompt(title, subtitle):
pygame.quit()
sys.exit()


def show_progress(snake_length):
global progress
if snake_length > progress:
progress = snake_length

leaderboard = SMALL_FONT.render(f"Best Score: {progress}", True, SCORE_COLOR)
leaderboard_rect = leaderboard.get_rect(center=(WIDTH/2, (3*HEIGHT/20)+HEIGHT/30))
arena.blit(leaderboard, leaderboard_rect)

###
### Display the main menu.
###
Expand Down Expand Up @@ -203,6 +216,7 @@ def update(self):

# Tell the bad news
pygame.draw.rect(arena, DEAD_HEAD_COLOR, snake.head)
show_progress(len(self.tail))
center_prompt("Game Over", "Press to restart")

# Respan the head
Expand Down Expand Up @@ -358,7 +372,7 @@ def draw_grid():
# If the head pass over an apple, lengthen the snake and drop another apple
if snake.head.x == apple.x and snake.head.y == apple.y:
snake.grow()
apple = Apple()
apple = Apple()


# Update display and move clock.
Expand Down