We're sorry but this app doesn't work properly without JavaScript enabled. Please enable it to continue.

This lesson's interactive features are locked, please to keep using them

Moving Around

We want the spaceship to be able to move; but what does that mean specifically? Let's break it down:

  1. If we press the move-left key, the ship should rotate to the left (i.e., counter-clockwise).
  2. If we press the move-right key, the ship should rotate to the right (i.e., clockwise).
  3. If we press the move-forward key, the ship should move forward.
  4. If we press the move-backward key, the ship should move backward.

Left and right seem pretty similar. Let's try to write a small function to tackle those first!

Assignment

  1.     def update(self, dt: float) -> None:
            keys = pygame.key.get_pressed()
    
            if keys[pygame.K_a]:
                # ?
            if keys[pygame.K_d]:
                # ?
    

    If you're using a non-QWERTY keyboard, you may want to change the keybindings in the code to something other than the W, A, S and D keys.

If everything seems to be working, run and submit the CLI tests.