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') # 身体 ...@@ -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') # 头 朝下
my_font = pygame.font.Font('neuropol.ttf', 18)
x, y = 240, 120 x, y = 240, 120
p = [(180, 90), (180, 120), (210, 120), (x, y)] p = [(180, 90), (180, 120), (210, 120), (x, y)]
...@@ -24,7 +25,7 @@ ax=360 ...@@ -24,7 +25,7 @@ ax=360
ay=300 ay=300
sd = "right" sd = "right"
sh = right sh = right
fsh=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:
...@@ -45,30 +46,28 @@ while True: ...@@ -45,30 +46,28 @@ while True:
sh = down sh = down
# 设置贪吃蛇的头部坐标 # 设置贪吃蛇的头部坐标
if sd == "right": if sd=="right":
x += 30 x+=30
elif sd == "left": elif sd=="left":
x -= 30 x-=30
elif sd == "up": elif sd=="up":
y -= 30 y-=30
else: else:
y += 30 y+=30
p.append((x, y)) p.append((x, y))
if x==ax and y==ay: if x==ax and y==ay:
ax=random.randint(1,22)*30-30 ax=random.randint(1,22)*30-30
ay=random.randint(1,16)*30-30 ay=random.randint(1,16)*30-30
fsh+=1
else: else:
p.pop(0) p.pop(0)
# 将背景图画上去
screen.blit(background, (0, 0)) screen.blit(background, (0, 0))
# 将贪吃蛇的头画上去
screen.blit(sh, p[-1]) screen.blit(sh, p[-1])
# 将贪吃蛇的身体画上去
for i in range(len(p)-1): for i in range(len(p)-1):
screen.blit(body, p[i]) 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)) screen.blit(food, (ax, ay))
# 刷新画面
pygame.display.update() pygame.display.update()
FPSCLOCK.tick(6) 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