Allow clicking on empty space to pick the piece (#3)

This commit is contained in:
Lonami Exo 2017-02-10 13:59:25 +01:00
parent 2dea9274cf
commit 0fb83b69c3
2 changed files with 10 additions and 4 deletions

View file

@ -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[][];

View file

@ -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;
}
}
}