Girando objetos em uma grade (GUI, JAVA SWING)
Ok, então estou tentando fazer este tutorial:http://mathcs.slu.edu/~fritts/cse131/labs/lab9/index.html
Mas eu não sei girar objetos
synchronized void moveDown() {
}
Existe algum método definido para isso ou eu tenho que implementar o meu próprio código? Eu pensei em mudar a forma do objeto, mas isso implicaria que eu tenho que mudar meu objeto atual o tempo todo, o que pode ser um pouco complicado de implementar.
O método que chama moveDown:
public void keyPressed(KeyEvent event) {
int key = event.getKeyCode();
switch (key) {
case KeyEvent.VK_UP: // up arrow
case KeyEvent.VK_KP_UP:
currentPiece.rotateCounterclockwise();
break;
case KeyEvent.VK_DOWN: // down arrow
case KeyEvent.VK_KP_DOWN:
currentPiece.rotateClockwise();
break;
case KeyEvent.VK_LEFT: // left arrow
case KeyEvent.VK_KP_LEFT:
currentPiece.moveLeft();
break;
case KeyEvent.VK_RIGHT: // right arrow
case KeyEvent.VK_KP_RIGHT:
currentPiece.moveRight();
break;
case KeyEvent.VK_SPACE: // space bar
currentPiece.drop();
}
}
Eu estava prestes a adicionar L1a, L1b, L1c, etc. Não tem outro jeito?
public static final int[][] L1 =
{{1,1},
{0,1},
{0,1}
};
public static final int[][] L2 =
{{0,1},
{0,1},
{1,1}
};
public static final int[][] T =
{{0,1},
{1,1},
{0,1}
};
public static final int[][] BOX =
{{1,1},
{1,1}
};
public static final int[][] BAR =
{{1,1,1,1}
};
public static final int[][] STEP1 =
{{1,0},
{1,1},
{0,1}
};
public static final int[][] STEP2 =
{{0,1},
{1,1},
{1,0}
};