Minor changes

This commit is contained in:
Loic Guegan 2022-11-01 13:44:10 +01:00
parent c61f050feb
commit f5974e8699

View file

@ -26,7 +26,7 @@ class Snake:
""" """
Reset game state Reset game state
""" """
self.snake=[(0,0)]*self.default_length self.snake=[(5,5)]*self.default_length
self.direction=3 # Like clock (12=up, 3=right, 6=bottom, 9=left) self.direction=3 # Like clock (12=up, 3=right, 6=bottom, 9=left)
self.new_apple() self.new_apple()
self.score=0 self.score=0
@ -95,6 +95,14 @@ class Snake:
else: else:
self.draw_pts(elt[0],elt[1],color=(color[0],int(color[1]/2),color[2]),scale=0.86) self.draw_pts(elt[0],elt[1],color=(color[0],int(color[1]/2),color[2]),scale=0.86)
def draw_apple(self,radius=None):
if radius==None:
radius=self.grid_pts/2
#self.draw_pts(self.apple[0],self.apple[1],color=(210,0,0))
pygame.draw.circle(self.screen, (210,0,0), (self.apple[0]*self.grid_pts+int(self.grid_pts/2),self.apple[1]*self.grid_pts+self.margin+int(self.grid_pts/2)), radius)
pygame.draw.circle(self.screen, (170,0,0), (self.apple[0]*self.grid_pts+int(self.grid_pts/2),self.apple[1]*self.grid_pts+self.margin+int(self.grid_pts/2)), radius/1.5)
def has_loose(self): def has_loose(self):
""" """
Return true if the game is loose Return true if the game is loose
@ -117,7 +125,7 @@ class Snake:
while True: while True:
self.screen.fill((0,0,0)) self.screen.fill((0,0,0))
self.draw_snake() self.draw_snake()
self.draw_pts(self.apple[0],self.apple[1],color=(210,0,0)) self.draw_apple()
self.draw_infos() self.draw_infos()
# Check for loose # Check for loose
if not(ignore_has_loose) and self.has_loose(): if not(ignore_has_loose) and self.has_loose():