title: How do I deal with pixels in pygame?
body: <p>While working with sprites in pygame, I eventually realized (due to minimal difference) that one cannot move a sprite by a fraction of a pixel. Albeit being a logical process, I came to the conclusion that equal velocity is unattainable at different angles.</p>
  
  <p>For example: </p>
  
  <pre><code>xmove = 5
  ymove = -5
  </code></pre>
  
  <p>I define the movement increments of the two coordinates of the sprite <code>ball</code> that leaves a platform on the bottom of the screen traveling at a 45° angle. I wish for this direction to change relative to the obstacles that it will encounter.</p>
  
  <p>The following determines the collision of the sprite with the "walls" of the screen:</p>
  
  <pre><code>if ball.rect.left&lt;=0:
      xmove = 5
  elif ball.rect.right&gt;=700:
      xmove = -5  
  elif ball.rect.top&lt;=0:
      ymove = 5
  elif ball.rect.bottom&gt;=400:
      ymove = -5
  </code></pre>
  
  <p>Here is some code to decide what happens after a collision with a <code>player</code> sprite (the platform) is detected:</p>
  
  <pre><code>if pygame.sprite.spritecollide(ball, player_sprite, False):# and ball.rect.bottom&gt;=player.rect.top:
      ymove=-5
      if ball.rect.bottomright [0] in range (player.rect.topleft [0], player.rect.topleft [0] + 15):
          xmove = -5
      elif ball.rect.bottomleft [0] in range (player.rect.topright [0] - 14, player.rect.topright [0] + 1):
          xmove = +5
      elif ball.rect.bottomright [0] in range (player.rect.topleft [0] + 15, player.rect.topleft [0] + 26):
          xmove = -4
          ymove = -5.83
      elif ball.rect.bottomleft [0] in range (player.rect.topright [0] - 26, player.rect.topright [0] - 15):
          xmove = +4
          ymove = -5.83
  </code></pre>
  
  <blockquote>
    <p>The idea here is to have the ball bounce at different angles based on where it hits the platform, all while keeping the same velocity (distance traveled per tick)</p>
  </blockquote>
  
  <p>So the problem here is that to compensate the decrease of one pixel on the x coordinate I use the Pythagorean theorem to output the y coordinate (-5.83). Being that pygame doesn't register fractions of a pixel, this will actually decrease the velocity of the ball significantly.</p>
  
  <p>So my question is, how do I get around this (as I don't want to be limited to 45° angles...)?</p>