Commit cc45df01 by BellCodeEditor

save project

parent 0d7a0795
Showing with 31 additions and 2 deletions
......@@ -11,10 +11,16 @@ screen = pygame.display.set_mode((660, 480))
# 背景
background = pygame.image.load('bg.png')
right = pygame.image.load('right.png')
left = pygame.image.load('left.png')
up = pygame.image.load('up.png')
down = pygame.image.load('down.png')
food = pygame.image.load('apple.png')
body = pygame.image.load('body.png')
x,y=240,120
a=[(180,90),(180,120),(210,120),(240,120)]
b='right'
snake_head = right
......@@ -23,7 +29,30 @@ while True:
if event.type == locals.QUIT:
# 接收到退出事件后退出程序
exit()
x+=30
if event.type == locals.KEYDOWN:
if event.key == locals.K_RIGHT and b != 'left':
b='right'
snake_head=right
if event.key == locals.K_LEFT and b != 'right':
b='left'
snake_head=left
if event.key == locals.K_UP and b != 'down':
b='up'
snake_head=up
if event.key == locals.K_DOWN and b != 'up':
b='down'
snake_head=down
if b == 'right':
x+=30
elif b == 'left':
x-=30
elif b == 'up':
y-=30
else:
y+=30
a.append((x,y))
a.pop(0)
......@@ -31,7 +60,7 @@ while True:
screen.blit(background, (0, 0))
# 将贪吃蛇画上去
screen.blit(right, a[-1])
screen.blit(snake_head, a[-1])
for i in range(len(a)-1):
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