Commit a4dc4a01 by BellCodeEditor

save project

parent 9185b2e7
Showing with 9 additions and 4 deletions
......@@ -5,6 +5,7 @@ x,y=240,120
pusition=[(180,90),(180,120),(210,120),(x,y)]
apple_x=360
apple_y=300
score=0
# 初始化pygame,为使用硬件做准备
pygame.init()
# 创建一个窗口
......@@ -18,6 +19,7 @@ body = pygame.image.load('body.png')
left = pygame.image.load('left.png')
up = pygame.image.load('up.png')
down = pygame.image.load('down.png')
my_font=pygame.font.Font('neuropol.ttf',18)
setheading = "right"
snake_head = right
while True:
......@@ -50,21 +52,24 @@ while True:
if x==apple_x and y==apple_y:
apple_x=randint(1,22)*30-30
apple_y=randint(1,16)*30-30
score= score+1
else:
pusition.pop(0)
# 将背景图画上去
screen.blit(background, (0, 0))
# 将背景图画上去
screen.blit(background, (0,0))
# 将贪吃蛇画上去
screen.blit(snake_head,pusition[-1])
# 将贪吃蛇的身体画上去
for i in range(len(pusition)-1):
screen.blit(body,pusition[i])
screen.blit(body,pusition[i])
info="Score"+" "+str(score)
text=my_font.render(info,True,(0,0,0))
#screen.blit(body, (210, 120))
#screen.blit(body, (180, 120))
#screen.blit(body, (180, 90))
# 将果实画上去
screen.blit(food, (apple_x, apple_y))
screen.blit(text,(500,5))
# 刷新画面
pygame.display.update()
FPSCLOCK.tick(3)
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