Commit 6ea3502a by BellCodeEditor

save project

parent 42da5f30
Showing with 18 additions and 6 deletions
...@@ -21,20 +21,32 @@ while True: ...@@ -21,20 +21,32 @@ 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.key == locals.K_UP and setheading != "up": if event.type == locals.KEYDOWN:
if event.key == locals.K_UP and setheading != "down":
setheading = "up" setheading = "up"
if event.key == locals.K_DOWN and setheading != "down": snake_head = up
if event.key == locals.K_DOWN and setheading != "up":
setheading = "down" setheading = "down"
if event.key == locals.K_LEFT and setheading != "left": snake_head = down
if event.key == locals.K_LEFT and setheading != "right":
setheading = "left" setheading = "left"
if event.key == locals.K_RIGHT and setheading != "right": snake_head = left
if event.key == locals.K_RIGHT and setheading != "left":
setheading = "right" setheading = "right"
snake_head = right
if snake_head == up:
y-=30
elif snake_head == down:
y+=30
elif snake_head == left:
x-=30
elif snake_head ==right:
x+=30 x+=30
poisttion.append((x,y)) poisttion.append((x,y))
poisttion.pop(0) poisttion.pop(0)
screen.blit(background, (0, 0)) screen.blit(background, (0, 0))
screen.blit(right, poisttion[-1]) screen.blit(snake_head, poisttion[-1])
for i in range(len(poisttion)-1): for i in range(len(poisttion)-1):
screen.blit(body, (poisttion[i])) screen.blit(body, (poisttion[i]))
......
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