Commit 9e471c56 by BellCodeEditor

save project

parent 0e4597a5
Showing with 26 additions and 4 deletions
...@@ -18,19 +18,41 @@ down = pygame.image.load('down.png') ...@@ -18,19 +18,41 @@ down = pygame.image.load('down.png')
x,y = 240,120 x,y = 240,120
sb=[(180,90),(180,120),(210,120),(x,y)] sb=[(180,90),(180,120),(210,120),(x,y)]
sth='right' sth='right'
ioit=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:
# 接收到退出事件后退出程序 # 接收到退出事件后退出程序
exit() exit()
if event.type == locals.KEYDOWN: if event.type == locals.KEYDOWN:
x+=30 if event.key==locals.K_RIGHT and sth!='left':
sth='right'
ioit=right
if event.key==locals.K_LEFT and sth!='right':
sth='left'
ioit=left
if event.key==locals.K_DOWN and sth!='up':
sth='down'
ioit=down
if event.key==locals.K_UP and sth!='down':
sth='up'
ioit=up
if sth=="right":
x +=30
elif sth=="left":
x -=30
elif sth=="up":
y -=30
else:
y +=30
sb.append((x,y)) sb.append((x,y))
sb.pop(0) sb.pop(0)
# 将背景图画上去 # 将背景图画上去
screen.blit(background, (0, 0)) screen.blit(background, (0, 0))
# 将贪吃蛇画上去 # 将贪吃蛇画上去
screen.blit(right,sb[-1]) screen.blit(ioit,sb[-1])
# 将贪吃蛇的身体画上去 # 将贪吃蛇的身体画上去
for i in range(len(sb)-1): for i in range(len(sb)-1):
screen.blit(body,sb[i]) screen.blit(body,sb[i])
...@@ -40,4 +62,4 @@ while True: ...@@ -40,4 +62,4 @@ while True:
screen.blit(food, (360, 300)) screen.blit(food, (360, 300))
# 刷新画面 # 刷新画面
pygame.display.update() pygame.display.update()
idiot.tick(10) idiot.tick(3)
\ No newline at end of file \ 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