Commit aae61cf2 by BellCodeEditor

save project

parent 2ca75163
Showing with 38 additions and 5 deletions
......@@ -12,19 +12,51 @@ background = pygame.image.load('bg.png')
right = pygame.image.load('right.png')
food = pygame.image.load('apple.png')
body = pygame.image.load('body.png')
left=pygame.image.load('left.png')
down=pygame.image.load('down.png')
up=pygame.image.load('up.png')
x,y=240,120
b=[(180,90),(180,120),(210,120),(x,y)]
s='right'
snake_head=right
while True:
for event in pygame.event.get():
if event.type == locals.QUIT:
# 接收到退出事件后退出程序
exit()
if event.type==locals.KEYDOWN:
if event.key==locals.K_RIGHT and s !='left':
s='right'
snake_head=right
if event.key==locals.K_LEFT and s !='right':
s='left'
snake_head=left
if event.key==locals.K_UP and s !='down':
s='up'
snake_head=up
if event.key==locals.K_DOWN and s !='up':
s='down'
snake_head=down
if s=='right':
x+=30
elif s=='left':
x-=30
elif s=='up':
y-=30
else:
y+=30
b.append((x,y))
b.pop(0)
screen.blit(background,(0,0))
# 将背景图画上去
screen.blit(background, (0, 0))
# 将贪吃蛇画上去
screen.blit(right, b[-1])
screen.blit(snake_head, b[-1])
# 将贪吃蛇的身体画上去
for i in range(len(b)-1):
screen.blit(body,b[i])
......@@ -33,9 +65,9 @@ while True:
# screen.blit(body, (180, 90))
# 将果实画上去
screen.blit(food, (360, 300))
x+=30
b.append((x,y))
b.pop(0)# 刷新画面
# 刷新画面
pygame.display.update()
a.tick(3)
\ 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