title: What is the simplest way to rotate a pygame sprite on holding a button?
body: <p>I currently have a racecar game in development, using Pygame. I understand that in order to get the sprite to move the way a real car does, trigonometry is required. However, for now, I am simply trying to get the racecar image to rotate as the user holds a button. What is the simplest way to do so?</p>
  
  <pre><code>import pygame
  pygame.init()
  
  #DEFING COLOURS
  BLACK = ( 0, 0, 0)
  WHITE = ( 255, 255, 255)
  BLUE = (0, 0, 255)
  GREEN = ( 0, 255, 0)
  RED = (255, 0, 0)
  
  size = (800,600)
  screen = pygame.display.set_mode(size)
  pygame.display.set_caption("My First Game")
  
  class Car(pygame.sprite.Sprite):
      #BASE CAR CLASS
  
      def __init__(self, filename):
          #INITIALISE OBJECT PROPERTIES
          super().__init__()
  
          #LOAD IMAGE
          self.image = pygame.image.load(filename).convert_alpha()
  
          #SET BACKGROUND COLOUR
          #self.image.set_colorkey(WHITE)
  
          #SET RECTANGLE COLLISION BOX
          self.rect = self.image.get_rect()
  
          self.angle = 0
          self.angle_change = 0
  
  #Create sprites list
  all_sprites_list = pygame.sprite.Group()
  
  #Create F1car object
  F1car = Car("car.png")
  car_rotation = 0.0
  surface = pygame.Surface((15, 15))
  
  #Add F1car to sprites list
  all_sprites_list.add(F1car)
  
  #LOOP UNTIL USER EXITS THE GAME
  carryOn = True
  
  #CLOCK TO CONTROL FRAME RATE
  clock = pygame.time.Clock()
  
  ##MAIN LOOP##
  while carryOn:
      #MAIN EVENT LOOP
      for event in pygame.event.get(): #USER DID SOMETHING
          if event.type == pygame.QUIT: #IF USER CLICKED CLOSE
              carryOn = False #END THE LOOP
          if event.type == pygame.KEYDOWN:
              if event.key == pygame.K_RIGHT:
                  car_rotation += 0.1
                  pygame.transform.rotate(surface, car_rotation)
  
      #GAME LOGIC
  
      #DRAWING CODE
  
      #CLEARING SCREEN
      screen.fill(WHITE)
  
      #DRAWING SHAPES
      pygame.draw.rect(screen, RED, [55, 200, 100, 70], 0)
      pygame.draw.rect(screen, BLUE, [78, 300, 60, 70], 0)
  
      #LIST OF SPRITES TO COLLIDE WITH EACHOTHER
      #blocks_hit_list = pygame.sprite.spritecollide(F1car, )
  
      #DRAW SPRITES FROM all_sprites_list LIST
      all_sprites_list.draw(screen)
  
      #UPDATE THE SCREEN
      pygame.display.flip()
  
      #SET UPDATE RATE
      clock.tick(60)
  
  pygame.quit()
  </code></pre>