Commit 58cea1e9 by BellCodeEditor

save project

parent 347c30a9
Showing with 8 additions and 1 deletions
...@@ -13,6 +13,8 @@ up = pygame.image.load("up.png") ...@@ -13,6 +13,8 @@ up = pygame.image.load("up.png")
down = pygame.image.load("down.png") down = pygame.image.load("down.png")
food = pygame.image.load("apple.png") food = pygame.image.load("apple.png")
body = pygame.image.load("body.png") body = pygame.image.load("body.png")
my_font = pygame.font.Font("neuropol.ttf",20)
score = 0
FPS = pygame.time.Clock() FPS = pygame.time.Clock()
x,y = 240,120 x,y = 240,120
position = [(180,90),(180,120),(210,120),(x,y)] position = [(180,90),(180,120),(210,120),(x,y)]
...@@ -55,15 +57,19 @@ while True: ...@@ -55,15 +57,19 @@ while True:
screen.blit(snake_heading,position[-1]) screen.blit(snake_heading,position[-1])
for i in range(len(position)-1): for i in range(len(position)-1):
screen.blit(body,position[i]) screen.blit(body,position[i])
info = "score:" + str(score)
text = my_font.render(info,True,(0,0,0))
screen.blit(text,(540,10))
if x == a_x and y == a_y: if x == a_x and y == a_y:
a_x = randint(0,21)*30 a_x = randint(0,21)*30
a_y = randint(0,15)*30 a_y = randint(0,15)*30
position.insert(0,last) position.insert(0,last)
screen.blit(body,last) screen.blit(body,last)
score += 1
screen.blit(food,(a_x,a_y)) screen.blit(food,(a_x,a_y))
for i in range(len(position)-1): for i in range(len(position)-1):
if (x,y) == position[i]: if (x,y) == position[i]:
exit() exit()
pygame.display.update() pygame.display.update()
FPS.tick(3) FPS.tick(3)
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment