Commit 7dc8ed42 by BellCodeEditor

save project

parent 8b74ab1c
Showing with 16 additions and 3 deletions
...@@ -18,9 +18,11 @@ left = pygame.image.load('left.png') # 头 朝左 ...@@ -18,9 +18,11 @@ 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') # 头 朝下
score=0 score=0
a=0
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)]
font=pygame.font.Font('neuropol.ttf',18) font=pygame.font.Font('neuropol.ttf',18)
font2=pygame.font.Font('neuropol.ttf',40)
setheading = "right" setheading = "right"
snake_head = right snake_head = right
apple_x=random.randint(1,22)*30-30 apple_x=random.randint(1,22)*30-30
...@@ -44,6 +46,8 @@ while True: ...@@ -44,6 +46,8 @@ while True:
setheading = 'down' setheading = 'down'
snake_head = down snake_head = down
# 设置贪吃蛇的头部坐标 # 设置贪吃蛇的头部坐标
if setheading == "right": if setheading == "right":
x += 30 x += 30
...@@ -66,12 +70,21 @@ while True: ...@@ -66,12 +70,21 @@ while True:
screen.blit(snake_head, position[-1]) screen.blit(snake_head, position[-1])
# 将贪吃蛇的身体画上去 # 将贪吃蛇的身体画上去
for i in range(len(position)-1): for i in range(len(position)-1):
if position[i]==position[-1]:
a=1
screen.blit(body, position[i]) screen.blit(body, position[i])
info='Score '+str(score) info='Score '+str(score)
text=font.render(info,True,(0,0,0)) text=font.render(info,True,(0,0,0))
screen.blit(text,(500,10)) screen.blit(text,(520,10))
# 将果实画上去 # 将果实画上去
screen.blit(food, (apple_x, apple_y)) screen.blit(food, (apple_x, apple_y))
if x<0 or x>630 or y<0 or y>450 or a==1:
text2=font2.render('GAME OVER',True,(0,0,0))
screen.blit(text2,(175,195))
pygame.display.update()
pygame.time.delay(2000)
exit()
# 刷新画面 # 刷新画面
pygame.display.update() pygame.display.update()
FPSCLOCK.tick(3) FPSCLOCK.tick(score*0.05+3)
\ No newline at end of file \ 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