Commit 8b3d8401 by BellCodeEditor

save project

parent 11569440
Showing with 35 additions and 4 deletions
...@@ -9,14 +9,44 @@ body = pygame.image.load('body.png') ...@@ -9,14 +9,44 @@ body = pygame.image.load('body.png')
right = pygame.image.load('right.png') right = pygame.image.load('right.png')
# 创apple.png = pygame.image.load('bg.png')建一个窗口 # 创apple.png = pygame.image.load('bg.png')建一个窗口
screen=pygame.display.set_mode((660,480)) screen=pygame.display.set_mode((660,480))
x,y=150,60
position= [(180,120),(150,120),(150,90),(x,y)]
setheading = "left"
FPSCLOCK=pygame.time.Clock()
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:
if event.key ==locals.K_RIGHT and setheading !="left":
setheading = 'right'
if event.key ==locals.K_LEFT and setheading !="right":
setheading = 'left'
if event.key ==locals.K_UP and setheading !="down":
setheading = 'up'
if event.key ==locals.K_DOWN and setheading !="up":
setheading = 'down'
if setheading == "right":
x +=30
elif setheading == "left":
x +=30
elif setheading == "up":
y +=30
else:
y +=30
position.append((x,y))
position.pop(0)
screen.blit(background,(0,0)) screen.blit(background,(0,0))
screen.blit(apple,(240,120)) screen.blit(apple,(240,120))
screen.blit(right,(210,120)) screen.blit(right,(x,y))
screen.blit(body,(180,120)) #screen.blit(body,(180,120))
screen.blit(body,(150,120)) # screen.blit(body,(150,120))
screen.blit(body,(150,90)) # screen.blit(body,(150,90))
for i in range(len(position)-1):
screen.blit(body,position[i])
pygame.display.update() pygame.display.update()
FPSCLOCK.tick(3)
\ 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