Commit 0f802d54 by BellCodeEditor

save project

parent 57557720
Showing with 26 additions and 3 deletions
......@@ -12,16 +12,39 @@ 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')
up = pygame.image.load('up.png')
down = pygame.image.load('down.png')
X, Y = 240, 120
i = [(180, 90), (180, 120), (210, 120), (X, Y)]
t = "right"
e = right
while True:
for event in pygame.event.get():
if event.type == locals.QUIT:
# 接收到退出事件后退出程序
exit()
X += 30
i.append((X, Y))
i.pop(0)
elif event.type == locals.KEYDOWN:
if event.key == locals.K_RIGHT and t !="left":
t = "right"
e = right
if event.key == locals.K_RIGHT and t !="down":
t = "up"
e = up
if event.key == locals.K_RIGHT and t !="right":
t = "left"
e = left
if event.key == locals.K_RIGHT and t !="up":
t = "down"
e = down
if t == "right":
x += 30
elif t == "left":
x -= 30
elif t == "up":
x -= 30
else:
y += 30
# 将背景图画上去
screen.blit(background, (0, 0))
# 将贪吃蛇画上去
......
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