Commit 01ce6648 by BellCodeEditor

save project

parent 64d156a8
Showing with 13 additions and 3 deletions
...@@ -17,6 +17,9 @@ body = pygame.image.load('body.png') ...@@ -17,6 +17,9 @@ body = pygame.image.load('body.png')
up = pygame.image.load('up.png') up = pygame.image.load('up.png')
down = pygame.image.load('down.png') down = pygame.image.load('down.png')
left = pygame.image.load('left.png') left = pygame.image.load('left.png')
my_font=pygame.font.Font('neuropol.ttf',18)
score = 0
x,y = 240,120 x,y = 240,120
pos = [(180,90),(180,120,),(210, 120), (x, y)] pos = [(180,90),(180,120,),(210, 120), (x, y)]
...@@ -54,13 +57,16 @@ while True: ...@@ -54,13 +57,16 @@ while True:
screen.blit(background,(0,0)) screen.blit(background,(0,0))
pos.append((x,y)) pos.append((x,y))
if x==apple_x and y==apple_y: if x==apple_x and y==apple_y:
apple_x = 30*random.randint(0,630) apple_x = 30*random.randint(0,21)
apple_y = 30*random.randint(0,450) apple_y = 30*random.randint(0,15)
score=score+1
else: else:
pos.pop(0) pos.pop(0)
# 将贪吃蛇的头画上去 # 将贪吃蛇的头画上去
screen.blit(snake_head, pos[-1]) # screen.blit(snake_head, pos[-1])#
# 将贪吃蛇的身体画上去 # 将贪吃蛇的身体画上去
for i in range(len(pos)-1): for i in range(len(pos)-1):
...@@ -68,6 +74,9 @@ while True: ...@@ -68,6 +74,9 @@ while True:
# 将果实画上去 # 将果实画上去
screen.blit(food, (apple_x, apple_y)) screen.blit(food, (apple_x, apple_y))
info="Score:"+str(score)
text = my_font.render(info,True,(0,0,0))
screen.blit(text,(0,0))
# 刷新画面 # 刷新画面
pygame.display.update() pygame.display.update()
FPSCLOCK.tick(3) FPSCLOCK.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