Commit 020b87bb by BellCodeEditor

save project

parent 92f8d717
Showing with 37 additions and 6 deletions
......@@ -6,27 +6,58 @@ pygame.init()
# 创建一个窗口
screen = pygame.display.set_mode((660, 480))
x,y=120,120
jishiqi=pygame.time.Clock()
snake=[(60, 90),(60, 120),(90, 120),(x,y)]
# 背景
background = pygame.image.load('bg.png')
right = pygame.image.load('right.png')
food = pygame.image.load('apple.png')
body = pygame.image.load('body.png')
x,y=120,120
up=pygame.image.load('up.png')
down=pygame.image.load('down.png')
left=pygame.image.load('left.png')
fangxiang="right"
tou= right
while True:
for event in pygame.event.get():
if event.type == locals.QUIT:
# 接收到退出事件后退出程序
exit()
x+=30
if event.type == locals.KEYDOWN:
if event.key == locals.K_RIGHT and fangxiang !="left":
fangxiang = "right"
tou=right
if event.key == locals.K_LEFT and fangxiang !="right":
fangxiang = "left"
tou=left
if event.key == locals.K_DOWN and fangxiang !="up":
fangxiang = "down"
tou=down
if event.key == locals.K_UP and fangxiang !="down":
fangxiang = "up"
tou=up
if fangxiang=="right":
x+=30
elif fangxiang=="left":
x-=30
elif fangxiang=="up":
y-=30
else:
y+=30
snake.append((x,y))
snake.pop(0)
# 将背景图画上去
screen.blit(background, (0, 0))
# 将贪吃蛇画上去
screen.blit(right, (x,y))
screen.blit(tou, (x,y))
for i in range(len(snake)-1):
screen.blit(body,snake[i])
# 将贪吃蛇的身体画上去
screen.blit(body, (90, 120))
screen.blit(body, (60, 120))
screen.blit(body, (60, 90))
# screen.blit(body, (90, 120))
# screen.blit(body, (60, 120))
# screen.blit(body, (60, 90))
# 将果实画上去
screen.blit(food, (360, 300))
# 刷新画面
......
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