Commit 288a30c6 by BellCodeEditor

save project

parent 313b2bfb
Showing with 11 additions and 10 deletions
...@@ -16,6 +16,7 @@ right= pygame.image.load('right.png') ...@@ -16,6 +16,7 @@ right= pygame.image.load('right.png')
x,y=240,120 x,y=240,120
position=[(180,90),(180,120),(210,120),(x,y)] position=[(180,90),(180,120),(210,120),(x,y)]
s="right" s="right"
d=right
while True: while True:
for event in pygame.event.get(): for event in pygame.event.get():
if event.type == locals.QUIT: if event.type == locals.QUIT:
...@@ -23,31 +24,31 @@ while True: ...@@ -23,31 +24,31 @@ while True:
exit() exit()
if event.type==locals.KEYDOWN: if event.type==locals.KEYDOWN:
if event.key==locals.K_RIGHT and s!='left': if event.key==locals.K_RIGHT and s!='left':
s="right" s="right"
d=right
if event.key==locals.K_LEFT and s!='right': if event.key==locals.K_LEFT and s!='right':
s="left" s="left"
d=left
if event.key==locals.K_UP and s!='down': if event.key==locals.K_UP and s!='down':
s="up" s="up"
d=up
if event.key==locals.K_DOWN and s!='up': if event.key==locals.K_DOWN and s!='up':
s="down" s="down"
d=down
if s == "right": if s == "right":
x+=30 x+=30
screen.blit(right,(x,y))
if s == "up": if s == "up":
y+=30
screen.blit(up,(x,y))
if s == "down":
y-=30 y-=30
screen.blit(down,(x,y)) if s == "down":
y+=30
if s == "left": if s == "left":
x-=30 x-=30
screen.blit(left,(x,y))
position.append((x,y)) position.append((x,y))
position.pop(0) position.pop(0)
# 将背景图画上去 # 将背景图画上去
screen.blit(background, (0, 0)) screen.blit(background, (0, 0))
# 将贪吃蛇画上 # 将贪吃蛇画上
screen.blit(right, (x,y)) screen.blit(d, (x,y))
# 将贪吃蛇的身体画上去 # 将贪吃蛇的身体画上去
for i in range(len(position)-1): for i in range(len(position)-1):
screen.blit(body,position[i]) screen.blit(body,position[i])
......
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