Commit 4fdc0b7c by BellCodeEditor

save project

parent 29d487d6
Showing with 7 additions and 1 deletions
...@@ -3,6 +3,7 @@ from pygame import locals ...@@ -3,6 +3,7 @@ from pygame import locals
import random as r import random as r
# 初始化pygame,为使用硬件做准备 # 初始化pygame,为使用硬件做准备
pygame.init() pygame.init()
score=0
# 创建一个窗口 # 创建一个窗口
screen = pygame.display.set_mode((660, 480)) screen = pygame.display.set_mode((660, 480))
...@@ -16,7 +17,7 @@ body = pygame.image.load('body.png') # 身体 ...@@ -16,7 +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
position = [(180, 90), (180, 120), (210, 120), (x, y)] position = [(180, 90), (180, 120), (210, 120), (x, y)]
apple_x=360 apple_x=360
...@@ -58,6 +59,7 @@ while True: ...@@ -58,6 +59,7 @@ while True:
num2=r.randint(1,16) num2=r.randint(1,16)
apple_x=30*num1-30 apple_x=30*num1-30
apple_y=30*num2-30 apple_y=30*num2-30
score+=1
else: else:
position.pop(0) position.pop(0)
# 将背景图画上去 # 将背景图画上去
...@@ -69,6 +71,9 @@ while True: ...@@ -69,6 +71,9 @@ while True:
screen.blit(body, position[i]) screen.blit(body, position[i])
# 将果实画上去 # 将果实画上去
screen.blit(food, (apple_x, apple_y)) screen.blit(food, (apple_x, apple_y))
info="score"+ser(score)
text=my_font.render(info,True,(0,0,0))
screen.blit(text,(540,10))
# 刷新画面 # 刷新画面
pygame.display.update() pygame.display.update()
FPSCLOCK.tick(3) FPSCLOCK.tick(3)
\ 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