Skip to content
  • P
    Projects
  • G
    Groups
  • S
    Snippets
  • Help

Administrator / pygame_lesson3_diy1

  • This project
    • Loading...
  • Sign in
Go to a project
  • Project
  • Repository
  • Issues 0
  • Merge Requests 0
  • Pipelines
  • Wiki
  • Snippets
  • Members
  • Activity
  • Graph
  • Charts
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
  • Files
  • Commits
  • Branches
  • Tags
  • Contributors
  • Graph
  • Compare
  • Charts
Commit 456b7629 authored 3 years ago by BellCodeEditor's avatar BellCodeEditor
Browse files
Options
  • Browse Files
  • Download
  • Email Patches
  • Plain Diff

save project

parent b280b707
Hide whitespace changes
Inline Side-by-side
Showing with 8 additions and 0 deletions
  • snake.py
snake.py
View file @ 456b7629
...@@ -10,6 +10,8 @@ screen = pygame.display.set_mode((660, 480)) ...@@ -10,6 +10,8 @@ screen = pygame.display.set_mode((660, 480))
FPSCLOCK = pygame.time.Clock() # pygame时钟,控制游戏速度(帧数) FPSCLOCK = pygame.time.Clock() # pygame时钟,控制游戏速度(帧数)
# 背景 # 背景
score=0
my_font=pygame.font.Font("neuropol.ttf",18)
background = pygame.image.load('bg.png') background = pygame.image.load('bg.png')
right = pygame.image.load('right.png') # 头 朝右 right = pygame.image.load('right.png') # 头 朝右
food = pygame.image.load('apple.png') # 食物 苹果 food = pygame.image.load('apple.png') # 食物 苹果
...@@ -44,6 +46,7 @@ while True: ...@@ -44,6 +46,7 @@ while True:
setheading = 'down' setheading = 'down'
snake_head = down snake_head = down
# 设置贪吃蛇的头部坐标 # 设置贪吃蛇的头部坐标
if setheading == "right": if setheading == "right":
x += 30 x += 30
...@@ -59,6 +62,7 @@ while True: ...@@ -59,6 +62,7 @@ while True:
b=random.randint(1,16) b=random.randint(1,16)
apple_x=a*30-30 apple_x=a*30-30
apple_y=b*30-30 apple_y=b*30-30
score+=1
else: else:
position.pop(0) position.pop(0)
# 将背景图画上去 # 将背景图画上去
...@@ -71,6 +75,9 @@ while True: ...@@ -71,6 +75,9 @@ while True:
# 将果实画上去 # 将果实画上去
screen.blit(food, (apple_x,apple_y)) screen.blit(food, (apple_x,apple_y))
into="score"+str(score)
text=my_font.render(into,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
This diff is collapsed. Click to expand it.
  • Write
  • Preview
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