Commit afd8b419 by BellCodeEditor

save project

parent 406b6ff5
Showing with 28 additions and 2 deletions
...@@ -10,6 +10,9 @@ screen = pygame.display.set_mode((660, 480)) ...@@ -10,6 +10,9 @@ screen = pygame.display.set_mode((660, 480))
# 背景 # 背景
background = pygame.image.load('bg.png') background = pygame.image.load('bg.png')
right = pygame.image.load('right.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') food = pygame.image.load('apple.png')
body = pygame.image.load('body.png') body = pygame.image.load('body.png')
...@@ -17,20 +20,43 @@ wait=pygame.time.Clock() ...@@ -17,20 +20,43 @@ wait=pygame.time.Clock()
x,y=240, 120 x,y=240, 120
s=[(210, 120), (180, 120), (180, 90),(x,y)] s=[(210, 120), (180, 120), (180, 90),(x,y)]
fx="right"
t=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 fx!="left":
fx="right"
t=right
if event.key==locals.K_LEFT and fx!="right":
fx="left"
t=left
if event.key==locals.K_UP and fx!="down":
fx="up"
t=up
if event.key==locals.K_DOWN and fx!="up":
fx="down"
t=down
if fx=="right":
x+=30
elif fx=="left":
x-=30
elif fx=="up":
y-=30
else:
y+=30
s.append((x,y)) s.append((x,y))
s.pop(0) s.pop(0)
# 将背景图画上去 # 将背景图画上去
screen.blit(background, (0, 0)) screen.blit(background, (0, 0))
screen.blit(t,s[-1])
# 将贪吃蛇画上去 # 将贪吃蛇画上去
screen.blit(right,s[-1])
for i in range(len(s)-1): for i in range(len(s)-1):
screen.blit(body, s[i]) screen.blit(body, s[i])
# 将贪吃蛇的身体画上去 # 将贪吃蛇的身体画上去
# screen.blit(body, (210, 120)) # screen.blit(body, (210, 120))
# screen.blit(body, (180, 120)) # screen.blit(body, (180, 120))
......
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