0

I want to press 'q' and the ship keep rotating to the left until i press 'e', how can i do this?

class Player(pygame.sprite.Sprite):
    def __init__(self, *groups):
        super().__init__(*groups)
        self.image = pygame.image.load('spaceship.png')
        self.image = pygame.transform.scale(self.image, [50, 50])
        self.rect = pygame.Rect(960, 540, 50, 50)
        self.PlayerPos = self.image.get_rect()
        self.speed = 0
        self.acceleration = 0.2

    def update(self, *args):
        keys = pygame.key.get_pressed()

        if keys[pygame.K_w]:
            self.speed -= self.acceleration

        if keys[pygame.K_q]:
            pass
        if keys[pygame.K_e]:
            pass

        self.rect.top += self.speed
  • I'm not sure on the actual rotation part, for which you can hopefully use the previous comment, but I would suggest defining a class variable in `__init__` called `self.rotating_left` as false and update it to true when q is pressed or false when e is pressed. Then in `update` add code to rotate the sprite if it is true. – Lecdi Aug 31 '21 at 18:01

0 Answers0