So, basically I need to find a good way to “flip” a char array used for a sprite in order to make him/it look to the left and vice versa. Here is my array ->
WARRIOR = (
" " +
"!!!!! " +
"!!oo! ^ " +
"!!!!! ^ " +
"##### ^ " +
"####### " +
"##### " +
"** ** ").toCharArray();
The display routine looks like this:
public void paintComponent(Graphics g) {
super.paintComponent(g);
for (int i = 0; i < WARRIOR.length; i++) {
int x = (i - 1) % 10;
int y = (i - 1) / 10;
if (WARRIOR[i] == '!') {
g.setColor(new Color(0, 0, 204));
g.fillRect(x_pos + x * 5, y_pos + y * 5, 5, 5);
}
else if (WARRIOR[i] == 'o') {
g.setColor(new Color(204, 0, 0));
g.fillRect(x_pos + x * 5, y_pos + y * 5, 5, 5);
}
// other characters here...
}
}
I’d suggest having an alternate display routine to draw sprites backwards instead of storing a reversed copy of the sprite.
Try changing this line:
to this:
This should draw sprites backwards.
Also, you may want to take a look at the XPM format, it is pretty similar to what you are doing.