Commit 44c07355 by BellCodeEditor

save project

parent d5739bd2
Showing with 17 additions and 17 deletions
...@@ -20,8 +20,8 @@ down = pygame.image.load('down.png') # 头 朝下 ...@@ -20,8 +20,8 @@ down = pygame.image.load('down.png') # 头 朝下
x, y = 240, 120 x, y = 240, 120
position = [(180, 90), (180, 120), (210, 120), (x, y)] position = [(180, 90), (180, 120), (210, 120), (x, y)]
setheading = "right" setheading = "d"
snake_head = right snake_head = d
while True: while True:
for event in pygame.event.get(): for event in pygame.event.get():
...@@ -29,25 +29,25 @@ while True: ...@@ -29,25 +29,25 @@ while True:
# 接收到退出事件后退出程序 # 接收到退出事件后退出程序
exit() exit()
if event.type == locals.KEYDOWN: if event.type == locals.KEYDOWN:
if event.key == locals.K_RIGHT and setheading != "left": if event.key == locals.K_d and setheading != "a":
setheading = 'right' setheading = 'd'
snake_head = right snake_head = d
if event.key == locals.K_LEFT and setheading != "right": if event.key == locals.K_a and setheading != "d":
setheading = 'left' setheading = 'a'
snake_head = left snake_head = a
if event.key == locals.K_UP and setheading != "down": if event.key == locals.K_w and setheading != "s":
setheading = 'up' setheading = 'a'
snake_head = up snake_head = a
if event.key == locals.K_DOWN and setheading != "up": if event.key == locals.K_s and setheading != "w":
setheading = 'down' setheading = 's'
snake_head = down snake_head = w
# 设置贪吃蛇的头部坐标 # 设置贪吃蛇的头部坐标
if setheading == "right": if setheading == "d"
x += 30 x += 30
elif setheading == "left": elif setheading == "a":
x -= 30 x -= 30
elif setheading == "up": elif setheading == "w":
y -= 30 y -= 30
else: else:
y += 30 y += 30
......
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