Commit f799ebac by BellCodeEditor

save project

parent c839794c
Showing with 10 additions and 6 deletions
...@@ -19,7 +19,7 @@ FPS = pygame.time.Clock() ...@@ -19,7 +19,7 @@ FPS = pygame.time.Clock()
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)]
heading = "right" heading = "right"
head = 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:
...@@ -28,25 +28,29 @@ while True: ...@@ -28,25 +28,29 @@ while True:
if event.type == locals.KEYDOWN: if event.type == locals.KEYDOWN:
if event.key == locals.K_RIGHT and heading != "left": if event.key == locals.K_RIGHT and heading != "left":
heading = "right" heading = "right"
head = right
if event.key == locals.K_LEFT and heading != "right": if event.key == locals.K_LEFT and heading != "right":
heading = "left" heading = "left"
head = left
if event.key == locals.K_UP and heading != "down": if event.key == locals.K_UP and heading != "down":
heading = "up" heading = "up"
head = up
if event.key == locals.K_DOWN and heading != "up": if event.key == locals.K_DOWN and heading != "up":
heading = "down" heading = "down"
head = down
if heading == "right": if heading == "right":
x += 30 x += 30
if heading == "left": if heading == "left":
x -= 30 x -= 30
if heading == "up": if heading == "up":
x -= 30 y -= 30
if heading == "down": if heading == "down":
x += 30 y += 30
position.append((x,y)) position.append((x,y))
position.pop(0) position.pop(0)
screen.blit(background, (0, 0)) screen.blit(background, (0, 0))
# 将贪吃蛇画上去 # 将贪吃蛇画上去
screen.blit(right, (x, y)) screen.blit(head, (x, y))
# 将贪吃蛇的身体画上去 # 将贪吃蛇的身体画上去
for i in range(len(position)-1): for i in range(len(position)-1):
screen.blit(body,position[i]) screen.blit(body,position[i])
...@@ -54,4 +58,4 @@ while True: ...@@ -54,4 +58,4 @@ while True:
screen.blit(food, (360, 300)) screen.blit(food, (360, 300))
# 刷新画面 # 刷新画面
pygame.display.update() pygame.display.update()
FPS.tick(3) FPS.tick(5)
\ No newline at end of file \ No newline at end of file
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