Commit b8db9b9d by BellCodeEditor

save project

parent 9228b980
Showing with 7 additions and 5 deletions
...@@ -13,18 +13,20 @@ right = pygame.image.load('right.png') ...@@ -13,18 +13,20 @@ 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')
x, y = 240, 120 x, y = 240, 120
setheading = 'right'
while True: while True:
for event in pygame.event.get(): for event in pygame.event.get():
if event.type == locals.QUIT: if event.type == locals.QUIT:
# 接收到退出事件后退出程序 # 接收到退出事件后退出程序
exit() exit()
if event.key == locals.K_RIGHT and setheading != "left" if event.type == locals.KEYDOWN:
setheading = 'right if event.key == locals.K_RIGHT and setheading != "left":
if event.key == locals.K_RIGHT and setheading != "right" setheading = 'right'
if event.key == locals.K_RIGHT and setheading != "right":
setheading = 'left' setheading = 'left'
if event.key == locals.K_RIGHT and setheading != "down" if event.key == locals.K_RIGHT and setheading != "down":
setheading = 'up' setheading = 'up'
if event.key == locals.K_RIGHT and setheading != "up" if event.key == locals.K_RIGHT and setheading != "up":
setheading = 'down' setheading = 'down'
if setheading == "right": if setheading == "right":
......
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