Commit b38e5cad by BellCodeEditor

save project

parent 525643e5
Showing with 37 additions and 4 deletions
...@@ -12,9 +12,14 @@ background = pygame.image.load('bg.png') ...@@ -12,9 +12,14 @@ background = pygame.image.load('bg.png')
right = pygame.image.load('right.png') right = pygame.image.load('right.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')
left=pygame.image.load('left.png')
up=pygame.image.load('up.png')
down=pygame.image.load('down.png')
x=240 x=240
y=120 y=120
p=[(180,90),(180,120),(210,120),(x,y)] p=[(180,90),(180,120),(210,120),(x,y)]
s='right'
s_1=right
while True: while True:
pygame.time.Clock().tick(3) pygame.time.Clock().tick(3)
...@@ -23,16 +28,44 @@ while True: ...@@ -23,16 +28,44 @@ while True:
if event.type == locals.QUIT: if event.type == locals.QUIT:
# 接收到退出事件后退出程序 # 接收到退出事件后退出程序
exit() exit()
if event.type == locals.KEYDOWN:
if event.key == locals.K_RIGHT and s != 'left':
s='right'
s_1=right
if event.key == locals.K_LEFT and s != 'right':
s='left'
s_1=left
if event.key == locals.K_UP and s != 'up':
s='up'
s_1=up
if event.key == locals.K_DOWN and s != 'down':
s='down'
s_1=down
# 将背景图画上去 # 将背景图画上去
screen.blit(background, (0, 0)) screen.blit(background, (0, 0))
# 将贪吃蛇画上去 # 将贪吃蛇画上去
screen.blit(right, (x, y)) if s=='right':
x+=30 x+=30
if s=='left':
x-=30
if s=='up':
y-=30
if s=='down':
y+=30
screen.blit(s_1, (x, y))
for i in range(len(p)-1):
screen.blit(body,p[i])
p.append((x,y)) p.append((x,y))
p.pop(0) p.pop(0)
for i in range(len(p)-1):
screen.blit(body,p[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