title: Is it possible to get the location of a sprite at an INSTANT?
body: <p>So I am working on a PacMan game, and I have my code set up so that if you hit the left key, it will 'remember' that and wait until the player is at a place where there are no walls, allowing it to move left. That way the player doesn't have to time their key hits precisely with where wall openings are. My issue is that when I hit left for instance, it plays the left moving animation, even though the player doesn't move in that direction until there is an opening in the wall. </p>
  
  <p>In my code, I am trying to make it so it only plays the left animation when the player is moving left. The way I am trying to do this, is get the position of the player at an instant, and later test to see if the player is now to the left of that, meaning it has successfully made the turn and should now play the left animation. Here is my basic thinking in code:</p>
  
  <pre><code>class Player (pygame.sprite.Sprite):
  
      def __init__(self, game, x, y):
          self.groups = game.all_sprites
  
          pygame.sprite.Sprite.__init__(self, self.groups)
  
          self.game = game
          self.image = sprite_sheet('pacman-spritesheet.png').get_image(0, 0, 24, 24)
  
          self.x = x * TILESIZE
          self.y = y * TILESIZE
  
  
          self.rect = self.image.get_rect()
  
          self.vx, self.vy = 0, 0
  
          self.spritesheet_index = 0
  
          self.first_time = pygame.time.get_ticks()
          self.delay = 43
  
  
          self.input_list = ['--']
  
          self.direction = ''
  
          self.POINTS = 0
  
  
  
      def get_keys(self):
  
  
  
          keys = pygame.key.get_pressed()
  
  
          if keys[pygame.K_LEFT]:
  
              self.input_list.append('left')
  
          if keys[pygame.K_RIGHT]:
  
              self.input_list.append('right')
  
          if keys[pygame.K_UP]:
  
              self.input_list.append('up')
  
          if keys[pygame.K_DOWN]:
  
              self.input_list.append('down')
  
  
  
      def last_direction(self):
          return self.input_list[len(self.input_list) - 1]
  
  
  
      def animate(self):
          self.spritesheet_index += 1
  
  
  
          if self.last_direction() == 'left':
              self.second_time = pygame.time.get_ticks()
  
              if self.second_time-self.first_time &gt; self.delay and self.first_x &lt; self.second_x:
                  self.image = PAC_LEFT[self.spritesheet_index % 4]
                  self.first_time = pygame.time.get_ticks()
  
  
          if self.last_direction() == 'right':
              self.second_time = pygame.time.get_ticks()
  
              if self.second_time - self.first_time &lt; self.delay:
                  self.image = PAC_RIGHT[self.spritesheet_index % 4]
                  self.first_time = pygame.time.get_ticks()
  
          if self.last_direction() == 'up':
              self.second_time = pygame.time.get_ticks()
  
              if self.second_time - self.first_time &gt; self.delay:
                  self.image = PAC_UP[self.spritesheet_index % 4]
                  self.first_time = pygame.time.get_ticks()
  
          if self.last_direction() == 'down':
              self.second_time = pygame.time.get_ticks()
  
              if self.second_time - self.first_time &gt; self.delay:
                  self.image = PAC_DOWN[self.spritesheet_index % 4]
                  self.first_time = pygame.time.get_ticks()
  
  
  
      def set_velocity(self):
          if self.last_direction() == 'left':
              self.vx = -PLAYER_SPEED
  
          if self.last_direction() == 'right':
              self.vx = PLAYER_SPEED
  
          if self.last_direction() == 'up':
              self.vy = -PLAYER_SPEED
  
          if self.last_direction() == 'down':
              self.vy = PLAYER_SPEED
  
  
      def move(self):
          self.x += self.vx
          self.y += self.vy
  
  
  
      def update(self):
          self.first_x = self.x
  
          self.get_keys()
  
          self.set_velocity()
          self.move()
  
          self.second_x = self.x
  
          self.animate()
  
          self.rect.x = self.x
          self.collide_with_wall('x')
  
          self.rect.y = self.y
          self.collide_with_wall('y')
  
  
          self.collide_with_point()
  </code></pre>