Commit 3b19ff4d by BellCodeEditor

save project

parent 936c519a
Showing with 26 additions and 8 deletions
......@@ -12,30 +12,48 @@ background = pygame.image.load('bg.png')
right = pygame.image.load('right.png')
food = pygame.image.load('apple.png')
body = pygame.image.load('body.png')
right = pygame.image.load('right.png')
right = pygame.image.load('right.png')
right = pygame.image.load('right.png')
left = pygame.image.load('left.png')
up = pygame.image.load('up.png')
down = pygame.image.load('down.png')
x = 240
x , y = 240, 120
wz = [(x - 90, y),(x - 60, y),(x-30, y),(x, y)]#初始位置
fx = "s"
st = right
while True:
for event in pygame.event.get():
if event.type == locals.QUIT:
# 接收到退出事件后退出程序
exit()
if event.type == locals.KEYDOWN:
if event.key == locals.K_LEFT and fx!= "y":
fx = "z"
st = left
if event.key == locals.K_RIGHT and fx!= "z":
fx = "y"
st = right
if event.key == locals.K_UP and fx!= "x":
fx = "s"
st = up
if event.key == locals.K_DOWN and fx!= "s":
fx = "x"
st = down
if fx=="s":
y = y - 30
elif fx=="x":
y = y + 30
elif fx=="z":
x = x - 30
else:
x = x + 30
# 将背景图画上去
x = x + 30
wz.append((x,y))
wz.pop(0)
screen.blit(background, (0, 0))
# 将贪吃蛇画上去
screen.blit(right, (x, y))
screen.blit(st, (x, y))
# 将贪吃蛇的身体画上去
for i in range(len(wz) - 1):
screen.blit(body,wz[i])
......
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