Commit 7fa0c593 by BellCodeEditor

save project

parent 51709d8e
Showing with 13 additions and 15 deletions
......@@ -17,6 +17,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)
x, y = 240, 120
p = [(180, 90), (180, 120), (210, 120), (x, y)]
......@@ -24,7 +25,7 @@ ax=360
ay=300
sd = "right"
sh = right
fsh=0
while True:
for event in pygame.event.get():
if event.type == locals.QUIT:
......@@ -45,30 +46,28 @@ while True:
sh = down
# 设置贪吃蛇的头部坐标
if sd == "right":
x += 30
elif sd == "left":
x -= 30
elif sd == "up":
y -= 30
if sd=="right":
x+=30
elif sd=="left":
x-=30
elif sd=="up":
y-=30
else:
y += 30
y+=30
p.append((x, y))
if x==ax and y==ay:
ax=random.randint(1,22)*30-30
ay=random.randint(1,16)*30-30
fsh+=1
else:
p.pop(0)
# 将背景图画上去
screen.blit(background, (0, 0))
# 将贪吃蛇的头画上去
screen.blit(sh, p[-1])
# 将贪吃蛇的身体画上去
for i in range(len(p)-1):
screen.blit(body, p[i])
# 将果实画上去
io='score:'+str(fsh)
text = my_font.render(io, True, (0, 0, 0))
screen.blit(text, (10, 10))
screen.blit(food, (ax, ay))
# 刷新画面
pygame.display.update()
FPSCLOCK.tick(6)
\ 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