Commit b12d9374 by BellCodeEditor

save project

parent 8339fceb
Showing with 29 additions and 8 deletions
...@@ -8,6 +8,8 @@ pygame.init() ...@@ -8,6 +8,8 @@ pygame.init()
screen = pygame.display.set_mode((800, 600)) screen = pygame.display.set_mode((800, 600))
x=240 x=240
y=120 y=120
setheading="r"
position=[(150,120),(180,120),(210,120),(x,y)]
# 背景 # 背景
FPSCLOCK=pygame.time.Clock() FPSCLOCK=pygame.time.Clock()
background = pygame.image.load('bg.png') background = pygame.image.load('bg.png')
...@@ -20,17 +22,36 @@ while True: ...@@ -20,17 +22,36 @@ while True:
if event.type == locals.QUIT: if event.type == locals.QUIT:
# 接收到退出事件后退出程序 # 接收到退出事件后退出程序
exit() exit()
if event.type==locals.KEYDOWN:
if event.key==locals.K_DOWN:
setheading='d'
if event.key==locals.K_UP:
setheading='u'
if event.key==locals.K_RIGHT:
setheading='r'
if event.key==locals.K_LEFT:
setheading='l'
# 将背景图画上去 # 将背景图画上去
screen.blit(background, (0, 0)) screen.blit(background, (0, 0))
screen.blit(right,(x,y))
x+=0.5
# 将贪吃蛇画上去 # 将贪吃蛇画上去
screen.blit(right,position[len(position)-1])
# 将贪吃蛇的身体画上去 # 将贪吃蛇的身体画上去
screen.blit(body, (x-30, y)) for i in range(len(position)-2,-1,-1):
screen.blit(body, (x-60, y)) screen.blit(body,position[i])
screen.blit(body, (x-90, y))
if setheading=="r":
x+=30
if setheading=="l":
x-=30
if setheading=="u":
y-=30
if setheading=="d":
y+=30
# 将果实画上去 # 将果实画上去
screen.blit(food, (360, 300)) screen.blit(food,(120,190))
position.append((x,y))
position.pop(0)
# 刷新画面 # 刷新画面
pygame.display.update() pygame.display.update()
FPSCLOCK.tick(60) FPSCLOCK.tick(30ss)
\ No newline at end of file \ 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