feat: change board cells color

This commit is contained in:
2025-04-28 11:04:41 +02:00
parent b57fa1482b
commit de4ed869ea
6 changed files with 65 additions and 13 deletions

View File

@@ -9,6 +9,7 @@ import chess.controller.event.GameAdaptator;
import chess.model.Color;
import chess.model.Coordinate;
import chess.model.Piece;
import chess.view.DDDrender.world.BoardEntity;
import chess.view.DDDrender.world.PieceEntity;
import chess.view.DDDrender.world.World;
@@ -21,15 +22,13 @@ public class DDDView extends GameAdaptator {
private final Window window;
private final Renderer renderer;
private final World world;
private BoardEntity boardEntity;
public DDDView(CommandExecutor commandExecutor) {
this.commandExecutor = commandExecutor;
this.renderer = new Renderer();
this.world = new World(new Camera());
this.window = new Window(this.renderer, this.world);
this.window.OnCellClick.connect(this::onCellClick);
this.window.OnCellEnter.connect(this::onCellEnter);
this.window.OnCellExit.connect(this::onCellExit);
}
// Invoked when a cell is clicked
@@ -39,7 +38,8 @@ public class DDDView extends GameAdaptator {
// Invoked when a cell is hovered
private void onCellEnter(Coordinate coordinate) {
// small test turning a piece red when hovered
// small test turning a cell red when hovered
this.boardEntity.setCellColor(coordinate, new Vector3f(1, 0, 0));
Piece p = pieceAt(coordinate);
if (p == null)
return;
@@ -48,6 +48,7 @@ public class DDDView extends GameAdaptator {
// Invoked when a cell is not hovered anymore
private void onCellExit(Coordinate coordinate) {
this.boardEntity.resetCellColor(coordinate);
Piece p = pieceAt(coordinate);
if (p == null)
return;
@@ -64,6 +65,9 @@ public class DDDView extends GameAdaptator {
public void onGameStart() {
this.window.scheduleTask(() -> {
initBoard();
this.window.OnCellClick.connect(this::onCellClick);
this.window.OnCellEnter.connect(this::onCellEnter);
this.window.OnCellExit.connect(this::onCellExit);
});
}
@@ -83,6 +87,8 @@ public class DDDView extends GameAdaptator {
piece.getColor() == Color.White ? 0.0f : (float) Math.PI));
}
}
this.boardEntity = new BoardEntity();
this.world.addEntity(this.boardEntity);
}
public void run() {