Commit 0e70adf2 by BellCodeEditor

save project

parent da8c533a
Showing with 33 additions and 7 deletions
...@@ -9,28 +9,54 @@ screen = pygame.display.set_mode((660, 480)) ...@@ -9,28 +9,54 @@ screen = pygame.display.set_mode((660, 480))
a=pygame.time.Clock() a=pygame.time.Clock()
set = "right"
x , y = 240 , 120 x , y = 240 , 120
abab = [(210, 120),(180, 120),(180, 90),(x,y)] abab = [(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')
food = pygame.image.load('apple.png') food = pygame.image.load('apple.png')
body = pygame.image.load('body.png') body = pygame.image.load('body.png')
up = pygame.image.load('up.png')
left = pygame.image.load('left.png')
down = pygame.image.load('down.png')
snake = 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()
elif event.type == locals.KEYDOWN:
if event.key == locals.K_RIGHT and set != "left":
x += 30 set = "right"
snake = right
if event.key == locals.K_LEFT and set != "right":
set = "left"
snake = left
if event.key == locals.K_UP and set != "down":
set = "up"
snake = up
if event.key == locals.K_DOWN and set != "up":
set = "down"
snake = down
if set == "right":
x += 30
if set == "left":
x -= 30
if set == "up":
y -= 30
if set == "down":
y += 30
abab.append((x,y)) abab.append((x,y))
abab.pop(0) abab.pop(0)
# 将背景图画上去 # 将背景图画上去
screen.blit(background, (0, 0)) screen.blit(background, (0, 0))
# 将贪吃蛇画上去 # 将贪吃蛇画上去
screen.blit(right, (x, y)) screen.blit(snake, (x, y))
# 将贪吃蛇的身体画上去 # 将贪吃蛇的身体画上去
for i in range(len(abab)-1): for i in range(len(abab)-1):
screen.blit(body ,abab[i]) screen.blit(body ,abab[i])
...@@ -41,4 +67,4 @@ while True: ...@@ -41,4 +67,4 @@ while True:
screen.blit(food, (360, 300)) screen.blit(food, (360, 300))
# 刷新画面 # 刷新画面
pygame.display.update() pygame.display.update()
a.tick(10) a.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