Commit 88c7190d by BellCodeEditor

save project

parent c65e70cd
Showing with 15 additions and 2 deletions
......@@ -8,6 +8,7 @@ pygame.init()
# 创建一个窗口
screen = pygame.display.set_mode((660, 480))
FPSCLOCK = pygame.time.Clock() # pygame时钟,控制游戏速度(帧数)
score=0
# 背景
background = pygame.image.load('bg.png')
......@@ -27,8 +28,14 @@ position = [(180, 90), (180, 120), (210, 120), (x, y)]
setheading = "right"
snake_head = right
my_font=pygame.font.Font("neuropol.ttf",18)
while True:
for event in pygame.event.get():
if event.type == locals.QUIT:
# 接收到退出事件后退出程序
......@@ -63,9 +70,11 @@ while True:
num2=random.randint(1,16)
apple_x=num1*30-30
apple_y=num2*30-30
score+=1
else:
position.pop(0)
if x>630 or x<0 or y>450 or y<0:
exit()
screen.blit(background, (0, 0))
# 将贪吃蛇的头画上去
......@@ -76,6 +85,9 @@ while True:
# 将果实画上去
screen.blit(food, (apple_x,apple_y))
info="score:"+str(score)
text=my_font.render(info,True,(0,0,0))
screen.blit(text,(540,10))
# 刷新画面
pygame.display.update()
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