title: Python rectangle collision handling with pygame
body: <p>I've been doing extensive research on this topic for the past few days and I can't seem to find an answer for my exact problem.</p>
  
  <p>So, I have a simple game set up where I have the player at 0, 0 with a width of 10x10</p>
  
  <pre><code>    player= pygame.Rect(0, 0, 10, 10)
  </code></pre>
  
  <p>and aside from that, the player has a velocity of x: 0, y: 10, which will make him fall (y is positive because the origin of the screen is at the top left.)</p>
  
  <p>and I have a tile at 0, 100, as shown:</p>
  
  <pre><code>    dirt= pygame.Rect(0, 100, 10, 10)
  </code></pre>
  
  <p>so, how can I <em>handle</em> collision, I already know I can detect it with Rect.colliderect(Rect).</p>
  
  <p>I've tried a few ways, but encountered some problems:</p>
  
  <p>I can't cut the player's velocity to 0 when he hits something and then move him 
  back until he's just touching the object because that still causes the problem of walking, when he walks, I apply +10 velocity on x, but unfortunately, the game still processes that he is falling and colliding <em>and</em> moving sideways, so it just moves him back to where he started.</p>
  
  <p>I'm a beginner, so a simple answer would be appreciated, and I would <em>like</em> to not have to use <em>any</em> third party modules other that pygame if I didn't have to.</p>
  
  <p><strong>Update:</strong></p>
  
  <p>Here is some of the rough test code I have tried:</p>
  
  <pre><code>    def sim(obj, time, world):
          time= time / 1000
          obj.physProp['vel']= (obj.physProp['vel'][0] + (accel[0] * time), obj.physProp['vel'][1] + (accel[1] * time))
          if obj.physProp['vel'][1] &gt; terminalY:
              obj.physProp['vel']= (obj.physProp['vel'][0], terminalY)
          obj.pos= (obj.pos[0] + (obj.physProp['vel'][0] * time) + ((accel[0] / 2) * (time ** 2)), obj.pos[1] + (obj.physProp['vel'][1] * time) + ((accel[1] / 2) * (time ** 2)))
  
          for ID in world:
              if obj.getRect().colliderect(world[ID].getRect()) == True:
                  pass
  
          return (obj.pos, obj.physProp['vel'])
  </code></pre>