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