Commit f109eda3 by BellCodeEditor

save project

parent 4bbacde7
Showing with 30 additions and 4 deletions
......@@ -10,8 +10,13 @@ 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')
sh="right"
head=right
x=240
y=120
l1=[(x,y),(x,y),(x,y),(x,y)]
......@@ -21,11 +26,32 @@ while True:
if event.type == locals.QUIT:
# 接收到退出事件后退出程序
exit()
if event.type==locals.KEYDOWN:
if event.key==locals.K_UP and sh !="down":
sh="up"
head=up
elif event.key==locals.K_DOWN and sh !="up":
sh="down"
head=down
elif event.key==locals.K_LEFT and sh !="right":
sh="left"
head=left
elif event.key==locals.K_RIGHT and sh !="left":
sh="right"
head=right
if sh=="right":
x+=30
elif sh=="left":
x-=30
elif sh=="up":
y-=30
elif sh=="down":
y+=30
# 将背景图画上去
screen.blit(background, (0, 0))
# 将贪吃蛇画上去
x+=30
screen.blit(right, (x, y))
screen.blit(head, (x, y))
l1.append((x,y))
l1.pop(0)
# 将贪吃蛇的身体画上去
......@@ -39,4 +65,4 @@ while True:
screen.blit(food, (360, 300))
# 刷新画面
pygame.display.update()
z.tick(2)
\ No newline at end of file
z.tick(5)
\ 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