When a piece is placed at a position, check if this space is placable and place it there.
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/pr Build is passing

This commit is contained in:
Debucquoy Anthony 2023-05-10 22:59:43 +02:00
parent 9aa09f8fbd
commit 4f821b44bc
Signed by: tonitch
GPG Key ID: A78D6421F083D42E

View File

@ -53,9 +53,20 @@ public class GameUI extends Group{
_piece.setLayoutX(event.getSceneX() - piece_pos_click.x);
_piece.setLayoutY(event.getSceneY() - piece_pos_click.y);
});
_piece.setOnMouseReleased(event -> {
if(event.getSceneX() > grid.getLayoutX() && event.getSceneX() < grid.getLayoutX() + grid.boundary_size.x
&& event.getSceneY() > grid.getLayoutY() && event.getSceneY() < grid.getLayoutY() + grid.boundary_size.y )
{
// Inverted because screen is x ; y and matrix is x ; y
Vec2 piece_position_in_grid = new Vec2(
(int) (_piece.getLayoutY() + (SEGMENT_SIZE+SPACE_SIZE)/2 - grid.getLayoutY())/(SEGMENT_SIZE+SPACE_SIZE),
(int) (_piece.getLayoutX() + (SEGMENT_SIZE+SPACE_SIZE)/2 - grid.getLayoutX())/(SEGMENT_SIZE+SPACE_SIZE)
);
System.out.println(level.placePiece(p, piece_position_in_grid) + piece_position_in_grid.toString());
}
});
getChildren().add(_piece);
}
}
}
}