When a piece is placed at a position, check if this space is placable and place it there.
This commit is contained in:
parent
9aa09f8fbd
commit
4f821b44bc
@ -53,9 +53,20 @@ public class GameUI extends Group{
|
|||||||
_piece.setLayoutX(event.getSceneX() - piece_pos_click.x);
|
_piece.setLayoutX(event.getSceneX() - piece_pos_click.x);
|
||||||
_piece.setLayoutY(event.getSceneY() - piece_pos_click.y);
|
_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);
|
getChildren().add(_piece);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user