Commit 16c34f51 by BellCodeEditor

auto save

parent 96b78aa0
Showing with 27 additions and 4 deletions
......@@ -7,19 +7,43 @@ pygame.init()
bodys=[(180, 90),(180, 120),(210, 120), (x,y)]
# 创建一个窗口
screen = pygame.display.set_mode((660, 480))
# 背景
background = pygame.image.load('bg.png')
right = pygame.image.load('right.png')
left = pygame.image.load('left.png')
up = pygame.image.load('up.png')
down = pygame.image.load('down.png')
food = pygame.image.load('apple.png')
body = pygame.image.load('body.png')
F=pygame.time.Clock()
T="right"
snack_head=right
while True:
for event in pygame.event.get():
if event.type == locals.QUIT:
# 接收到退出事件后退出程序
exit()
if event.type == locals.KEYDOWN:
if event.key==locals.K_LEFT and T!="right":
T="left"
snack_head=left
if event.key==locals.K_RIGHT and T!="left":
T="right"
snack_head=right
if event.key==locals.K_UP and T!="down":
T="up"
snack_head=up
if event.key==locals.K_DOWN and T!="up":
T="down"
snack_head=down
if T=="right":
x+=30
if T=="left":
x-=30
if T=="up":
y-=30
if T=="down":
y+=30
# 将背景图画上去
screen.blit(background, (0, 0))
# 将贪吃蛇画上去
......@@ -32,9 +56,8 @@ while True:
screen.blit(food, (360, 300))
for i in range(len(bodys)-1):
screen.blit(body,bodys[i])
x+=30
bodys.pop(0)
bodys.append((x,y))
bodys.pop(0)
F.tick(5)
# 刷新画面
pygame.display.update()
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