I am coding a snake on pygame. The user can move it freely (not like the original snake). The problem is that when the user is holding down a key, let's say : DOWN. He then presses LEFT to go diagonal down-left, finally releases LEFT while still holding DOWN : the snake is supposed to go down but he stops moving.
I have printed key events and it is detected, but it is not looping anymore like it is when I am holding a single key.
Here is my event loop :
running = True
pygame.key.set_repeat(True)
while running:
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
if event.type == pygame.KEYUP:
snake.direction = None
keys = pygame.key.get_pressed()
print(keys[pygame.K_DOWN],keys[pygame.K_RIGHT])
if keys:
snake.mise_a_jour_position(keys)
grid.mise_a_jour_grille()
screen.blit(background, (0, 0))
grid.draw()
snake.draw()
pygame.display.update()