Commit d2f02fec by BellCodeEditor

save project

parent da3f7b88
Showing with 41 additions and 4 deletions
...@@ -6,15 +6,51 @@ pygame.init() ...@@ -6,15 +6,51 @@ pygame.init()
sab = pygame.image.load('bg.png') sab = pygame.image.load('bg.png')
food = pygame.image.load('apple.png') food = pygame.image.load('apple.png')
right = pygame.image.load('right.png') right = pygame.image.load('right.png')
body = pygame.image.load('body.png')
# 创建一个窗口 # 创建一个窗口
sb=pygame.display.set_mode((660,480)) sb=pygame.display.set_mode((660,480))
FPSCLOCK = pygame.time.Clock()
x, y = 240, 120
lb = [(180,90),(180,120),(210,120),(x,y)]
fx = "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:
if event.key == locals.K_RIGHT and fx != "left":
fx = "right"
if event.key == locals.K_LEFT and fx != "right":
fx = "left"
if event.key == locals.K_UP and fx != "down":
fx = "up"
if event.key == locals.K_DOWN and fx != "up":
fx = "down"
if fx == "right":
x += 30
elif fx == "left":
x -= 30
elif fx == "up":
y -= 30
else:
y += 30
#x += 30
lb.append((x,y))
lb.pop(0)
sb.blit(sab,(0,0)) sb.blit(sab,(0,0))
sb.blit(right, lb[-1])
#sb.blit(right,(x,y))
#sb.blit(sab,(0,0))
sb.blit(food,(120,300)) sb.blit(food,(120,300))
sb.blit(right,(120,330)) #sb.blit(right,(x,y))
pygame.display.update() for i in range(len(lb)-1):
sb.blit(body, lb[i])
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