add world interface
This commit is contained in:
@@ -1,22 +1,78 @@
|
||||
package chess.view.DDDrender;
|
||||
|
||||
import chess.controller.CommandExecutor;
|
||||
import chess.controller.event.GameAdaptator;
|
||||
import org.joml.Vector2f;
|
||||
import org.joml.Vector3f;
|
||||
|
||||
public class DDDView extends GameAdaptator{
|
||||
import chess.controller.CommandExecutor;
|
||||
import chess.controller.commands.GetPieceAtCommand;
|
||||
import chess.controller.event.GameAdaptator;
|
||||
import chess.model.Color;
|
||||
import chess.model.Coordinate;
|
||||
import chess.model.Piece;
|
||||
import chess.view.DDDrender.world.PieceEntity;
|
||||
import chess.view.DDDrender.world.World;
|
||||
|
||||
public class DDDView extends GameAdaptator {
|
||||
|
||||
private static final Vector3f BLACK = new Vector3f(0.3f, 0.3f, 0.3f);
|
||||
private static final Vector3f WHITE = new Vector3f(1.0f, 1.0f, 1.0f);
|
||||
|
||||
private final CommandExecutor commandExecutor;
|
||||
private final Window window;
|
||||
private final Renderer renderer;
|
||||
private final World world;
|
||||
|
||||
public DDDView(CommandExecutor commandExecutor) {
|
||||
this.commandExecutor = commandExecutor;
|
||||
this.renderer = new Renderer();
|
||||
this.window = new Window(commandExecutor, this.renderer);
|
||||
this.world = new World(new Camera());
|
||||
this.window = new Window(this.renderer, this.world);
|
||||
this.window.OnCellClick.connect(this::onCellClick);
|
||||
}
|
||||
|
||||
// Invoked when a cell is clicked
|
||||
private void onCellClick(Coordinate coordinate) {
|
||||
|
||||
}
|
||||
|
||||
private Piece pieceAt(Coordinate pos) {
|
||||
GetPieceAtCommand cmd = new GetPieceAtCommand(pos);
|
||||
this.commandExecutor.executeCommand(cmd);
|
||||
return cmd.getPiece();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onGameStart() {
|
||||
this.window.scheduleTask(() -> {
|
||||
initBoard();
|
||||
});
|
||||
}
|
||||
|
||||
private void initBoard() {
|
||||
for (int i = 0; i < Coordinate.VALUE_MAX; i++) {
|
||||
for (int j = 0; j < Coordinate.VALUE_MAX; j++) {
|
||||
Coordinate pos = new Coordinate(i, j);
|
||||
Piece piece = pieceAt(pos);
|
||||
if (piece == null)
|
||||
continue;
|
||||
|
||||
Vector2f pieceBoardPos = DDDPlacement.coordinates_to_vector(pos);
|
||||
Vector3f pieceWorldPos = new Vector3f(pieceBoardPos.x(), 0, pieceBoardPos.y());
|
||||
|
||||
this.world.addEntity(new PieceEntity(piece, pieceWorldPos,
|
||||
piece.getColor() == Color.White ? WHITE : BLACK,
|
||||
piece.getColor() == Color.White ? 0.0f : (float) Math.PI));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void run() {
|
||||
this.window.addRegularTask((delta) -> {
|
||||
final float angle = 1f;
|
||||
final Camera cam = this.world.getCamera();
|
||||
cam.setRotateAngle(cam.getRotateAngle() + angle * delta);
|
||||
});
|
||||
this.window.run();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user