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 screenshot the pattern
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);
is show relative to a temporary enemy(the yellow box) aiming "up".
I currently have simple code to rotate a pattern array by 90 degree increments, as seen here. 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.
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).
private Point2d[] rotateList(Point2d[] points, int direction) {
for (int i = 0; i < 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;
}