Commit 32653ea0 by BellCodeEditor

save project

parent 493e59ee
Showing with 30 additions and 5 deletions
...@@ -12,22 +12,47 @@ background = pygame.image.load('bg.png') ...@@ -12,22 +12,47 @@ 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')
body = pygame.image.load('body.png') body = pygame.image.load('body.png')
down = pygame.image.load('down.png')
up = pygame.image.load('up.png')
left = pygame.image.load('left.png')
x,y=240,120 x,y=240,120
s=pygame.time.Clock() s=pygame.time.Clock()
a=[(210,120),(180,120),(180,90),(x,y)] a=[(210,120),(180,120),(180,90),(x,y)]
set1='right'
st=right
while True: while True:
for event in pygame.event.get(): for i in pygame.event.get():
if event.type == locals.QUIT: if i.type == locals.QUIT:
# 接收到退出事件后退出程序 # 接收到退出事件后退出程序
exit() exit()
x+=30 if i.type == locals.KEYDOWN:
if i.key == locals.K_RIGHT and set1 != 'left':
set1='right'
st=right
if i.key == locals.K_LEFT and set1 !='right':
set1='left'
st=left
if i.key == locals.K_UP and set1 !='down':
set1='up'
st=up
if i.key == locals.K_DOWN and set1 != 'up':
set1='down'
st=down
if set1=='right':
x+=30
elif set1=='left':
x-=30
elif set1=='down':
y+=30
else:
y-=30
a.append((x,y)) a.append((x,y))
a.pop(0) a.pop(0)
# 将背景图画上去 # 将背景图画上去
screen.blit(background, (0, 0)) screen.blit(background, (0, 0))
# 将贪吃蛇画上去 # 将贪吃蛇画上去
screen.blit(right, a[-1]) screen.blit(st, a[-1])
# 将贪吃蛇的身体画上去 # 将贪吃蛇的身体画上去
for i in range(len(a)-1): for i in range(len(a)-1):
screen.blit(body,a[i]) screen.blit(body,a[i])
......
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