基本上,我需要找到一种好的方式来"翻转"用于精灵的字符数组,以便使它看起来向左和向右。这是我的数组->
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...
}
}
x
(倒数而不是正数)。不要存储翻转的精灵,只需在显示时翻转它。 - Dagg Nabbit