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 Vector2 pos;
|
||||||
final int colorIndex;
|
final int colorIndex;
|
||||||
final int rotation;
|
private final int rotation;
|
||||||
|
|
||||||
final int cellCols, cellRows;
|
final int cellCols, cellRows;
|
||||||
private boolean shape[][];
|
private boolean shape[][];
|
||||||
|
|
|
@ -141,12 +141,18 @@ public class PieceHolder implements BinSerializable {
|
||||||
Gdx.input.getX(),
|
Gdx.input.getX(),
|
||||||
Gdx.graphics.getHeight() - Gdx.input.getY()); // Y axis is inverted
|
Gdx.graphics.getHeight() - Gdx.input.getY()); // Y axis is inverted
|
||||||
|
|
||||||
|
final float perPieceWidth = area.width / count;
|
||||||
for (int i = 0; i < count; ++i) {
|
for (int i = 0; i < count; ++i) {
|
||||||
if (pieces[i] != null && pieces[i].getRectangle().contains(mouse)) {
|
if (pieces[i] != null) {
|
||||||
|
Rectangle maxPieceArea = new Rectangle(
|
||||||
|
area.x + i * perPieceWidth, area.y, perPieceWidth, area.height);
|
||||||
|
|
||||||
|
if (maxPieceArea.contains(mouse)) {
|
||||||
heldPiece = i;
|
heldPiece = i;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
heldPiece = -1;
|
heldPiece = -1;
|
||||||
return false;
|
return false;
|
||||||
|
|
Loading…
Reference in a new issue