Commit 34fc5379 by BellCodeEditor

save project

parent a62301ee
Showing with 19 additions and 7 deletions
...@@ -4,7 +4,7 @@ from pygame import locals ...@@ -4,7 +4,7 @@ from pygame import locals
# 初始化pygame,为使用硬件做准备 # 初始化pygame,为使用硬件做准备
pygame.init() pygame.init()
sss=0
# 创建一个窗口 # 创建一个窗口
screen = pygame.display.set_mode((660, 480)) screen = pygame.display.set_mode((660, 480))
FPSCLOCK = pygame.time.Clock() # pygame时钟,控制游戏速度(帧数) FPSCLOCK = pygame.time.Clock() # pygame时钟,控制游戏速度(帧数)
...@@ -17,12 +17,13 @@ body = pygame.image.load('body.png') # 身体 ...@@ -17,12 +17,13 @@ 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') # 头 朝下
ttf=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
apple_y=300 apple_y=300
xx=660
yy=480
...@@ -58,11 +59,15 @@ while True: ...@@ -58,11 +59,15 @@ while True:
else: else:
y += 30 y += 30
position.append((x, y)) position.append((x, y))
position.pop(0)
if apple_x==x and apple_y==y: if apple_x==x and apple_y==y:
food=random.?(660,480) num1=random.randint(1,22)
num2=random.randint(1,16)
apple_x=30*num1-30
apple_y=30*num2-30
sss+=10
else :
position.pop(0)
...@@ -76,6 +81,12 @@ while True: ...@@ -76,6 +81,12 @@ while True:
# 将果实画上去 # 将果实画上去
screen.blit(food, (apple_x, apple_y)) screen.blit(food, (apple_x, apple_y))
nnn='score'+str(sss)
list1=ttf.render(nnn,True,(0,0,0))
screen.blit(list1,(540,0))
# 刷新画面 # 刷新画面
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