Allow clicking on empty space to pick the piece (#3)
This commit is contained in:
parent
2dea9274cf
commit
0fb83b69c3
2 changed files with 10 additions and 4 deletions
|
@ -21,7 +21,7 @@ public class Piece {
|
|||
|
||||
final Vector2 pos;
|
||||
final int colorIndex;
|
||||
final int rotation;
|
||||
private final int rotation;
|
||||
|
||||
final int cellCols, cellRows;
|
||||
private boolean shape[][];
|
||||
|
|
|
@ -141,10 +141,16 @@ public class PieceHolder implements BinSerializable {
|
|||
Gdx.input.getX(),
|
||||
Gdx.graphics.getHeight() - Gdx.input.getY()); // Y axis is inverted
|
||||
|
||||
final float perPieceWidth = area.width / count;
|
||||
for (int i = 0; i < count; ++i) {
|
||||
if (pieces[i] != null && pieces[i].getRectangle().contains(mouse)) {
|
||||
heldPiece = i;
|
||||
return true;
|
||||
if (pieces[i] != null) {
|
||||
Rectangle maxPieceArea = new Rectangle(
|
||||
area.x + i * perPieceWidth, area.y, perPieceWidth, area.height);
|
||||
|
||||
if (maxPieceArea.contains(mouse)) {
|
||||
heldPiece = i;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue