fix global variables

This commit is contained in:
Kristofers Solo 2022-04-23 13:38:12 +03:00
parent 35c8a9a8aa
commit fc80ab7ec5
3 changed files with 12 additions and 2 deletions

View File

@ -90,9 +90,9 @@ class Snake:
if index == len(self.body) - 1:
self.turns.pop(head_pos)
else:
from assets.scripts.menu import walls
from globals import walls
from snake import end_screen
if walls: # end game if goes into the wall
from snake import end_screen
head.move(head.direction)
if head.direction[0] == -1 and head.pos[0] < 0: # left to right
end_screen()

View File

@ -73,6 +73,9 @@ def options() -> None:
for event in pygame.event.get():
if event.type == pygame.QUIT:
quit()
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_ESCAPE:
main_menu()
if event.type == pygame.MOUSEBUTTONDOWN and event.button == 1:
if speed_button.check_input(mouse_pos):
change_speed()
@ -101,6 +104,9 @@ def scoreboard() -> None:
for event in pygame.event.get():
if event.type == pygame.QUIT:
quit()
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_ESCAPE:
main_menu()
if event.type == pygame.MOUSEBUTTONDOWN and event.button == 1:
if back_button.check_input(mouse_pos):
main_menu()

View File

@ -47,6 +47,7 @@ def end_screen() -> None:
def main() -> None:
snakes.clear()
from globals import fps, multiplayer, walls
pygame.display.set_caption("Snake")
@ -83,6 +84,9 @@ def main() -> None:
for event in pygame.event.get():
if event.type == pygame.QUIT:
quit()
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_ESCAPE:
end_screen()
for snake in snakes:
snake.move()