Commit 4556a53b by BellCodeEditor

save project

parent 13aadd36
Showing with 12 additions and 5 deletions
...@@ -16,6 +16,7 @@ body = pygame.image.load('body.png') # 身体 ...@@ -16,6 +16,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') # 头 朝下
myfont = pygame.font.Font('neuropol.ttf',20) #导入文本
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)]
...@@ -24,6 +25,7 @@ apple_x = 360#设置苹果x坐标 ...@@ -24,6 +25,7 @@ apple_x = 360#设置苹果x坐标
apple_y = 300#设置苹果y坐标 apple_y = 300#设置苹果y坐标
setheading = "right" setheading = "right"
snake_head = right snake_head = right
score = 0#设置分数变量
while True: while True:
for event in pygame.event.get(): for event in pygame.event.get():
...@@ -54,12 +56,13 @@ while True: ...@@ -54,12 +56,13 @@ while True:
else: else:
y += 30 y += 30
if x == apple_x and y ==apple_y:#如果吃到 if x == apple_x and y ==apple_y:#如果吃到
sum1 = random.randint(1,22)#随机生成新的坐标,在吃到后 sum1 = random.randint(1,22)#随机生成新格子,在吃到后
sum2 = random.randint(1,16) sum2 = random.randint(1,16)
apple_x = sum1*30-30 apple_x = sum1*30-30#函数,计算一下便可
apple_y = sum2*30-30 apple_y = sum2*30-30
score+=10#加分
else: else:
position.pop(0) position.pop(0)#实现变长
position.append((x, y)) position.append((x, y))
# 将背景图画上去 # 将背景图画上去
...@@ -72,6 +75,10 @@ while True: ...@@ -72,6 +75,10 @@ while True:
# 将果实画上去 # 将果实画上去
screen.blit(food, (apple_x, apple_y))#新的坐标 screen.blit(food, (apple_x, apple_y))#新的坐标
info = 'score:'+str(score)#说话内容变量
text=myfont.render(info,True,(119,110,255))#内容与颜色
screen.blit(text,(540,10))#位置
# 刷新画面 # 刷新画面
pygame.display.update() pygame.display.update()
FPSCLOCK.tick(10)#设置帧数,越高越快 FPSCLOCK.tick(8)#设置帧数,越高越快
\ 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