Commit bdee280a by BellCodeEditor

save project

parent f0353f2d
Showing with 27 additions and 4 deletions
...@@ -8,11 +8,14 @@ screen = pygame.display.set_mode((660, 480)) ...@@ -8,11 +8,14 @@ screen = pygame.display.set_mode((660, 480))
FPSCLOCK=pygame.time.Clock() FPSCLOCK=pygame.time.Clock()
# 背景 # 背景
background = pygame.image.load('bg.png') background = pygame.image.load('bg.png')
left = pygame.image.load('left.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') up=pygame.image.load('up.png')
down=pygame.image.load('down.png') down=pygame.image.load('down.png')
seathing="right"
snake_head=right
x,y=240,120 x,y=240,120
pioition=[(180,90),(180,120),(210,120),(x,y)] pioition=[(180,90),(180,120),(210,120),(x,y)]
while True: while True:
...@@ -20,13 +23,33 @@ while True: ...@@ -20,13 +23,33 @@ 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 seathing!="left":
seathing="right"
snake_head=right
if event.key == locals.K_LEFT and seathing!="right":
seathing="left"
snake_head=left
if event.key == locals.K_UP and seathing!="down":
seathing="up"
snake_head=up
if event.key == locals.K_DOWN and seathing!="up":
seathing="down"
snake_head=down
# 将背景图画上去 # 将背景图画上去
x+=30 if seathing =="up":
y-=30
elif seathing =="down":
y+=30
elif seathing =="right":
x+=30
elif seathing =="left":
x-=30
pioition.append((x,y)) pioition.append((x,y))
pioition.pop(0) pioition.pop(0)
screen.blit(background, (0, 0)) screen.blit(background, (0, 0))
# 将贪吃蛇画上去 # 将贪吃蛇画上去
screen.blit(right,(x,y)) screen.blit(snake_head,(x,y))
# 将贪吃蛇的身体画上去 # 将贪吃蛇的身体画上去
#screen.blit(body, (210, 120)) #screen.blit(body, (210, 120))
#screen.blit(body, (180, 120)) #screen.blit(body, (180, 120))
...@@ -37,4 +60,4 @@ while True: ...@@ -37,4 +60,4 @@ while True:
screen.blit(food, (360, 300)) screen.blit(food, (360, 300))
# 刷新画面 # 刷新画面
pygame.display.update() pygame.display.update()
FPSCLOCK.tick(3) FPSCLOCK.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