Commit a744a35a by BellCodeEditor

save project

parent 66c44a15
Showing with 30 additions and 4 deletions
...@@ -8,26 +8,52 @@ pygame.init() ...@@ -8,26 +8,52 @@ pygame.init()
screen = pygame.display.set_mode((660, 480)) screen = pygame.display.set_mode((660, 480))
x,y=240,120 x,y=240,120
b=[(210,120),(180,120),(180,90),(x,y)] b=[(210,120),(180,120),(180,90),(x,y)]
a=pygame.time.Clock() a=pygame.time.Clock()
# 背景 # 背景
background = pygame.image.load('bg.png') background = pygame.image.load('bg.png')
right = pygame.image.load('right.png') right = pygame.image.load('right.png')
down = pygame.image.load('down.png')
left = pygame.image.load('left.png')
up = pygame.image.load('up.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')
s = "right"
sh = 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()
if event.type == locals.KEYDOWN:
x += 30 if event.key == locals.K_RIGHT and s !="left":
s = "right"
sh = right
if event.key == locals.K_LEFT and s !="right":
s = "left"
sh = left
if event.key == locals.K_UP and s !="up":
s = "down"
sh = down
if event.key == locals.K_DOWN and s !="down":
s = "up"
sh = up
#设贪吃蛇
if s =="left":
x-=30
elif s == "right":
x+=30
elif s == "up":
y-=30
else :
y+=30
b.append((x,y)) b.append((x,y))
b.pop(0) b.pop(0)
# 将背景图画上去 # 将背景图画上去
screen.blit(background, (0, 0)) screen.blit(background, (0, 0))
# 将贪吃蛇画上去 # 将贪吃蛇画上去
screen.blit(right, (x, y)) screen.blit(sh, (x, y))
# 将贪吃蛇的身体画上去 # 将贪吃蛇的身体画上去
# screen.blit(body, (210, 120)) # screen.blit(body, (210, 120))
# screen.blit(body, (180, 120)) # screen.blit(body, (180, 120))
......
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