Skip to content
Open
Show file tree
Hide file tree
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
3 changes: 2 additions & 1 deletion AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@
from several developers (GitHub usernames):

* Lucas Almeida (lalmeida32)
* Gustavo Sampaio (GusSampaio)







35 changes: 24 additions & 11 deletions sucury.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +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 = 3 # Max Snake Speed
current_speed = MIN_SPEED
can_change_speed = False

##
## Game implementation.
Expand Down Expand Up @@ -148,6 +153,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
Expand Down Expand Up @@ -247,6 +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: # F : disable/enable changing snake speed
can_change_speed = not can_change_speed

## Update the game

Expand All @@ -273,9 +284,11 @@ 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()


# Update display and move clock.
pygame.display.update()
clock.tick(CLOCK_TICKS)
clock.tick(CLOCK_TICKS * current_speed)