Commit 8afba0b5 by BellCodeEditor

save project

parent ae71d568
Showing with 9 additions and 1 deletions
...@@ -17,6 +17,7 @@ body = pygame.image.load('body.png') # 身体 ...@@ -17,6 +17,7 @@ body = pygame.image.load('body.png') # 身体
left = pygame.image.load('left.png') # 头 朝左 left = pygame.image.load('left.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') # 头 朝下
text = pygame.font.Font("neuropol.ttf",20)
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)]
...@@ -24,7 +25,7 @@ apple_X=360 ...@@ -24,7 +25,7 @@ apple_X=360
apple_Y=240 apple_Y=240
snake_head = right snake_head = right
Score=0
while True: while True:
for event in pygame.event.get(): for event in pygame.event.get():
if event.type == locals.QUIT: if event.type == locals.QUIT:
...@@ -53,10 +54,13 @@ while True: ...@@ -53,10 +54,13 @@ while True:
if x==apple_X and y==apple_Y: if x==apple_X and y==apple_Y:
apple_X=30*randint(0,21) apple_X=30*randint(0,21)
apple_Y=30*randint(0,14) apple_Y=30*randint(0,14)
Score+=10
else: else:
position.pop(0) position.pop(0)
out_score="Score:"+str(Score)
# 将背景图画上去 # 将背景图画上去
screen.blit(background, (0, 0)) screen.blit(background, (0, 0))
# 将果实画上去 # 将果实画上去
screen.blit(food, (apple_X,apple_Y)) screen.blit(food, (apple_X,apple_Y))
# 将贪吃蛇的头画上去 # 将贪吃蛇的头画上去
...@@ -64,6 +68,9 @@ while True: ...@@ -64,6 +68,9 @@ while True:
# 将贪吃蛇的身体画上去 # 将贪吃蛇的身体画上去
for i in range(len(position)-1): for i in range(len(position)-1):
screen.blit(body, position[i]) screen.blit(body, position[i])
score_txt=text.render(out_score,True,(0,0,0))
screen.blit(score_txt,(515,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