Commit 86aa613c by BellCodeEditor

auto save

parent 00f8fa2e
Showing with 32 additions and 2 deletions
import pygame
from pygame import locals
xy = []
FPS = pygame.time.Clock()
# 初始化pygame,为使用硬件做准备
......@@ -12,8 +11,15 @@ 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')
down = pygame.image.load('down.png')
up = pygame.image.load('up.png')
food = pygame.image.load('apple.png')
body = pygame.image.load('body.png')
xandy = 240,120
xy = [(180,90),(180,120),(210,120),(x,y)]
setheading = 'right'
snake_head = right
while True:
FPS.tick(3)
......@@ -21,10 +27,34 @@ while True:
if event.type == locals.QUIT:
# 接收到退出事件后退出程序
exit()
elif event.type == locals.KEYDOWN:
if event.key == locals.K_RIGHT and sethanding != 'left':
sethending = 'right'
snake_head = right
if event.key == locals.K_LEFT and sethanding != 'right':
setheanding = 'left'
snake_head = left
if event.key == locals.K_UP and sethanding != 'down':
sethending = 'up'
snake_head = up
if event.key == locals.K_DOWN and sethanding != 'up':
setheanding = 'down'
snake_head = down
if setheading == 'right':
x+=30
elif setheading == 'left':
x-=30
elif sethanding == 'up':
y-=30
else:
y+=30
xy.append(xandy)
xy.pop(0)
# 将背景图画上去
screen.blit(background, (0, 0))
# 将贪吃蛇画上去
screen.blit(right, xy[3])
for i in range(len(xy)-1):
screen.blit(body,xy[i])
# 将贪吃蛇的身体画上去
screen.blit(body, xy[2])
screen.blit(body, xy[1])
......
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