Commit 0c340ba4 by BellCodeEditor

auto save

parent e5af7d8e
Showing with 33 additions and 3 deletions
......@@ -12,18 +12,48 @@ background = pygame.image.load('bg.png')
right = pygame.image.load('right.png')
food = pygame.image.load('apple.png')
body = pygame.image.load('body.png')
up = pygame.image.load('up.png')
left = pygame.image.load('left.png')
down = pygame.image.load('down.png')
x = 240
y = 120
snake = [(180, 90), (180, 120), (210, 120),(x,y)]
position = [(180, 90), (180, 120), (210, 120),(x,y)]
set = "right"
snake = right
while True:
for event in pygame.event.get():
if event.type == locals.QUIT:
# 接收到退出事件后退出程序
exit()
x += 30
if event.type == locals.KEYDOWN:
if event.key == locals.K_d and set != 'left':
set = 'right'
snake = right
if event.key == locals.K_a and set != 'right':
set = 'left'
snake = left
if event.key == locals.K_w and set != 'down':
set = 'up'
snake = up
if event.key == locals.K_s and set != 'up':
set = 'down'
snake = down
if set == 'right':
x +=30
if set == 'left':
x -=30
if set == 'up':
y -=30
if set == 'down':
y +=30
position.append((x,y))
position.pop(0)
screen.blit(background,(0,0))
screen.blit(snake, position[-1])
for i in range(len(position)-1):
screen.blit(body,position[i])
screen.blit(food, (360, 300))
# 刷新画面
pygame.display.update()
......
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