Commit ae3b5338 by BellCodeEditor

save project

parent 93048372
Showing with 16 additions and 8 deletions
...@@ -16,15 +16,27 @@ x=240 ...@@ -16,15 +16,27 @@ x=240
y=120 y=120
positon=[(180,90),(180,120),(210,120),(x,y)] positon=[(180,90),(180,120),(210,120),(x,y)]
FPSCLOCK=pygame.time.Clock() FPSCLOCK=pygame.time.Clock()
setheading="right"
while True: while True:
x += 30
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.key==locals.K_RIGHT and setheading!="left":
setheading="right"
x += 30
if event.key==locals.K_LEFT and setheading!="right":
setheading="left"
x -= 30
if event.key==locals.K_UP and setheading!="down":
setheading="up"
y -= 30
if event.key==locals.K_DOWN and setheading!="up":
setheading="down"
y +=30
positon.append((x,y))
positon.pop(0)
screen.blit(background, (0, 0)) screen.blit(background, (0, 0))
# 将贪吃蛇画上去 # 将贪吃蛇画上去
screen.blit(right, positon[-1]) screen.blit(right, positon[-1])
...@@ -33,9 +45,6 @@ while True: ...@@ -33,9 +45,6 @@ while True:
screen.blit(body, positon[i]) screen.blit(body, positon[i])
# 将果实画上去 # 将果实画上去
screen.blit(food, (360, 300)) screen.blit(food, (360, 300))
# 刷新画面
positon.append((x,y))
positon.pop(0)
pygame.display.update() pygame.display.update()
FPSCLOCK.tick(3) FPSCLOCK.tick(3)
\ 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