Commit f799ebac by BellCodeEditor

save project

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