diff --git a/snake.py b/snake.py index 0842714..0d97e97 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=3,grid_width=30,grid_height=30, grid_pts=30,fps=10): + def __init__(self, margin=80,length=4,grid_width=30,grid_height=30, grid_pts=30,fps=5): # Init attributes self.grid_width=grid_width self.grid_height=grid_height @@ -32,11 +32,12 @@ class Snake: self.score=0 self.attempt+=1 - def draw_pts(self,x,y,color=(255,255,255)): + def draw_pts(self,x,y,color=(255,255,255),scale=1): """ Draw element on the snake area """ - rect=pygame.Rect(self.grid_pts*x, self.grid_pts*y+self.margin, self.grid_pts, self.grid_pts) + delta=int(self.grid_pts-int(self.grid_pts*scale)) + rect=pygame.Rect(self.grid_pts*x+delta, self.grid_pts*y+self.margin+delta, self.grid_pts-2*delta, self.grid_pts-2*delta) pygame.draw.rect(self.screen,color,rect, 0) def draw_infos(self,color=(255,255,255),thickness=10): @@ -89,6 +90,10 @@ class Snake: color=(0,150,150) if i==0 else (0,max(255-i*10,120),0) elt=self.snake[i] self.draw_pts(elt[0],elt[1],color=color) + if i>0: + self.draw_pts(elt[0],elt[1],color=(color[0],int(color[1]/2),color[2]),scale=max(0.7,1-i/4)) + else: + self.draw_pts(elt[0],elt[1],color=(color[0],int(color[1]/2),color[2]),scale=0.86) def has_loose(self): """