Skip to content

Commit

Permalink
new files
Browse files Browse the repository at this point in the history
  • Loading branch information
Notdutra committed Aug 27, 2024
1 parent dba5cfa commit aecc386
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 13 deletions.
8 changes: 8 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/Snake.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/inspectionProfiles/profiles_settings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

35 changes: 22 additions & 13 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@
import pygame
import random




async def game_loop():
global direction, change_to, score, snake_speed, fruit_spawn, fruit_position

Expand Down Expand Up @@ -61,23 +58,35 @@ def show_score(choice, color, font, size):
score_rect = score_surface.get_rect()
game_window.blit(score_surface, score_rect)

# Game over function
def game_over():
# game over function
async def game_over():
# creating font object my_font
my_font = pygame.font.SysFont('times new roman', 50)
game_over_surface = my_font.render('Your Score is : ' + str(score), True, red)

# creating a text surface on which text
# will be drawn
game_over_surface = my_font.render('Your Score is : ' + str(score) + " | Press SPACE to play again", True, red)

# create a rectangular object for the text surface object
game_over_rect = game_over_surface.get_rect()

# setting position of the text
game_over_rect.midtop = (window_x / 2, window_y / 4)

# blit will draw the text on screen
game_window.blit(game_over_surface, game_over_rect)
pygame.display.flip()

# This should be awaited when called from an async function
async def wait_then_quit():
await asyncio.sleep(2) # Asynchronous sleep
pygame.quit()
quit()
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
quit()
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_SPACE:
return # Exit the loop to restart the game

# Schedule the wait_then_quit task
asyncio.create_task(wait_then_quit())
await asyncio.sleep(0)

while True:
for event in pygame.event.get():
Expand Down

0 comments on commit aecc386

Please sign in to comment.