Skip to content
Open
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
24 changes: 20 additions & 4 deletions sucury.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,12 @@
SCORE_COLOR = "#ffffff" # Color of the scoreboard.
MESSAGE_COLOR = "#808080" # Color of the game-over message.

WINDOW_TITLE = "KhobraPy" # Window title.
WINDOW_TITLE = "Sucury" # Window title.

CLOCK_TICKS = 7 # How fast the snake moves.

BORDERLESS_MODE = False

##
## Game implementation.
##
Expand All @@ -68,6 +70,7 @@
## This function is called when the snake dies.

def center_prompt(title, subtitle):
global BORDERLESS_MODE

# Show title and subtitle.

Expand All @@ -89,6 +92,8 @@ def center_prompt(title, subtitle):
if event.type == pygame.QUIT:
pygame.quit()
sys.exit()
if event.key == pygame.K_b: # 'B' Borderless switch
BORDERLESS_MODE = not BORDERLESS_MODE
if event.key == pygame.K_q: # 'Q' quits game
pygame.quit()
sys.exit()
Expand Down Expand Up @@ -123,11 +128,19 @@ def __init__(self):
# This function is called at each loop interation.

def update(self):
global apple
global apple, BORDERLESS_MODE

# Check for border crash.
if self.head.x not in range(0, WIDTH) or self.head.y not in range(0, HEIGHT):
self.alive = False
if not BORDERLESS_MODE:
if self.head.x not in range(0, WIDTH) or self.head.y not in range(0, HEIGHT):
self.alive = False
else:
if self.head.x not in range(0, WIDTH):
if(self.head.x < 0): self.head.x = WIDTH
else: self.head.x = -1
if self.head.y not in range(0, HEIGHT):
if(self.head.y < 0): self.head.y = HEIGHT
else: self.head.y = -1

# Check for self-bite.
for square in self.tail:
Expand Down Expand Up @@ -215,6 +228,9 @@ def draw_grid():

center_prompt("Welcome", "Press to start")




##
## Main loop
##
Expand Down