Commit 274e8de4 by BellCodeEditor

save project

parent 40a18420
Showing with 7 additions and 10 deletions
......@@ -4,7 +4,7 @@ import random
# 初始化pygame,为使用硬件做准备
pygame.init()
score=0
pygame.font.Font("neuropol.ttf",15)
# 创建一个窗口
screen = pygame.display.set_mode((660, 480))
FPSCLOCK = pygame.time.Clock() # pygame时钟,控制游戏速度(帧数)
......@@ -17,7 +17,6 @@ body = pygame.image.load('body.png') # 身体
left = pygame.image.load('left.png') # 头 朝左
up = pygame.image.load('up.png') # 头 朝上
down = pygame.image.load('down.png') # 头 朝下
ziti=pygame.font.Font("neuropol.ttf",18)
x, y = 240, 120
position = [(180, 90), (180, 120), (210, 120), (x, y)]
......@@ -58,9 +57,8 @@ while True:
position.append((x, y))
if x==apple_x and y==apple_y:
apple_x=random.randint(1,21)*30
apple_y=random.randint(1,15)*30
score+=10
apple_x=random.randint(1,22)*30
apple_y=random.randint(1,16)*30
else:
position.pop(0)
# 将背景图画上去
......@@ -70,12 +68,11 @@ while True:
# 将贪吃蛇的身体画上去
for i in range(len(position)-1):
screen.blit(body, position[i])
info="Score:"+str(score)
text=ziti.render(info,True,(0,0,0))
screen.blit(text,(540,10))
# 将果实画上去
screen.blit(food, (apple_x, apple_y))
# 刷新画面
pygame.display.update()
FPSCLOCK.tick(3)
\ No newline at end of file
if x<0 or x>630 or y<0 or y>450:
exit()
\ 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