Commit a0a25e43 by BellCodeEditor

save project

parent e1b1eefe
Showing with 29 additions and 3 deletions
......@@ -7,6 +7,11 @@ background = pygame.image.load('bg.png')
right = pygame.image.load('right.png')
apple = pygame.image.load('apple.png')
body = pygame.image.load('body.png')
up = pygame.image.load('up.png')
left = pygame.image.load('left.png')
down = pygame.image.load('down.png')
setheading = "right"
snake_head = right
# 创建一个窗口
x, y = 240, 120
pos = [(180,90),(180,120),(210,120),(x,y)]
......@@ -15,11 +20,32 @@ while True:
print(event)
if event.type == locals.QUIT:
exit()
if event.type == locals.KEYDOWN:
if event.key == locals.K_UP and setheading != "down":
setheading = "up"
snake_head = up
elif event.key == locals.K_DOWN and setheading != "up":
setheading = "down"
snake_head = down
elif event.key == locals.K_LEFT and setheading != "right":
setheading = "left"
snake_head = left
else:
setheading = "right"
snake_head = right
if setheading == "right":
x += 30
if setheading == "left":
x -= 30
if setheading == "down":
y += 30
if setheading == "up":
y -= 30
screen.blit(background,(0,0))
x+=30
pos.append((x,y))
pos.pop(0)
screen.blit(right,pos[-1])
screen.blit(snake_head,pos[-1])
for i in range(len(pos)-1):
screen.blit(body,(pos[i]))
# screen.blit(body,(150,120))
......@@ -29,4 +55,4 @@ while True:
screen.blit(apple,(120,300))
pygame.display.update()
aaz = pygame.time.Clock()
aaz.tick(3)
aaz.tick(10)
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