title: c++ player-wall collision with SFML
body: <p>My friend and I are developing a top down puzzle game.<br>
  We have already implemented a player class that can walk and collide the walls, but the problem is after the collision itself.  </p>
  
  <p><strong>For example:</strong><br>
  When the player hits a wall to its right, we set the velocity on the <strong><code>x</code></strong> axis to be <strong>0</strong>, and the player stops. But after that, if the user presses the <kbd>up</kbd> key, the player moves one pixel up, and then stops again.<br>
  After that if you keep pressing right and up alternately, the player is walking through the wall pixel after pixel.</p>
  
  <p><a href="https://i.stack.imgur.com/WVO9E.gif" rel="nofollow noreferrer">The player moves through the wall</a></p>
  
  <p>And here is the collision detection of the player:</p>
  
  <pre><code>for (int i = 0; i &lt; lvl.getSizeInTiles().x; i++) {
          for (int j = 0; j &lt; lvl.getSizeInTiles().y; j++) {
              if (lvl.getTileFromBuffer(i, j).getType() == "wall") {
                  if (intersects(lvl.getTileFromBuffer(i, j).getPosition().x, lvl.getTileFromBuffer(i, j).getPosition().y, lvl.getTileFromBuffer(i, j).getSize().x, lvl.getTileFromBuffer(i, j).getSize().y)) {
                      if (faceDirection == "UP" &amp;&amp; vel.y &lt; 0) {
                          collidesUp = true;
                      }
                      else {
                          collidesUp = false;
                      }
  
                      if (faceDirection == "DOWN" &amp;&amp; vel.y &gt; 0) {
                          collidesDown = true;
                      }
                      else {
                          collidesDown = false;
                      }
  
                      if (faceDirection == "LEFT" &amp;&amp; vel.x &lt; 0) {
                          collidesLeft = true;
                      }
                      else {
                          collidesLeft = false;
                      }
  
                      if (faceDirection == "RIGHT" &amp;&amp; vel.x &gt; 0) {
                          collidesRight = true;
                      }
                      else {
                          collidesRight = false;
                      }
                  }
              }
          }
      }
  }
  if (vel.x &gt; 0 &amp;&amp; !collidesRight) {
      pos.x += vel.x;
  }
  if (vel.x &lt; 0 &amp;&amp; !collidesLeft) {
      pos.x += vel.x;
  }
  if (vel.y &gt; 0 &amp;&amp; !collidesDown) {
      pos.y += vel.y;
  }
  if (vel.y &lt; 0 &amp;&amp; !collidesUp) {
      pos.y += vel.y;
  }
  </code></pre>
  
  <p><strong>Just a quick note:</strong> The <strong><code>intersect(x, y, w, h)</code></strong> function is a part of the player class, and tell us if you need to see it.</p>
  
  <p>We will be happy if you send a reply about our code, or link us to a place we can find a solution.</p>
  
  <p>So thank you for any help, and please ask questions if you need to, Arad and Ron.  </p>