所以,基本上我需要找到一种“翻转”用于精灵的字符数组的好方法,以使他/它看起来向左,反之亦然。这是我的数组->
WARRIOR = (
" " +
"!!!!! " +
"!!oo! ^ " +
"!!!!! ^ " +
"##### ^ " +
"####### " +
"##### " +
"** ** ").toCharArray();
显示例程如下所示:
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...
}
}