title: Java collision detection for rotated rectangles?
body: <p>I am writing my first java game and so far:</p>
  
  <p>I've made a rectangle that can walk around with WSAD, and he always faces where the mouse is pointing. Also if you click, he shoots bullets where your mouse is pointing (and the bullets rotate to face that direction). I've also made enemies which follow you around, and they rotate to face towards your character. The problem i am having is that the collision detection I've written is only detecting the collision of the objects (character, enemies and bullets) before their rotation (using .intersects()). This means that some parts of their bodies overlap when drawn.</p>
  
  <p>I've been looking around, and I haven't found any solutions that I understand or can apply to my situation. I've been rotating my Graphics2D grid for each of the objects so far, so they are not actually being rotated, just drawn out to be. Is there a way I can actually rotate their shapes and then use something like .intersects() ?</p>
  
  <p>Any help or suggestions are appreciated.</p>
  
  <p>Here is what I use to see if it will collide by moving on the x axis:</p>
  
  <pre><code>public boolean detectCollisionX(int id, double xMove, double rectXco, double rectYco, int width, int height)
  {
      boolean valid=true;
      //create the shape of the object that is moving.
      Rectangle enemyRectangleX=new Rectangle((int)(rectXco+xMove)-enemySpacing,(int)rectYco-enemySpacing,width+enemySpacing*2,height+enemySpacing*2);
      if (rectXco+xMove&lt;0 || rectXco+xMove&gt;(areaWidth-width))
      {
          valid=false;
      }
      if(enemyNumber&gt;0)
      {
          for (int x=0; x&lt;=enemyNumber; x++)
          {
              if (x!=id)
              {
                  //enemies and other collidable objects will be stored in collisionObjects[x] as rectangles.
                  if (enemyRectangleX.intersects(collisionObjects[x])==true)
                  {
                      valid=false;
                  }
              }
          }
      }
      return valid;
  }
  </code></pre>