Commit 07d4d42d by BellCodeEditor

save project

parent febd9cb5
Showing with 10 additions and 3 deletions
...@@ -6,8 +6,6 @@ down = pygame.image.load('down.png') ...@@ -6,8 +6,6 @@ down = pygame.image.load('down.png')
x=240 x=240
y=120 y=120
position = [(180,90),(180,120),(210,120),(x,y)] position = [(180,90),(180,120),(210,120),(x,y)]
setheading="right"
snake_head=right
# 初始化pygame,为使用硬件做准备 # 初始化pygame,为使用硬件做准备
pygame.init() pygame.init()
...@@ -19,6 +17,8 @@ background = pygame.image.load('bg.png') ...@@ -19,6 +17,8 @@ background = pygame.image.load('bg.png')
right = pygame.image.load('right.png') 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')
setheading="right"
snake_head=right
while True: while True:
for event in pygame.event.get(): for event in pygame.event.get():
...@@ -38,7 +38,14 @@ while True: ...@@ -38,7 +38,14 @@ while True:
if event.key == locals.K_down and setheading != "up": if event.key == locals.K_down and setheading != "up":
setheading="down" setheading="down"
snake_head=down snake_head=down
x += 30 if setheading=="right":
x+=30
elif setheading=="left":
x-=30
elif setheading=="up":
y+=30
else:
y+=30
position.append((x,y)) position.append((x,y))
position.pop(0) position.pop(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