Commit 4618021c authored by Anders H. Rebner's avatar Anders H. Rebner
Browse files

Added possible moves indicators, tweaked hexSideLength

parent e7bab470
......@@ -47,12 +47,14 @@ public class GameController {
// If another piece is already active, deactivate it
if (activePiece != null) {
activePiece.setRotateHead(false);
this.view.removePossibleMoves();
}
// If clicked piece is owned by player and player is not finished, activate piece
if(this.model.getPieceOwnerId(cubeCoordinates) == playerController.getPlayer().getID() && !this.model.isPlayerFinished(playerController.getPlayer().getID())) {
activePiece = this.view.getPiece(cubeCoordinates);
activePiece.setRotateHead(true);
previousCoordinateClicked = cubeCoordinates;
this.view.placePossibleMoves(model.getPossibleMoves(previousCoordinateClicked));
}
} else { // Field does NOT have piece
......@@ -65,6 +67,7 @@ public class GameController {
playerController.getNetWorkController().sendToServer(new cPlayerPieceMove(previousCoordinateClicked, cubeCoordinates, playerController.getLobby().getID(), playerController.getPlayer().getID()));
previousCoordinateClicked = null;
this.view.removePossibleMoves();
this.view.placeTurnIndicator(playerNameTextFieldCoordinates.get(this.model.getPlayerTurnSlot()));
} else {
System.out.println("Move was not allowed"); // TODO: Give feedback (move was not valid/not executed)
......@@ -74,7 +77,6 @@ public class GameController {
}
}
public void playerMovedPiece(Vector3 fromCoordinates, Vector3 toCoordinates, int playerId) {
if (this.model.movePiece(fromCoordinates, toCoordinates, playerId, this)) {
this.view.moveOtherPlayerPiece(fromCoordinates, toCoordinates);
......
......@@ -2,6 +2,7 @@ package com.mygdx.game.controllers
import com.badlogic.gdx.math.Vector2
import com.badlogic.gdx.math.Vector3
import java.util.*
import kotlin.math.roundToInt
import kotlin.math.sqrt
......@@ -39,3 +40,16 @@ fun pixelToCube(vector: Vector2, hexSideLength: Float = 1F) : Array<Float> {
return arrayOf(cubeX, cubeY, cubeZ)
}
fun cubeCoordinateSetToPixel(cubeCoordinateSet: List<List<Vector3>>, hexSideLength: Float = 1F): List<List<Array<Float>>> {
// Convert to pixel coordinates
val startFieldCoordinatesPixel: MutableList<List<Array<Float>>> = ArrayList()
for (coordinateSet in cubeCoordinateSet) {
val coordinateSetPixel: MutableList<Array<Float>> = ArrayList()
for (coordinate in coordinateSet) {
coordinateSetPixel.add(cubeToPixel(coordinate, hexSideLength))
}
startFieldCoordinatesPixel.add(coordinateSetPixel)
}
return startFieldCoordinatesPixel
}
\ No newline at end of file
......@@ -69,6 +69,10 @@ class Game(gameState: GameState, playerIds: LinkedHashSet<Int>) {
}
}
fun getPossibleMoves(fromCoordinates: Vector3): ArrayList<Vector3>? {
return getGameState()?.getGameMode()?.getPossibleMoves(fromCoordinates)
}
fun getPlayerTurnId(): Int {
return playerTurnId
}
......
......@@ -13,6 +13,7 @@ import com.badlogic.gdx.scenes.scene2d.ui.Image;
import com.badlogic.gdx.scenes.scene2d.ui.Skin;
import com.badlogic.gdx.scenes.scene2d.ui.TextButton;
import com.badlogic.gdx.scenes.scene2d.ui.TextField;
import com.badlogic.gdx.utils.Array;
import com.badlogic.gdx.utils.Scaling;
import com.mygdx.game.Constants;
import com.mygdx.game.controllers.GameController;
......@@ -57,6 +58,9 @@ public class PlayView extends View{
GameController gameController;
List<TextField> playerNameFields;
List<Image> possibleMoves = new ArrayList<>();
Texture possibleMoveTexture;
float scale_factor_piece;
public float hex_side_length;
......@@ -80,7 +84,7 @@ public class PlayView extends View{
// Calculate scale factors for board and pieces, and corresponding hex side length
float scale_factor_board = Gdx.graphics.getHeight() / boardImage.getHeight();
this.scale_factor_piece = scale_factor_board * 0.18421F;
this.hex_side_length = scale_factor_board / 0.00678F;
this.hex_side_length = scale_factor_board / 0.0068F;
boardImage.setScaleX(scale_factor_board);
boardImage.setScaleY(scale_factor_board);
......@@ -107,6 +111,8 @@ public class PlayView extends View{
rocketExhaustImage.rotateBy(-30);
stage.addActor(rocketExhaustImage);
possibleMoveTexture = (Texture) assetManager.get(PlayAssets.POSSIBLE_FIELD.path, PlayAssets.POSSIBLE_FIELD.classType);
starPieceBase = (Texture) assetManager.get(PlayAssets.STAR_PIECE_BASE.path, PlayAssets.STAR_PIECE_BASE.classType);
starPieceBaseBorder = (Texture) assetManager.get(PlayAssets.STAR_PIECE_BASE_BORDER.path, PlayAssets.STAR_PIECE_BASE_BORDER.classType);
starPieceMast = (Texture) assetManager.get(PlayAssets.STAR_PIECE_MAST.path, PlayAssets.STAR_PIECE_MAST.classType);
......@@ -162,7 +168,7 @@ public class PlayView extends View{
int colorCounter = 0;
// Convert to pixel coordinates
List<List<Float[]>> startFieldPixelCoordinates = cubeCoordinateSetToPixel(startFieldCubeCoordinates);
List<List<Float[]>> startFieldPixelCoordinates = UtilsKt.cubeCoordinateSetToPixel(startFieldCubeCoordinates, hex_side_length);
for (int i = 0; i < startFieldPixelCoordinates.size(); i++) {
for (int j = 0; j < startFieldPixelCoordinates.get(i).size(); j++) {
......@@ -170,8 +176,9 @@ public class PlayView extends View{
float coordinateX = startFieldPixelCoordinates.get(i).get(j)[0];
float coordinateY = startFieldPixelCoordinates.get(i).get(j)[1];
// Base coordinates from center of screen
coordinateX += Gdx.graphics.getWidth() / 2F - (starPieceBase.getWidth() * scale_factor_piece) / 2F;
coordinateY = Gdx.graphics.getHeight() / 2F - coordinateY - (starPieceBase.getHeight() * scale_factor_piece) / 2F; // Adjusted for inverted y-axis
coordinateY = Gdx.graphics.getHeight() / 2F - coordinateY - (starPieceBase.getHeight() * scale_factor_piece) / 2F + 3F;
color = PIECE_COLORS.get(colorCounter);
StarPiece piece = new StarPiece(scale_factor_piece, coordinateX, coordinateY, color, starPieceBase, starPieceBaseBorder, starPieceMast, starPieceMastBorder, starPieceHead, starPieceHeadBorder);
......@@ -207,6 +214,34 @@ public class PlayView extends View{
rocketExhaustImage.remove();
}
public void placePossibleMoves(List<Vector3> cubeCoordinates) {
Float[] coordinates;
for (Vector3 cubeCoordinate : cubeCoordinates) {
coordinates = UtilsKt.cubeToPixel(cubeCoordinate, hex_side_length);
float coordinateX = coordinates[0];
float coordinateY = coordinates[1];
Image possibleMoveImage = new Image(possibleMoveTexture);
possibleMoveImage.setSize(1.2F * hex_side_length, 1.2F * hex_side_length);
// Base coordinates from center of screen
coordinateX += Gdx.graphics.getWidth() / 2F - (possibleMoveImage.getWidth() / 2F);
coordinateY = Gdx.graphics.getHeight() / 2F - coordinateY - (possibleMoveImage.getHeight() / 2F) + 4F;
possibleMoveImage.setPosition(coordinateX, coordinateY);
stage.addActor(possibleMoveImage);
possibleMoves.add(possibleMoveImage);
}
}
public void removePossibleMoves() {
for (Image possibleMove : possibleMoves) {
possibleMove.remove();
}
}
public void setPlayerFinished(int playerIndex, int place) {
// Weaken playername-field
TextField playerNameField = playerNameFields.get(playerIndex);
......@@ -284,20 +319,6 @@ public class PlayView extends View{
return this.pieces.get(coordinates);
}
private List<List<Float[]>> cubeCoordinateSetToPixel(List<List<Vector3>> cubeCoordinateSet) {
// Convert to pixel coordinates
List<List<Float[]>> startFieldCoordinatesPixel = new ArrayList<>();
for (List<Vector3> coordinateSet : cubeCoordinateSet) {
List<Float[]> coordinateSetPixel = new ArrayList<>();
for (Vector3 coordinate : coordinateSet) {
coordinateSetPixel.add(UtilsKt.cubeToPixel(coordinate, hex_side_length));
}
startFieldCoordinatesPixel.add(coordinateSetPixel);
}
return startFieldCoordinatesPixel;
}
public void movePiece(StarPiece piece, Vector3 toCoordinates) {
Float[] pixelCoordinates = UtilsKt.cubeToPixel(toCoordinates, hex_side_length);
......
......@@ -13,7 +13,8 @@ public enum PlayAssets {
STAR_PIECE_MAST("Game/1x/StarPiece_Mast.png", Texture.class),
STAR_PIECE_MAST_BORDER("Game/1x/StarPiece_MastBrd.png", Texture.class),
ROCKET("Menu/0.25x/Rocket_Main@0.25x.png", Texture.class),
ROCKET_EXHAUST("Menu/0.25x/Rocket_Exhaust@0.25x.png", Texture.class);
ROCKET_EXHAUST("Menu/0.25x/Rocket_Exhaust@0.25x.png", Texture.class),
POSSIBLE_FIELD("Game/1x/Possible_Field.png", Texture.class);
public final String path;
public final Class classType;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment