Commit bad7a58e by BellCodeEditor

save project

parent 8c9264c3
Showing with 29 additions and 8 deletions
...@@ -7,7 +7,8 @@ pygame.init() ...@@ -7,7 +7,8 @@ pygame.init()
# 创建一个窗口 # 创建一个窗口
screen = pygame.display.set_mode((660, 480)) screen = pygame.display.set_mode((660, 480))
x,y=240, 120 x,y=240, 120
setheading="right"
aaa=[(180, 90),(180, 120),(210, 120),(x,y)]
# 背景 # 背景
background = pygame.image.load('bg.png') background = pygame.image.load('bg.png')
right = pygame.image.load('right.png') right = pygame.image.load('right.png')
...@@ -16,21 +17,41 @@ body = pygame.image.load('body.png') ...@@ -16,21 +17,41 @@ body = pygame.image.load('body.png')
aa=pygame.time.Clock() aa=pygame.time.Clock()
while True: while True:
x+=30 if setheading=="right":
x+=30
elif setheading=="left":
x-=30
elif setheading=="up":
y-=30
else:
y+=30
aaa.append((x,y))
aaa.pop(0)
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 setheading != "left":
setheading="right"
if event.key==locals.K_LEFT and setheading != "right":
setheading="left"
if event.key==locals.K_UP and setheading != "down":
setheading="up"
if event.key==locals.K_DOWN and setheading != "up":
setheading="down"
# 将背景图画上去 # 将背景图画上去
screen.blit(background, (0, 0)) screen.blit(background, (0, 0))
# 将贪吃蛇画上去 # 将贪吃蛇画上去
screen.blit(right, (x,y)) screen.blit(right, aaa[-1])
# 将贪吃蛇的身体画上去 # 将贪吃蛇的身体画上去
screen.blit(body, (210, 120)) for i in range(len(aaa)-1):
screen.blit(body, (180, 120)) screen.blit(body,aaa[i])
screen.blit(body, (180, 90)) # screen.blit(body, (210, 120))
# screen.blit(body, (180, 120))
# screen.blit(body, (180, 90))
# 将果实画上去 # 将果实画上去
screen.blit(food, (360, 300)) screen.blit(food, (360, 300))
# 刷新画面 # 刷新画面
pygame.display.update() pygame.display.update()
aa.tick(24) aa.tick(1)
\ 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