Yeah, for this one you're going to have to use trigonometry. More specifically, the atan2 function.
So, what you need to do is get the closest enemy, and calculate the angle to it. To do this, do:
1
| double angle = Math.atan2(target.x - this.x, target.y, - this.y); |
That will be in radians, of course, so put a Math.toDegrees(x) around that for degrees.
Now, it'll be easier to do in degrees, so you should convert to that. We have to divide 360 into 8 parts, which is 45. So what you're going to do is something like this
1 2 3 4 5
| if(angle >= 0 && angle < 45) { sprite is this } else if(angle >= 45 && angle < 90) { sprite is that } |
But then again, it all matters on perspective, this way would be useful in basically all possible perspectives, but your game has a bird-eye view, it would be easier to rotate the image.