Commit 28fe25dc by BellCodeEditor

save project

parent bfd27ca3
Showing with 14 additions and 18 deletions
import pygame
import time
from random import randint
from pygame import locals
......@@ -20,7 +19,6 @@ left = pygame.image.load('left.png') # 头 朝左
up = pygame.image.load('up.png') # 头 朝上
down = pygame.image.load('down.png') # 头 朝下
txt=pygame.font.Font("neuropol.ttf",20)
over=pygame.font.Font("neuropol.ttf",75)
x, y = 240, 120
position = [(180, 90), (180, 120), (210, 120), (x, y)]
......@@ -49,35 +47,33 @@ while True:
snake_head = down
# 设置贪吃蛇的头部坐标
if setheading == "right":
x += 30
elif setheading == "left":
x -= 30
elif setheading == "up":
y -= 30
else:
y += 30
position.append((x, y))
if position[-1] == (fx,fy):
fx=randint(0,20)*30
fy=randint(0,15)*30
score+=1
else:
position.pop(0)
# 将背景图画上去
text=txt.render("SCORE:"+str(score),True,(0,0,0))
if 0>x or x>630 or 0>y or y>450:
exit()
screen.blit(background, (0, 0))
# 将贪吃蛇的头画上去
screen.blit(snake_head, position[-1])
if 0>x or 630<x or 0>y or y>450:
a=over.render("GAME OVER",True,(0,0,0))
screen.blit(a, (0, 75))
else:
if setheading == "right":
x += 30
elif setheading == "left":
x -= 30
elif setheading == "up":
y -= 30
else:
y += 30
# 将贪吃蛇的身体画上去
for i in range(len(position)-1):
screen.blit(body, position[i])
# 将果实画上去1
screen.blit(food, (fx, fy))
screen.blit(text,(10,10))
......
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