title: j2me - Rotate array of 2d points in 45 degree increments
body: <p>I'm working on a roguelike style cellphone game that operates on a grid. Attacks/Items in this game operate by targeting tiles in a pattern relative to the user. The paturn is usually relative to the direction the user is aiming in as well,  For instance in this <a href="http://arlenphillips.googlepages.com/Shotgun.PNG" rel="nofollow noreferrer">screenshot</a> the pattern            </p>
  
  <pre><code>Point2d[] damageTiles = new Point2d[4];
  
  damageTiles[0] = new Point2d(0, -1);
  damageTiles[1] = new Point2d(0, -2);
  damageTiles[2] = new Point2d(1, -2);
  damageTiles[3] = new Point2d(-1, -2);
  </code></pre>
  
  <p>is show relative to a temporary enemy(the yellow box) aiming "up".</p>
  
  <p>I currently have simple code to rotate a pattern array by 90 degree increments, as seen <a href="http://arlenphillips.googlepages.com/screenshot.2.png" rel="nofollow noreferrer">here</a>. My question is, Is there an easy way to rotate an array of 2d points by 45 degree increments, allowing my Attacks/Items to fire on the diagonal, preferably without using floating point math, as it tends to run slowly on many phones(or so i hear). This is probably a trivial question to anyone familiar with graphics programming, but I've been hit with a case of coder's-block. </p>
  
  <p>My current rotation code is shown below. I now realize that a better way to do it would be to take an angle instead of a "direction" and rotate the points by that angle (rejecting angles that are not multiples of 45 of course).</p>
  
  <pre><code>private Point2d[] rotateList(Point2d[] points, int direction) {
      for (int i = 0; i &lt; points.length; i++) {
  
          if (direction == ROTATE_LEFT) {
              int temp = points[i].x;
              points[i].x = points[i].y;
              points[i].y = -1 * temp;
          }
          else if (direction == ROTATE_RIGHT) {
              int temp = points[i].x;
              points[i].x = -1 * points[i].y;
              points[i].y = temp;
          }
  
      }
  
      return points;
  }
  </code></pre>