Commit fd807f70 by BellCodeEditor

auto save

parent 48db45fc
Showing with 12 additions and 4 deletions
...@@ -10,6 +10,7 @@ screen = pygame.display.set_mode((660, 480)) ...@@ -10,6 +10,7 @@ screen = pygame.display.set_mode((660, 480))
FPSCLOCK = pygame.time.Clock() # pygame时钟,控制游戏速度(帧数) FPSCLOCK = pygame.time.Clock() # pygame时钟,控制游戏速度(帧数)
apple_x=360 apple_x=360
apple_y=300 apple_y=300
score=0
# 背景 # 背景
background = pygame.image.load('bg.png') background = pygame.image.load('bg.png')
...@@ -18,7 +19,8 @@ food = pygame.image.load('apple.png') # 食物 苹果 ...@@ -18,7 +19,8 @@ food = pygame.image.load('apple.png') # 食物 苹果
body = pygame.image.load('body.png') # 身体 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)]
...@@ -44,7 +46,8 @@ while True: ...@@ -44,7 +46,8 @@ while True:
if event.key == locals.K_DOWN and setheading != "up": if event.key == locals.K_DOWN and setheading != "up":
setheading = 'down' setheading = 'down'
snake_head = down snake_head = down
if x<0 or x>630 or y<0 or y>450:
exit()
# 设置贪吃蛇的头部坐标 # 设置贪吃蛇的头部坐标
if setheading == "right": if setheading == "right":
x += 30 x += 30
...@@ -56,8 +59,9 @@ while True: ...@@ -56,8 +59,9 @@ while True:
y += 30 y += 30
position.append((x, y)) position.append((x, y))
if apple_x==x and apple_y==y: if apple_x==x and apple_y==y:
apple_x=random.randint(1,22)*30-30 apple_x=random.randint(1,21)*30-30
apple_y=random.randint(1,16)*30-30 apple_y=random.randint(1,15)*30-30
score+=random.randint(1,20)
else: else:
position.pop(0) position.pop(0)
...@@ -72,6 +76,9 @@ while True: ...@@ -72,6 +76,9 @@ while True:
# 将果实画上去 # 将果实画上去
screen.blit(food, (apple_x, apple_y)) screen.blit(food, (apple_x, apple_y))
info="SCORE:"+str(score)
text=my_font.render(info,True,(255,0,0))
screen.blit(text,(480,10))
# 刷新画面 # 刷新画面
pygame.display.update() pygame.display.update()
FPSCLOCK.tick(8) FPSCLOCK.tick(8)
\ 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