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

Board, pieces and hex_side_length adjusted to device screen, added background image

parent d7b15bee
......@@ -70,10 +70,10 @@ public class UniCheckersClient extends ApplicationAdapter {
//gvm.push(new LoadingView(gvm, playerController, assetManager, stage, skin));
//gvm.push(new CinematicView(gvm, playerController, assetManager, stage, skin));
// TODO: Remove the following four lines and use the above line instead
PlayView playView = new PlayView(gvm, playerController, assetManager, stage, skin, null);
gameController = new GameController(model, playView);
playView.setGameController(gameController);
gvm.push(playView);
}
......
......@@ -2,7 +2,6 @@ package com.mygdx.game.controllers;
import com.badlogic.gdx.math.Vector3;
import com.mygdx.game.model.Game;
import com.mygdx.game.views.Constants;
import com.mygdx.game.views.PlayView;
import com.mygdx.game.views.tokens.StarPiece;
......@@ -24,7 +23,7 @@ public class GameController {
}
public void handleClick(float x, float y) {
Vector3 cubeCoordinates = UtilsKt.pixelToCube(x, y, Constants.HEX_SIDE_LENGTH);
Vector3 cubeCoordinates = UtilsKt.pixelToCube(x, y, this.view.hex_side_length);
// If field exists at clicked coordinates
if (this.model.fieldExists(cubeCoordinates)) {
......
......@@ -22,7 +22,6 @@ class Game(gameState: GameState) {
}
fun fieldHasPiece(cubeCoordinates: Vector3): Boolean {
print(this.gameState.getBoardState()?.fields?.get(cubeCoordinates)?.hasPiece())
return this.gameState.getBoardState()?.fields?.get(cubeCoordinates)?.hasPiece() == true
}
......
......@@ -12,7 +12,13 @@ import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.scenes.scene2d.Stage;
import com.badlogic.gdx.scenes.scene2d.ui.Image;
import com.badlogic.gdx.scenes.scene2d.ui.Skin;
import com.mygdx.game.controllers.GameController;
import com.mygdx.game.controllers.PlayerController;
import com.mygdx.game.model.DefaultBoard;
import com.mygdx.game.model.Game;
import com.mygdx.game.model.GameMode;
import com.mygdx.game.model.GameState;
import com.mygdx.game.model.gamemodes.rules.DefaultRules;
import com.mygdx.game.views.enums.CharacterAssets;
import com.mygdx.game.views.enums.CinematicAssets;
import com.mygdx.game.views.enums.LobbyAssets;
......@@ -269,7 +275,13 @@ public class CinematicView extends View{
if(fadeOutAlpha >= 1){
stage.clear();
startFadeout = false;
gvm.set(new PlayView(gvm, playerController, assetManager, stage, skin, lobbyAvatars));
Game model = new Game(new GameState(new GameMode(new DefaultRules(), new DefaultBoard())));
PlayView playView = new PlayView(gvm, playerController, assetManager, stage, skin, lobbyAvatars);
GameController gameController = new GameController(model, playView);
playView.setGameController(gameController);
gvm.set(playView);
}
}
......
package com.mygdx.game.views;
public class Constants {
public static final Float SCALE_FACTOR_BOARD = 0.19F;
public static final Float SCALE_FACTOR_PIECE = 0.035F;
public static final Float HEX_SIDE_LENGTH = 28F;
}
......@@ -20,7 +20,6 @@ import com.mygdx.game.views.tokens.StarPiece;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
......@@ -30,7 +29,6 @@ public class PlayView extends View{
int row_height = Gdx.graphics.getHeight() / Help_Guides;
int col_width = Gdx.graphics.getWidth() / Help_Guides;
Float BOARD_SCALE_FACTOR = Constants.SCALE_FACTOR_BOARD;
List<Color> PIECE_COLORS = Arrays.asList(Color.PINK, Color.CYAN, Color.LIME, Color.GOLD, Color.LIGHT_GRAY, Color.PURPLE);
Texture starPieceBase;
......@@ -43,19 +41,36 @@ public class PlayView extends View{
HashMap<Vector3, StarPiece> pieces;
GameController gameController;
float scale_factor_piece;
public float hex_side_length;
public PlayView(GameViewManager gvm, PlayerController playerController, AssetManager assetManager, Stage stage, Skin skin, ArrayList<AnimatedSprite> lobbyAvatars) {
super(gvm, playerController, assetManager, stage, skin);
// Create and downscale background image
Texture background = new Texture("Game/1x/GameBoard@1x.png");
// Create background image
Texture background = new Texture("Game/1x/StarBackground1x.png");
Image backgroundImage = new Image(background);
backgroundImage.setScaleX(BOARD_SCALE_FACTOR);
backgroundImage.setScaleY(BOARD_SCALE_FACTOR);
//backgroundImage.setScaling(Scaling.fit);
backgroundImage.setScaling(Scaling.fill);
backgroundImage.setSize(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
backgroundImage.setPosition(Gdx.graphics.getWidth() / 2F - backgroundImage.getWidth() * backgroundImage.getScaleX() / 2F, Gdx.graphics.getHeight() / 2F - backgroundImage.getHeight() * backgroundImage.getScaleY() / 2F);
stage.addActor(backgroundImage);
// Create board image
Texture board = new Texture("Game/1x/GameBoard@1x.png");
Image boardImage = new Image(board);
// 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;
boardImage.setScaleX(scale_factor_board);
boardImage.setScaleY(scale_factor_board);
boardImage.setPosition(Gdx.graphics.getWidth() / 2F - boardImage.getWidth() * boardImage.getScaleX() / 2F, Gdx.graphics.getHeight() / 2F - board.getHeight() * boardImage.getScaleY() / 2F);
stage.addActor(boardImage);
for (PlayAssets asset : PlayAssets.values()) {
assetManager.load(asset.path, asset.classType);
}
......@@ -127,11 +142,11 @@ public class PlayView extends View{
float coordinateX = startFieldPixelCoordinates.get(i).get(j)[0];
float coordinateY = startFieldPixelCoordinates.get(i).get(j)[1];
coordinateX += Gdx.graphics.getWidth() / 2F - (starPieceBase.getWidth() * Constants.SCALE_FACTOR_PIECE) / 2F;
coordinateY = Gdx.graphics.getHeight() / 2F - coordinateY - (starPieceBase.getHeight() * Constants.SCALE_FACTOR_PIECE) / 2F; // Adjusted for inverted y-axis
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
color = PIECE_COLORS.get(colorCounter);
StarPiece piece = new StarPiece(coordinateX, coordinateY, color, starPieceBase, starPieceBaseBorder, starPieceMast, starPieceMastBorder, starPieceHead, starPieceHeadBorder);
StarPiece piece = new StarPiece(scale_factor_piece, coordinateX, coordinateY, color, starPieceBase, starPieceBaseBorder, starPieceMast, starPieceMastBorder, starPieceHead, starPieceHeadBorder);
this.pieces.put(startFieldCubeCoordinates.get(i).get(j), piece);
}
colorCounter++;
......@@ -181,7 +196,7 @@ public class PlayView extends View{
List<Float[]> coordinateSetPixel = new ArrayList<>();
for (Vector3 coordinate : coordinateSet) {
coordinateSetPixel.add(UtilsKt.cubeToPixel(coordinate, Constants.HEX_SIDE_LENGTH));
coordinateSetPixel.add(UtilsKt.cubeToPixel(coordinate, hex_side_length));
}
startFieldCoordinatesPixel.add(coordinateSetPixel);
}
......@@ -189,10 +204,10 @@ public class PlayView extends View{
}
public void movePiece(StarPiece piece, Vector3 toCoordinates) {
Float[] pixelCoordinates = UtilsKt.cubeToPixel(toCoordinates, Constants.HEX_SIDE_LENGTH);
Float[] pixelCoordinates = UtilsKt.cubeToPixel(toCoordinates, hex_side_length);
piece.setX((Gdx.graphics.getWidth() / 2F) + pixelCoordinates[0] - ((starPieceBase.getWidth() * Constants.SCALE_FACTOR_PIECE) / 2F));
piece.setY(Gdx.graphics.getHeight() / 2F - pixelCoordinates[1] - ((starPieceBase.getHeight() * Constants.SCALE_FACTOR_PIECE) / 2F));
piece.setX((Gdx.graphics.getWidth() / 2F) + pixelCoordinates[0] - ((starPieceBase.getWidth() * scale_factor_piece) / 2F));
piece.setY(Gdx.graphics.getHeight() / 2F - pixelCoordinates[1] - ((starPieceBase.getHeight() * scale_factor_piece) / 2F));
// Replace key
pieces.values().remove(piece);
......
......@@ -3,8 +3,6 @@ package com.mygdx.game.views.tokens;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.Batch;
import com.badlogic.gdx.graphics.g2d.Sprite;
import com.mygdx.game.views.Constants;
public class StarPiece {
......@@ -22,9 +20,9 @@ public class StarPiece {
private boolean rotateHead;
private float headRotation = 1;
Float SCALE_FACTOR;
Float scale_factor;
public StarPiece (float xPos, float yPos, Color color, Texture base, Texture baseBorder, Texture mast, Texture mastBorder, Texture head, Texture headBorder){
public StarPiece (float scale_factor, float xPos, float yPos, Color color, Texture base, Texture baseBorder, Texture mast, Texture mastBorder, Texture head, Texture headBorder){
this.xPos = xPos;
this.yPos = yPos;
......@@ -38,32 +36,32 @@ public class StarPiece {
this.headBorder = headBorder;
this.rotateHead=false;
this.SCALE_FACTOR = Constants.SCALE_FACTOR_PIECE;
this.scale_factor = scale_factor;
}
public void draw(Batch sb){
Color sbColor = sb.getColor();
sb.begin();
sb.setColor(color);
sb.draw(base, xPos, yPos, base.getWidth() * SCALE_FACTOR, base.getHeight() * SCALE_FACTOR);
sb.draw(base, xPos, yPos, base.getWidth() * scale_factor, base.getHeight() * scale_factor);
sb.setColor(Color.BLACK);
sb.draw(baseBorder, xPos, yPos, baseBorder.getWidth() * SCALE_FACTOR, baseBorder.getHeight() * SCALE_FACTOR);
sb.draw(baseBorder, xPos, yPos, baseBorder.getWidth() * scale_factor, baseBorder.getHeight() * scale_factor);
sb.setColor(color);
sb.draw(mast, xPos+ (base.getWidth() * SCALE_FACTOR)/2-(mast.getWidth() * SCALE_FACTOR)/2, yPos+(base.getHeight() * SCALE_FACTOR)*0.35f, mast.getWidth() * SCALE_FACTOR, mast.getHeight() * SCALE_FACTOR);
sb.draw(mast, xPos+ (base.getWidth() * scale_factor)/2-(mast.getWidth() * scale_factor)/2, yPos+(base.getHeight() * scale_factor)*0.35f, mast.getWidth() * scale_factor, mast.getHeight() * scale_factor);
sb.setColor(Color.BLACK);
sb.draw(mastBorder, xPos+(base.getWidth() * SCALE_FACTOR)/2-(mast.getWidth()*SCALE_FACTOR)/2, yPos+(base.getHeight() * SCALE_FACTOR)*0.35f, mastBorder.getWidth() * SCALE_FACTOR, mastBorder.getHeight() * SCALE_FACTOR);
sb.draw(mastBorder, xPos+(base.getWidth() * scale_factor)/2-(mast.getWidth()*scale_factor)/2, yPos+(base.getHeight() * scale_factor)*0.35f, mastBorder.getWidth() * scale_factor, mastBorder.getHeight() * scale_factor);
if(rotateHead){
sb.setColor(color);
sb.draw(head,
xPos+(base.getWidth() * SCALE_FACTOR)/2-(head.getWidth()*SCALE_FACTOR)/2,
yPos+(base.getHeight()*SCALE_FACTOR)-(head.getWidth()*SCALE_FACTOR)/2,
head.getWidth()*SCALE_FACTOR/2,
head.getHeight()*SCALE_FACTOR/2,
head.getWidth()*SCALE_FACTOR,
head.getHeight()*SCALE_FACTOR,
xPos+(base.getWidth() * scale_factor)/2-(head.getWidth()*scale_factor)/2,
yPos+(base.getHeight()*scale_factor)-(head.getWidth()*scale_factor)/2,
head.getWidth()*scale_factor/2,
head.getHeight()*scale_factor/2,
head.getWidth()*scale_factor,
head.getHeight()*scale_factor,
1F,
1F,
headRotation++,
......@@ -76,12 +74,12 @@ public class StarPiece {
sb.setColor(Color.BLACK);
sb.draw(headBorder,
xPos+(base.getWidth()*SCALE_FACTOR)/2-(head.getWidth()*SCALE_FACTOR)/2,
yPos+(base.getHeight()*SCALE_FACTOR)-(head.getWidth()*SCALE_FACTOR)/2,
head.getWidth()*SCALE_FACTOR/2,
head.getHeight()*SCALE_FACTOR/2,
head.getWidth()*SCALE_FACTOR,
head.getHeight()*SCALE_FACTOR,
xPos+(base.getWidth()*scale_factor)/2-(head.getWidth()*scale_factor)/2,
yPos+(base.getHeight()*scale_factor)-(head.getWidth()*scale_factor)/2,
head.getWidth()*scale_factor/2,
head.getHeight()*scale_factor/2,
head.getWidth()*scale_factor,
head.getHeight()*scale_factor,
1F,
1F,
headRotation++,
......@@ -94,9 +92,9 @@ public class StarPiece {
}
else{
sb.setColor(color);
sb.draw(head, xPos+(base.getWidth() * SCALE_FACTOR)/2-(head.getWidth() * SCALE_FACTOR)/2, yPos+(base.getHeight() * SCALE_FACTOR)-(head.getWidth() * SCALE_FACTOR)/2, head.getWidth() * SCALE_FACTOR, head.getHeight() * SCALE_FACTOR);
sb.draw(head, xPos+(base.getWidth() * scale_factor)/2-(head.getWidth() * scale_factor)/2, yPos+(base.getHeight() * scale_factor)-(head.getWidth() * scale_factor)/2, head.getWidth() * scale_factor, head.getHeight() * scale_factor);
sb.setColor(Color.BLACK);
sb.draw(headBorder, xPos+(base.getWidth() * SCALE_FACTOR)/2-(head.getWidth() * SCALE_FACTOR)/2, yPos+(base.getHeight() * SCALE_FACTOR)-(head.getWidth() * SCALE_FACTOR)/2, headBorder.getWidth() * SCALE_FACTOR, headBorder.getHeight() * SCALE_FACTOR);
sb.draw(headBorder, xPos+(base.getWidth() * scale_factor)/2-(head.getWidth() * scale_factor)/2, yPos+(base.getHeight() * scale_factor)-(head.getWidth() * scale_factor)/2, headBorder.getWidth() * scale_factor, headBorder.getHeight() * scale_factor);
}
sb.setColor(sbColor);
......@@ -123,9 +121,9 @@ public class StarPiece {
return yPos;
}
public float getWidth() { return base.getWidth() * SCALE_FACTOR;}
public float getWidth() { return base.getWidth() * scale_factor;}
public float getHeight() { return base.getHeight() * SCALE_FACTOR;}
public float getHeight() { return base.getHeight() * scale_factor;}
public void setPosition(float xPos, float yPos){
this.xPos = xPos;
......
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