Commit 445e822d by BellCodeEditor

save project

parent 1103e0fb
Showing with 28 additions and 3 deletions
......@@ -8,24 +8,49 @@ screen = pygame.display.set_mode((660,480))
food = pygame.image.load("apple.png")
background = pygame.image.load("bg.png")
right = pygame.image.load("right.png")
left = pygame.image.load("left.png")
up = pygame.image.load("up.png")
down = pygame.image.load("down.png")
body=pygame.image.load("body.png")
x,y=210,120
l=[(210,120),(180,120),(180,90),(x,y)]
settheading="right"
snake_head=right
while True:
x+=30
for event in pygame.event.get():
if event.type == locals.QUIT:
exit()
if event.type==locals.KEYDOWN:
if event.key==locals.K_RIGHT and settheading!="left":
settheading="right"
snake_head=right
if event.key==locals.K_LEFT and settheading!="right":
settheading="left"
snake_head=left
if event.key==locals.K_UP and settheading!="down":
settheading="up"
snake_head=up
if event.key==locals.K_DOWN and settheading!="up":
settheading="down"
snake_head=down
if settheading=="right":
x+=30
elif settheading=="left":
x-=30
elif settheading=="down":
y+=30
else:
y-=30
l.append((x,y))
l.pop(0)
screen.blit(background,(0,0))
for i in range(len(l)-1):
screen.blit(body,l[i])
screen.blit(food,(360,300))
screen.blit(right,(x,y))
screen.blit(snake_head,(x,y))
pygame.display.update()
a=pygame.time.Clock()
a.tick(3)
a.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