Commit 86d3bda7 by BellCodeEditor

save project

parent 29e72c05
Showing with 17 additions and 17 deletions
......@@ -6,8 +6,7 @@ pygame.init()
# 创建一个窗口
screen = pygame.display.set_mode((660, 480))
x,y=240,120
dog=[(210,120),(180,120),(180,90),(x,y)]
m=pygame.time.Clock()
# 背景
background = pygame.image.load('bg.png')
......@@ -17,6 +16,8 @@ body = pygame.image.load('body.png')
left= pygame.image.load('left.png')
up= pygame.image.load('up.png')
down = pygame.image.load('down.png')
x,y=240,120
dog=[(180,90),(180,120),(210,120),(x,y)]
u="right"
sk=right
while True:
......@@ -25,33 +26,32 @@ while True:
# 接收到退出事件后退出程序
exit()
if event.type == locals.KEYDOWN:
if event.type == locals.RIGHT and u!='left':
if event.key== locals.K_RIGHT and u!='left':
u='right'
sk=right
if events.type == locals.LEFT and u!='right':
if event.key == locals.K_LEFT and u!='right':
u='left'
sk=left
if event.type == locals.DOWN and u!='up':
if event.key== locals.K_DOWN and u!='up':
u='down'
sk=down
if event.type == locals.UP and u!='down':
if event.key== locals.K_UP and u!='down':
u='up'
sk=up
if u=="right":
x+=30
if u=="left":
x-=30
if u=="up":
y-=30
if u=="down":
y+=30
x+=30
if u=="right":
x+=30
elif u=="left":
x-=30
elif u=="up":
y-=30
else:
y+=30
dog.append((x,y))
dog.pop(0)
# 将背景图画上去
screen.blit(background, (0, 0))
# 将贪吃蛇画上去
screen.blit(right, dog[-1])
screen.blit(sk, dog[-1])
# 将贪吃蛇的身体画上去
for i in range(len(dog)-1):
screen.blit(body,dog[i])
......@@ -61,4 +61,4 @@ while True:
# 刷新画面
m.tick(3)
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