summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xsnake/snake.py12
1 files changed, 9 insertions, 3 deletions
diff --git a/snake/snake.py b/snake/snake.py
index e28ef61..0248204 100755
--- a/snake/snake.py
+++ b/snake/snake.py
@@ -4,19 +4,24 @@ import sys, pygame, random
class Snake:
- def __init__(self, length=10,grid_width=50,grid_height=50, grid_pts=15,fps=10):
+ def __init__(self, margin=80,length=10,grid_width=50,grid_height=50, grid_pts=15,fps=10):
self.grid_width=grid_width
self.grid_height=grid_height
self.grid_pts=grid_pts
+ self.margin=margin
self.fps=fps
self.snake=[(0,0)]*length
self.direction=3 # Like clock (12=up, 3=right, 6=bottom, 9=left)
self.new_apple()
pygame.init()
- self.screen=pygame.display.set_mode((grid_width*grid_pts,grid_height*grid_pts))
+ self.screen=pygame.display.set_mode((grid_width*grid_pts,grid_height*grid_pts+margin))
def draw_pts(self,x,y,color=(255,255,255)):
- rect=pygame.Rect(self.grid_pts*x, self.grid_pts*y, self.grid_pts, self.grid_pts)
+ rect=pygame.Rect(self.grid_pts*x, self.grid_pts*y+self.margin, self.grid_pts, self.grid_pts)
+ pygame.draw.rect(self.screen,color,rect, 0)
+
+ def draw_infos(self,color=(255,255,255),thickness=5):
+ rect=pygame.Rect(0, self.margin-thickness, self.grid_width*self.grid_pts, thickness)
pygame.draw.rect(self.screen,color,rect, 0)
@@ -64,6 +69,7 @@ class Snake:
self.screen.fill((0,0,0))
self.draw_snake()
self.draw_pts(self.apple[0],self.apple[1],color=(255,0,0))
+ self.draw_infos()
# Check for loose
if not(ignore_has_loose) and self.has_loose():
break