Skip to content

Commit

Permalink
Revert "Fix balls not aligned with cells"
Browse files Browse the repository at this point in the history
This reverts commit e4d961a.
  • Loading branch information
pietrygamat committed May 12, 2024
1 parent 5cc337f commit 6c2c265
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 14 deletions.
15 changes: 9 additions & 6 deletions src/main/java/net/jockx/kulki/view/shapes/BallShape.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,18 @@ public BallShape(Ball ball){
public void moveTo(List<CellNode> cellsInPath){

Path path = new Path();
MoveTo start = new MoveTo(
cellsInPath.getFirst().getBoundsInParent().getCenterX() - getBoundsInParent().getCenterX(),
cellsInPath.getFirst().getBoundsInParent().getCenterY() - getBoundsInParent().getCenterY());
CellNode lastNode = cellsInPath.get(cellsInPath.size()-1);
double oldLayoutX = getLayoutX();
double oldLayoutY = getLayoutY();
setLayoutX(lastNode.moveToPosition.getX());
setLayoutY(lastNode.moveToPosition.getY());

MoveTo start = new MoveTo(oldLayoutX - getLayoutX(), oldLayoutY - getLayoutY());
path.getElements().add(start);

for (CellNode cell : cellsInPath){
double x = cell.getBoundsInParent().getCenterX() - getBoundsInParent().getCenterX();
double y = cell.getBoundsInParent().getCenterY() - getBoundsInParent().getCenterY();
path.getElements().add(new LineTo(x, y));
LineTo relativeLine = new LineTo(cell.moveToPosition.getX() - getLayoutX(), cell.moveToPosition.getY() - getLayoutY());
path.getElements().add(relativeLine);
}

PathTransition pathTransition = new PathTransition();
Expand Down
16 changes: 8 additions & 8 deletions src/main/java/net/jockx/kulki/view/shapes/CellNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import javafx.scene.Group;
import javafx.scene.input.MouseEvent;
import javafx.scene.paint.Color;
import javafx.scene.shape.LineTo;
import javafx.scene.shape.Rectangle;
import net.jockx.kulki.controller.EventHandlers;
import net.jockx.kulki.controller.GameController;
Expand All @@ -14,6 +15,7 @@
public class CellNode extends Group {

private final Rectangle CellShape;
final LineTo moveToPosition;
private BallShape ball;

private final int column;
Expand All @@ -26,15 +28,12 @@ public CellNode(double width, double height, int x, int y) {
this.row = y;

getChildren().add(CellShape);
boundsInParentProperty().addListener((observable, oldValue, newValue) -> {
if(this.ball != null) {
this.ball.setLayoutX(newValue.getCenterX());
this.ball.setLayoutY(newValue.getCenterY());
}
});
addEventHandler(MouseEvent.MOUSE_ENTERED_TARGET, EventHandlers.onMouseOver);
addEventHandler(MouseEvent.MOUSE_EXITED_TARGET, EventHandlers.onMouseAway);
addEventHandler(MouseEvent.MOUSE_CLICKED, EventHandlers.onClick);
moveToPosition = new LineTo(x * (width + 5) + getCellShape().getWidth() / 2,
y * (height + 5) + getCellShape().getHeight() / 2);

}

public CellNode (double width, double height){
Expand All @@ -46,6 +45,7 @@ public CellNode (double width, double height){

this.column = -1;
this.row = -1;
moveToPosition = null;
}


Expand Down Expand Up @@ -100,8 +100,8 @@ public void setBall(BallShape ball) {
}

public void setBallFirstTime(BallShape ball){
ball.setLayoutX(this.getBoundsInParent().getCenterX());
ball.setLayoutY(this.getBoundsInParent().getCenterY());
ball.setLayoutX(moveToPosition.getX());
ball.setLayoutY(moveToPosition.getY());
setBall(ball);
}

Expand Down

0 comments on commit 6c2c265

Please sign in to comment.