Commit 99675e60 by BellCodeEditor

save project

parent d4ca9cca
Showing with 13 additions and 5 deletions
......@@ -15,7 +15,7 @@ FPSCLOCK = pygame.time.Clock() # pygame时钟,控制游戏速度(帧数)
background = pygame.image.load('bg.png')
right = pygame.image.load('ls1.png') # 头 朝右
food = pygame.image.load('ys.png') # 食物 苹果
body = pygame.image.load('body.png') # 身体
body = pygame.image.load('ls.png') # 身体
left = pygame.image.load('ls2.png') # 头 朝左
up = pygame.image.load('ls.png') # 头 朝上
down = pygame.image.load('ls3.png') # 头 朝下
......@@ -26,7 +26,7 @@ ys_x=360
ys_y=300
setheading = "right"
snake_head = right
score=0
score=20
while True:
for event in pygame.event.get():
......@@ -64,8 +64,16 @@ while True:
num_y=random.randint(1,16)
ys_x=30*num_x-30
ys_y=30*num_y-30
score += 20
else:
score-=1
position.pop(0)
if x<0 or x>630 or y<0 or y> 450:
exit()
if score==0:
exit()
# 将背景图画上去
screen.blit(background, (0, 0))
# 将贪吃蛇的头画上去
......@@ -78,8 +86,8 @@ while True:
screen.blit(food, (ys_x, ys_y))
info='Score:'+str(score)
text=my_font.render(info,True,(0,0,0))
screen.blit(text,(510,0))
screen.blit(text,(450,0))
# 刷新画面
pygame.display.update()
FPSCLOCK.tick(5)
\ No newline at end of file
FPSCLOCK.tick(15)
\ 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