0

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()
Mrofsnart
  • 89
  • 6
  • 1
    `pygame.key.get_pressed()` is not an event. Call it in the application loop instead of the event loop. – Rabbid76 Dec 21 '22 at 14:01

0 Answers0