title: My sprites get stuck on the edge of the screen using a C++ framework called ASGE
body: <p>I am using a custom game engine created by one of my lecturers. </p>
  
  <p>I have 4 inputs that the user can have for a pong game. These inputs work as intended however as soon as the sprite (paddle for pong) touches either the top or the bottom they get stuck there and are unable to move. Adding an else statement saying <code>w_keypress = false;</code> doesn't work.</p>
  
  <pre><code>if (w_keypress)
  {
     if (player_one-&gt;yPos() &gt;= 0 &amp;&amp; player_one-&gt;yPos() + player_one-&gt;height() &lt;= game_height)
     {
        yspeed_player_one = -500;
        s_keypress = false;
        y_pos_player_one += yspeed_player_one * (game_time.delta.count() / 1000.f);
        player_one-&gt;yPos(y_pos_player_one);
  
        std::cout &lt;&lt; "keypress w" &lt;&lt; std::endl;
     }
  }
  </code></pre>
  
  <p>EDIT: The problem can easily be fixed by setting the y value to a y value that doesn't make the sprite interfere with the top or the bottom of the screen. </p>
  
  <p>e.g.</p>
  
  <pre><code>if (player_one-yPos() &gt; game_height)
  {
      player_one-&gt;yPos(game_height - (player_one-&gt;height() / 2)
  }
  else if (player_one-&gt;yPos() &lt; 0)
  {
      player_one-&gt;yPos(0 + (player_one-&gt;height() / 2)
  }
  </code></pre>
  
  <p>This code detects if the player has gone off the top or the bottom of the screen and then moves the player half of its height down or up depending on which y value you are.</p>