summaryrefslogtreecommitdiff
path: root/snake.py
diff options
context:
space:
mode:
authorLoic Guegan <manzerbredes@mailbox.org>2022-11-01 22:12:14 +0100
committerLoic Guegan <manzerbredes@mailbox.org>2022-11-01 22:12:14 +0100
commita1469f368b01828342f70e906d436b5849a1d737 (patch)
tree8a9f47a5458e96803fcd7ed8d8312dcdd3f1b5a4 /snake.py
parent3b35b6866d4abbc4eb446ab8a4a06c305305325b (diff)
Minor changes
Diffstat (limited to 'snake.py')
-rwxr-xr-xsnake.py9
1 files changed, 6 insertions, 3 deletions
diff --git a/snake.py b/snake.py
index cfaa9b8..a517146 100755
--- a/snake.py
+++ b/snake.py
@@ -7,7 +7,7 @@ class Snake:
Programmable Game of Snake written in PyGame
"""
- def __init__(self, margin=80,length=4,grid_width=30,grid_height=30, grid_pts=30,fps=80):
+ def __init__(self, startat=(0,0), margin=80,length=4,grid_width=30,grid_height=30, grid_pts=30,fps=80):
# Init attributes
self.grid_width=grid_width
self.grid_height=grid_height
@@ -16,6 +16,7 @@ class Snake:
self.default_length=length
self.attempt=0
self.fps=fps
+ self.startat=startat
# Setup pygame
pygame.init()
self.font=pygame.font.SysFont(pygame.font.get_default_font(), int(self.margin/2))
@@ -26,7 +27,7 @@ class Snake:
"""
Reset game state
"""
- self.snake=[(0,0)]*self.default_length
+ self.snake=[self.startat]*self.default_length
self.direction=3 # Like clock (12=up, 3=right, 6=bottom, 9=left)
self.new_apple()
self.score=0
@@ -156,7 +157,9 @@ class Snake:
break
# Check if an event handler is available
if event_handler!=None:
- event_handler(self,last_event)
+ code=event_handler(self,last_event)
+ if code < 0:
+ break
last_event=0
self.move()
# Check for eating apple