Commit 2844fb06 by BellCodeEditor

save project

parent 3cc77de6
Showing with 35 additions and 1 deletions
...@@ -4,19 +4,50 @@ from pygame import locals ...@@ -4,19 +4,50 @@ from pygame import locals
pygame.init() pygame.init()
FPSCLOCK=pygame.time.Clock() FPSCLOCK=pygame.time.Clock()
backgroud=pygame.image.load("bg.png") backgroud=pygame.image.load("bg.png")
right=pygame.image.load("right.png") left=pygame.image.load("left.png")
food=pygame.image.load("apple.png") food=pygame.image.load("apple.png")
up=pygame.image.load("up.png")
right=pygame.image.load("right.png")
down=pygame.image.load("down.png")
body=pygame.image.load("body.png") body=pygame.image.load("body.png")
# 创建一个窗口 # 创建一个窗口
x=240 x=240
y=120 y=120
position=[(180,120),(210,120),(240,120),(x,y)] position=[(180,120),(210,120),(240,120),(x,y)]
screen=pygame.display.set_mode((660,480)) screen=pygame.display.set_mode((660,480))
setheading="right"
snack_head=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()
x+=30 x+=30
if event.type==locals.KEYDOWN:
if event.key==locals.K_RIGHT and setheading !="lesf":
setheading="right"
snack_head=right
if event.key==locals.K_LEFT and setheading !="right":
setheading="left"
snack_head=left
if event.key==locals.K_DOWN and setheading !="up":
setheading="down"
snack_head=down
if event.key==locals.K_UP and setheading !="down":
setheading="up"
snack_head=up
if setheading =="right":
x+=30
if setheading =="left":
x-=30
if setheading =="up":
y-=30
if setheading =="down":
y+=30
position.append((x,y)) position.append((x,y))
position.pop(0) position.pop(0)
screen.blit(backgroud,(0,0)) screen.blit(backgroud,(0,0))
...@@ -25,8 +56,11 @@ while True: ...@@ -25,8 +56,11 @@ while True:
#screen.blit(body,(210,120)) #screen.blit(body,(210,120))
#screen.blit(body,(180,120)) #screen.blit(body,(180,120))
#screen.blit(body,(180,90)) #screen.blit(body,(180,90))
for i in range(len(position)-1): for i in range(len(position)-1):
screen.blit(body,position[i]) screen.blit(body,position[i])
pygame.display.update() pygame.display.update()
......
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