Commit ec5bc27f by BellCodeEditor

save project

parent 5e82d83d
Showing with 18 additions and 3 deletions
...@@ -18,9 +18,10 @@ FPSCLock=pygame.time.Clock() ...@@ -18,9 +18,10 @@ FPSCLock=pygame.time.Clock()
setheading = "right" 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.type == locals.KEYDOWN: if event.type == locals.KEYDOWN:
if event.key == locals.K_RIGHT and setheading != "left": if event.key == locals.K_RIGHT and setheading != "left":
setheading = "right" setheading = "right"
...@@ -29,7 +30,21 @@ while True: ...@@ -29,7 +30,21 @@ while True:
if event.key == locals.K_UP and setheading != "down": if event.key == locals.K_UP and setheading != "down":
setheading = "up" setheading = "up"
if event.key == locals.K_DOWN and setheading != "left": if event.key == locals.K_DOWN and setheading != "left":
setheading = "down" setheading = "down"
if setheading == "right":
x+=30
elif setheading == "left":
x-=30
elif setheading == "up":
y+=30
else:
y-=30
# 将背景图画上去 # 将背景图画上去
screen.blit(background, (0, 0)) screen.blit(background, (0, 0))
# 将贪吃蛇画上去 # 将贪吃蛇画上去
...@@ -46,7 +61,7 @@ while True: ...@@ -46,7 +61,7 @@ while True:
screen.blit(food, (360, 300)) screen.blit(food, (360, 300))
# 刷新画面 # 刷新画面
pygame.display.update() pygame.display.update()
x=x+30
FPSCLock.tick(3) FPSCLock.tick(3)
......
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