make white space on detached pieces
This commit is contained in:
parent
f0e1f8a56b
commit
11e831d2a4
@ -22,9 +22,22 @@ public class GameUI extends Group{
|
|||||||
|
|
||||||
getChildren().add(grid);
|
getChildren().add(grid);
|
||||||
|
|
||||||
|
Vec2 piece_space = new Vec2(SPACE_SIZE, SPACE_SIZE);
|
||||||
|
int column = 0;
|
||||||
for (Piece p : level.getPieces()) {
|
for (Piece p : level.getPieces()) {
|
||||||
MatrixShape _piece = new MatrixShape(p);
|
MatrixShape _piece = new MatrixShape(p);
|
||||||
|
|
||||||
|
_piece.setLayoutX(piece_space.x);
|
||||||
|
_piece.setLayoutY(piece_space.y);
|
||||||
|
|
||||||
|
piece_space.y += _piece.boundary_size.y;
|
||||||
|
|
||||||
|
if(piece_space.y >= Controller.screen_size.y){
|
||||||
|
column++;
|
||||||
|
piece_space.y = SPACE_SIZE;
|
||||||
|
piece_space.x = (SEGMENT_SIZE*3 + SPACE_SIZE*4 )* column;
|
||||||
|
}
|
||||||
|
|
||||||
// Pieces Events
|
// Pieces Events
|
||||||
_piece.setOnMouseClicked(event -> {
|
_piece.setOnMouseClicked(event -> {
|
||||||
if(event.getButton() == MouseButton.SECONDARY){
|
if(event.getButton() == MouseButton.SECONDARY){
|
||||||
|
@ -4,6 +4,7 @@ import javafx.scene.Node;
|
|||||||
import javafx.scene.image.Image;
|
import javafx.scene.image.Image;
|
||||||
import javafx.scene.image.ImageView;
|
import javafx.scene.image.ImageView;
|
||||||
import javafx.scene.layout.GridPane;
|
import javafx.scene.layout.GridPane;
|
||||||
|
import javafx.scene.layout.Pane;
|
||||||
import javafx.scene.paint.Paint;
|
import javafx.scene.paint.Paint;
|
||||||
import javafx.scene.shape.Rectangle;
|
import javafx.scene.shape.Rectangle;
|
||||||
import school_project.*;
|
import school_project.*;
|
||||||
@ -34,8 +35,8 @@ public class MatrixShape extends GridPane {
|
|||||||
boolean[][] shape_matrix = shape.getShape();
|
boolean[][] shape_matrix = shape.getShape();
|
||||||
for (int i = 0; i < shape_matrix.length; i++) {
|
for (int i = 0; i < shape_matrix.length; i++) {
|
||||||
for (int j = 0; j < shape_matrix[i].length; j++) {
|
for (int j = 0; j < shape_matrix[i].length; j++) {
|
||||||
|
Node _cell;
|
||||||
if(shape_matrix[i][j]){
|
if(shape_matrix[i][j]){
|
||||||
Node _cell;
|
|
||||||
if(shape instanceof Piece){
|
if(shape instanceof Piece){
|
||||||
Piece p = (Piece) shape;
|
Piece p = (Piece) shape;
|
||||||
_cell = new Rectangle(GameUI.SEGMENT_SIZE, GameUI.SEGMENT_SIZE);
|
_cell = new Rectangle(GameUI.SEGMENT_SIZE, GameUI.SEGMENT_SIZE);
|
||||||
@ -47,8 +48,12 @@ public class MatrixShape extends GridPane {
|
|||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
add(_cell, j, i);
|
|
||||||
}
|
}
|
||||||
|
else{
|
||||||
|
_cell = new Pane();
|
||||||
|
((Pane) _cell).setPrefSize(GameUI.SEGMENT_SIZE, GameUI.SEGMENT_SIZE);
|
||||||
|
}
|
||||||
|
add(_cell, j, i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
boundary_size = new Vec2((GameUI.SEGMENT_SIZE + GameUI.SPACE_SIZE) * shape.getWidth(), (GameUI.SEGMENT_SIZE + GameUI.SPACE_SIZE) * shape.getHeight());
|
boundary_size = new Vec2((GameUI.SEGMENT_SIZE + GameUI.SPACE_SIZE) * shape.getWidth(), (GameUI.SEGMENT_SIZE + GameUI.SPACE_SIZE) * shape.getHeight());
|
||||||
|
Loading…
Reference in New Issue
Block a user