From 2fce5958a845167e784789be23ccae2dfc95b8f9 Mon Sep 17 00:00:00 2001 From: Gustavo Sampaio <95039361+GusSampaio@users.noreply.github.com> Date: Thu, 12 Oct 2023 19:01:48 -0300 Subject: [PATCH 1/4] Update AUTHORS --- AUTHORS | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/AUTHORS b/AUTHORS index 82a4b34..8e56861 100644 --- a/AUTHORS +++ b/AUTHORS @@ -12,9 +12,10 @@ from several developers (GitHub usernames): * Lucas Almeida (lalmeida32) + * Gustavo Sampaio (GusSampaio) - \ No newline at end of file + From e3f800189d364c6f8291bcbaee430a8d67f8d7b1 Mon Sep 17 00:00:00 2001 From: pedromonici Date: Fri, 13 Oct 2023 16:02:53 -0300 Subject: [PATCH 2/4] feat: add commands to change snake speed --- sucury.py | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/sucury.py b/sucury.py index 74a7d24..455543b 100755 --- a/sucury.py +++ b/sucury.py @@ -46,7 +46,11 @@ WINDOW_TITLE = "KhobraPy" # Window title. -CLOCK_TICKS = 7 # How fast the snake moves. +CLOCK_TICKS = 7 # How fast the snake moves. + +MIN_SPEED = 1 # Min Snake Speed +MAX_SPEED = 5 # Max Snake Speed +current_speed = MIN_SPEED ## ## Game implementation. @@ -148,6 +152,10 @@ def update(self): # Respan the initial tail self.tail = [] + # Reset the speed to the minimum value + global current_speed + current_speed = MIN_SPEED + # Initial direction self.xmov = 1 # Right self.ymov = 0 # Still @@ -247,6 +255,14 @@ def draw_grid(): sys.exit() elif event.key == pygame.K_p: # S : pause game game_on = not game_on + elif event.key == pygame.K_f: + if current_speed < MAX_SPEED: + current_speed += 1 + print(current_speed) + elif event.key == pygame.K_l: + if current_speed > MIN_SPEED: + current_speed -= 1 + print(current_speed) ## Update the game @@ -278,4 +294,4 @@ def draw_grid(): # Update display and move clock. pygame.display.update() - clock.tick(CLOCK_TICKS) + clock.tick(CLOCK_TICKS * current_speed) From dd5fdd87b89951ab9e4955cfe83c13b66ebd4812 Mon Sep 17 00:00:00 2001 From: pedromonici Date: Fri, 13 Oct 2023 16:02:53 -0300 Subject: [PATCH 3/4] feat: add commands to change snake speed --- sucury.py | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/sucury.py b/sucury.py index 74a7d24..455543b 100755 --- a/sucury.py +++ b/sucury.py @@ -46,7 +46,11 @@ WINDOW_TITLE = "KhobraPy" # Window title. -CLOCK_TICKS = 7 # How fast the snake moves. +CLOCK_TICKS = 7 # How fast the snake moves. + +MIN_SPEED = 1 # Min Snake Speed +MAX_SPEED = 5 # Max Snake Speed +current_speed = MIN_SPEED ## ## Game implementation. @@ -148,6 +152,10 @@ def update(self): # Respan the initial tail self.tail = [] + # Reset the speed to the minimum value + global current_speed + current_speed = MIN_SPEED + # Initial direction self.xmov = 1 # Right self.ymov = 0 # Still @@ -247,6 +255,14 @@ def draw_grid(): sys.exit() elif event.key == pygame.K_p: # S : pause game game_on = not game_on + elif event.key == pygame.K_f: + if current_speed < MAX_SPEED: + current_speed += 1 + print(current_speed) + elif event.key == pygame.K_l: + if current_speed > MIN_SPEED: + current_speed -= 1 + print(current_speed) ## Update the game @@ -278,4 +294,4 @@ def draw_grid(): # Update display and move clock. pygame.display.update() - clock.tick(CLOCK_TICKS) + clock.tick(CLOCK_TICKS * current_speed) From 708501a8b317064ba5ba2332861430dddfd3258e Mon Sep 17 00:00:00 2001 From: pedromonici Date: Mon, 23 Oct 2023 18:55:55 -0300 Subject: [PATCH 4/4] change the logic to change snake speed --- sucury.py | 39 ++++++++++++++++++--------------------- 1 file changed, 18 insertions(+), 21 deletions(-) diff --git a/sucury.py b/sucury.py index 455543b..e5b41ed 100755 --- a/sucury.py +++ b/sucury.py @@ -35,22 +35,23 @@ GRID_SIZE = 50 # Square grid size. -HEAD_COLOR = "#00aa00" # Color of the snake's head. -DEAD_HEAD_COLOR = "#4b0082" # Color of the dead snake's head. -TAIL_COLOR = "#00ff00" # Color of the snake's tail. -APPLE_COLOR = "#aa0000" # Color of the apple. -ARENA_COLOR = "#202020" # Color of the ground. -GRID_COLOR = "#3c3c3b" # Color of the grid lines. -SCORE_COLOR = "#ffffff" # Color of the scoreboard. -MESSAGE_COLOR = "#808080" # Color of the game-over message. +HEAD_COLOR = "#00aa00" # Color of the snake's head. +DEAD_HEAD_COLOR = "#4b0082" # Color of the dead snake's head. +TAIL_COLOR = "#00ff00" # Color of the snake's tail. +APPLE_COLOR = "#aa0000" # Color of the apple. +ARENA_COLOR = "#202020" # Color of the ground. +GRID_COLOR = "#3c3c3b" # Color of the grid lines. +SCORE_COLOR = "#ffffff" # Color of the scoreboard. +MESSAGE_COLOR = "#808080" # Color of the game-over message. -WINDOW_TITLE = "KhobraPy" # Window title. +WINDOW_TITLE = "KhobraPy" # Window title. -CLOCK_TICKS = 7 # How fast the snake moves. +CLOCK_TICKS = 7 # How fast the snake moves. -MIN_SPEED = 1 # Min Snake Speed -MAX_SPEED = 5 # Max Snake Speed -current_speed = MIN_SPEED +MIN_SPEED = 1 # Min Snake Speed +MAX_SPEED = 3 # Max Snake Speed +current_speed = MIN_SPEED +can_change_speed = False ## ## Game implementation. @@ -255,14 +256,8 @@ def draw_grid(): sys.exit() elif event.key == pygame.K_p: # S : pause game game_on = not game_on - elif event.key == pygame.K_f: - if current_speed < MAX_SPEED: - current_speed += 1 - print(current_speed) - elif event.key == pygame.K_l: - if current_speed > MIN_SPEED: - current_speed -= 1 - print(current_speed) + elif event.key == pygame.K_f: # F : disable/enable changing snake speed + can_change_speed = not can_change_speed ## Update the game @@ -289,6 +284,8 @@ 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.tail.append(pygame.Rect(snake.head.x, snake.head.x, GRID_SIZE, GRID_SIZE)) + if can_change_speed: + current_speed += 0.1 apple = Apple()