diff options
Diffstat (limited to 'snake.py')
| -rwxr-xr-x | snake.py | 9 |
1 files changed, 6 insertions, 3 deletions
@@ -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 |
