Commit b57da0b6 by BellCodeEditor

auto save

parent 90221fc3
Showing with 28 additions and 6 deletions
......@@ -9,7 +9,7 @@ pygame.init()
screen = pygame.display.set_mode((660, 480))
FPSCLOCK = pygame.time.Clock() # pygame时钟,控制游戏速度(帧数)
ticks=5
# 背景
background = pygame.image.load('bg.png')
right = pygame.image.load('right.png') # 头 朝右
......@@ -18,12 +18,16 @@ body = pygame.image.load('body.png') # 身体
left = pygame.image.load('left.png') # 头 朝左
up = pygame.image.load('up.png') # 头 朝上
down = pygame.image.load('down.png') # 头 朝下
roadblock =pygame.image.load("路障2.png")
font = pygame.font.Font("neuropol.ttf",18)
score=0
x, y = 240, 120
position = [(x, y)]
apple_x=360
apple_y=300
roadblock_x=300
roadblock_y=240
roadblock_position=[(roadblock_x,roadblock_y)]
setheading = "right"
snake_head = right
......@@ -60,34 +64,52 @@ while True:
if x>630 or y>450 or x<0 or y<0:
exit()
for i in roadblock_position:
if i==(x,y):
exit()
if x==apple_x and y==apple_y:
num1=random.randint(1,22)
num2=random.randint(1,16)
apple_x=num1*30-30
apple_y=num2*30-30
score+=1
if len(roadblock_position) <10:
num3=random.randint(1,22)
num4=random.randint(1,16)
if num3==num1 and num2==num4 or num3==x and num4==y:
num3=random.randint(1,22)
num4=random.randint(1,16)
roadblock_x=num3*30-30
roadblock_y=num4*30-30
roadblock_position.append((roadblock_x,roadblock_y))
score+=1
else:
position.pop(0)
info="SCORE:"+str(score)
a=font.render(info,True,(0,0,0))
# 将背景图画上去
screen.blit(background, (0, 0))
# 将背景图画上去c
screen.blit(background, (0,0))
# 将贪吃蛇的头画上去
screen.blit(snake_head, position[-1])
# 将贪吃蛇的身体画上去
for i in range(len(position)-1):
screen.blit(body, position[i])
for i in range(len(roadblock_position)-1):
screen.blit(roadblock, roadblock_position[i])
# 将果实画上去
screen.blit(food,(apple_x,apple_y))
screen.blit(a, (0,0))
# 刷新画面
pygame.display.update()
FPSCLOCK.tick(3)
\ No newline at end of file
FPSCLOCK.tick(ticks)
\ No newline at end of file
路障2.png

858 Bytes

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