Game UI #38
@ -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){
|
||||
|
@ -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());
|
||||
|
Loading…
Reference in New Issue
Block a user