SPACE_K - pause functionality

This commit is contained in:
Vadzim Valchkovich 2023-06-07 13:01:04 +02:00
parent 5842270806
commit eb765050c5
2 changed files with 16 additions and 1 deletions

View File

@ -38,6 +38,7 @@ class Engine:
self.goals: list = []
self.runnin: bool = False
self.paused: bool = False
def __init_squares_field__(self, num_squares, square_size):
squares = []
@ -66,12 +67,14 @@ class Engine:
self.running = False
def action(self):
self.user.handler(self)
if self.paused:
return
if not self.state.path:
if self.goals:
if not self.state.graphsearch(self) and self.goals:
self.objects.remove(self.goals.pop().parent)
self.user.handler(self)
self.predict()
else:
# went path
@ -109,6 +112,9 @@ class Engine:
self.action_clock += action_time
def redraw(self):
if self.paused:
return
self.screen.fill((255, 255, 255))
for row in self.squares:

View File

@ -1,4 +1,6 @@
import time
import pygame
from termcolor import colored
class UserController:
@ -9,3 +11,10 @@ class UserController:
for event in pygame.event.get():
if event.type == pygame.QUIT:
engine.quit()
elif event.type == pygame.KEYDOWN:
if event.key == pygame.K_SPACE:
engine.paused = not engine.paused
if engine.paused:
print(colored("Paused", "red"))
else:
print(colored("Continued", "green"))