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

View file

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