From 60bf1fa5d087c48157fb606ba943e843edc15cba Mon Sep 17 00:00:00 2001 From: Anthony Debucquoy Date: Fri, 5 May 2023 12:03:40 +0200 Subject: [PATCH] make white space on detached pieces --- app/src/main/java/school_project/GameUI.java | 13 +++++++++++++ .../main/java/school_project/Utils/MatrixShape.java | 9 +++++++-- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/school_project/GameUI.java b/app/src/main/java/school_project/GameUI.java index 6b81899..139109a 100644 --- a/app/src/main/java/school_project/GameUI.java +++ b/app/src/main/java/school_project/GameUI.java @@ -22,9 +22,22 @@ public class GameUI extends Group{ getChildren().add(grid); + Vec2 piece_space = new Vec2(SPACE_SIZE, SPACE_SIZE); + int column = 0; for (Piece p : level.getPieces()) { 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 _piece.setOnMouseClicked(event -> { if(event.getButton() == MouseButton.SECONDARY){ diff --git a/app/src/main/java/school_project/Utils/MatrixShape.java b/app/src/main/java/school_project/Utils/MatrixShape.java index fed4045..5ed0f34 100644 --- a/app/src/main/java/school_project/Utils/MatrixShape.java +++ b/app/src/main/java/school_project/Utils/MatrixShape.java @@ -4,6 +4,7 @@ import javafx.scene.Node; import javafx.scene.image.Image; import javafx.scene.image.ImageView; import javafx.scene.layout.GridPane; +import javafx.scene.layout.Pane; import javafx.scene.paint.Paint; import javafx.scene.shape.Rectangle; import school_project.*; @@ -34,8 +35,8 @@ public class MatrixShape extends GridPane { boolean[][] shape_matrix = shape.getShape(); for (int i = 0; i < shape_matrix.length; i++) { for (int j = 0; j < shape_matrix[i].length; j++) { + Node _cell; if(shape_matrix[i][j]){ - Node _cell; if(shape instanceof Piece){ Piece p = (Piece) shape; _cell = new Rectangle(GameUI.SEGMENT_SIZE, GameUI.SEGMENT_SIZE); @@ -47,8 +48,12 @@ public class MatrixShape extends GridPane { 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());