title: Rectangle collision detection system not working
body: <p>I made this rectangle collision system for a simple game I'm working on, but it's not working properly. It only registers a collision when the bottom left pixel of the player collides with the object, and I can't figure out why. Thanks in advance for any help.</p>
  
  <pre><code>public static boolean collision(int playerX, int playerY, int playerWidth, int playerHeight,
          int obstacleX, int obstacleY, int obstacleWidth, int obstacleHeight){
  
      if (coordinateWithinRect(playerX, playerY, obstacleX,
              obstacleY, obstacleWidth, obstacleHeight)) {
          return true;
      } else if (coordinateWithinRect(playerX - playerWidth,
              playerY, obstacleX, obstacleY, obstacleWidth,
              obstacleHeight)) {
          return true;
      } else if (coordinateWithinRect(playerX - playerWidth,
              playerY + playerHeight, obstacleX, obstacleY,
              obstacleWidth, obstacleHeight)) {
          return true;
      } else if (coordinateWithinRect(playerX, playerY
              + playerHeight, obstacleX, obstacleY, obstacleWidth,
              obstacleHeight)) {
          return true;
      } else {
          return false;
      }
  }
  
  
  private static boolean coordinateWithinRect(int xCoord, int yCoord, int xRect, int yRect, int width, int height) {
      if (xCoord &gt; xRect &amp;&amp; xCoord &lt; (xRect + width) &amp;&amp; yCoord &lt; yRect &amp;&amp; yCoord &gt; (yRect - height)) {
          return true;
      } else {
          return false;
      }
  }
  </code></pre>