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

Adjusted piece placement for inverted y-axis, colored pieces and created Constants file

parent 59ae8056
......@@ -2,10 +2,10 @@ 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 java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
public class GameController {
......@@ -13,13 +13,14 @@ public class GameController {
private Game model;
private PlayView view;
Float HEX_SIDE_LENGTH;
public GameController(Game model, PlayView view) {
this.model = model;
this.view = view;
this.HEX_SIDE_LENGTH = Constants.HEX_SIDE_LENGTH;
List<List<Vector3>> startFieldCoordinates = this.model.getStartFieldCoordinates();
System.out.println("Riktig kube controller: " + startFieldCoordinates.get(4).get(3));
System.out.println("Over t.v. controller: " + startFieldCoordinates.get(4).get(2));
List<List<Float[]>> startFieldCoordinatesPixel = new ArrayList<>();
......@@ -27,13 +28,7 @@ public class GameController {
List<Float[]> coordinateSetPixel = new ArrayList<>();
for (Vector3 coordinate : coordinateSet) {
coordinateSetPixel.add(UtilsKt.cubeToPixel(coordinate, 38F));
if (coordinate.x == -5F && coordinate.y == 2F && coordinate.z == 3F) {
System.out.println("Over t.v. controller: " + Arrays.toString(UtilsKt.cubeToPixel(coordinate, 38F)));
}
if (coordinate.x == -5F && coordinate.y == 1F && coordinate.z == 4F) {
System.out.println("Riktig controller: " + Arrays.toString(UtilsKt.cubeToPixel(coordinate, 38F)));
}
coordinateSetPixel.add(UtilsKt.cubeToPixel(coordinate, HEX_SIDE_LENGTH));
}
startFieldCoordinatesPixel.add(coordinateSetPixel);
......
......@@ -49,7 +49,7 @@ class DefaultRules: AbstractRules() {
Vector3(-6F,4F,2F), Vector3(-6F,3F,3F), Vector3(-6F,2F,4F), Vector3(-7F,4F,3F),
Vector3(-7F, 3F, 4F), Vector3(-8F,4F,4F)
),
listOf( Vector3(-1F,5F,4F), Vector3(-2F,5F,-3F), Vector3(-3F,5F,-2F), Vector3(-4F,5F,-1F),
listOf( Vector3(-1F,5F,-4F), Vector3(-2F,5F,-3F), Vector3(-3F,5F,-2F), Vector3(-4F,5F,-1F),
Vector3(-2F,6F,-4F), Vector3(-3F,6F,-3F), Vector3(-4F,6F,-2F), Vector3(-3F,7F,-4F),
Vector3(-4F,7F,-3F), Vector3(-4F,8F,-4F)
)
......
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;
}
......@@ -3,10 +3,8 @@ package com.mygdx.game.views;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.assets.AssetManager;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.Pixmap;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.scenes.scene2d.Stage;
import com.badlogic.gdx.scenes.scene2d.ui.Image;
import com.badlogic.gdx.scenes.scene2d.ui.Skin;
......@@ -27,6 +25,8 @@ public class PlayView extends View{
private Texture background;
private Image backgroundImage;
Float BOARD_SCALE_FACTOR;
int Help_Guides = 12;
int row_height = Gdx.graphics.getHeight() / Help_Guides;
int col_width = Gdx.graphics.getWidth() / Help_Guides;
......@@ -45,9 +45,11 @@ public class PlayView extends View{
background = new Texture("Game/1x/GameBoard@1x.png");
this.backgroundImage = new Image(background);
backgroundImage.setScaleX(0.25F);
backgroundImage.setScaleY(0.25F);
backgroundImage.setScaling(Scaling.fill);
this.BOARD_SCALE_FACTOR = Constants.SCALE_FACTOR_BOARD;
backgroundImage.setScaleX(BOARD_SCALE_FACTOR);
backgroundImage.setScaleY(BOARD_SCALE_FACTOR);
//backgroundImage.setScaling(Scaling.fit);
backgroundImage.setPosition(Gdx.graphics.getWidth() / 2F - backgroundImage.getWidth() * backgroundImage.getScaleX() / 2F, Gdx.graphics.getHeight() / 2F - backgroundImage.getHeight() * backgroundImage.getScaleY() / 2F);
stage.addActor(backgroundImage);
......@@ -82,8 +84,8 @@ public class PlayView extends View{
int x = Gdx.input.getX() - (Gdx.graphics.getWidth() / 2);
int y = Gdx.input.getY() - (Gdx.graphics.getHeight() / 2);
System.out.println("Midtstilt: " + x + ", " + y);
System.out.println("Vanlig: " + Gdx.input.getX() + " " + Gdx.input.getY());
System.out.println("Centered: " + x + ", " + y);
System.out.println("Normal : " + Gdx.input.getX() + ", " + Gdx.input.getY());
}
}
......@@ -102,29 +104,27 @@ public class PlayView extends View{
stage.draw();
//StarPiece piece = new StarPiece(500, 200, Color.RED, starPieceBase, starPieceBaseBorder, starPieceMast, starPieceMastBorder, starPieceHead, starPieceHeadBorder);
//piece.draw(stage.getBatch());
for (StarPiece piece : pieces.values()) {
piece.draw(stage.getBatch());
}
}
public void initializePieces(List<List<Float[]>> coordinates) {
//System.out.println("View: " + Arrays.toString(coordinates.get(4).get(3)));
System.out.println("Riktig + midt view: " + coordinates.get(4).get(3)[1] + (Gdx.graphics.getHeight() / 2F));
System.out.println("Over t.v + midt view: " + coordinates.get(4).get(2)[1] + (Gdx.graphics.getHeight() / 2F));
List<Color> colors = Arrays.asList(Color.PINK, Color.CYAN, Color.LIME, Color.GOLD, Color.LIGHT_GRAY, Color.PURPLE);
Color color;
int colorCounter = 0;
for (List<Float[]> coordinateSet : coordinates) {
for (Float[] coordinate : coordinateSet) {
coordinate[0] += Gdx.graphics.getWidth() / 2F;//-= piece.getWidth() / 2;
coordinate[1] += Gdx.graphics.getHeight() / 2F;//-= piece.getHeight() / 2;
Color color = Color.RED;
if (coordinate[1] > Gdx.graphics.getHeight() / 2F) {
color = Color.BLACK;
}
coordinate[0] += Gdx.graphics.getWidth() / 2F - (starPieceBase.getWidth() * 0.035F) / 2F;
coordinate[1] = Gdx.graphics.getHeight() / 2F - coordinate[1] - (starPieceBase.getHeight() * 0.035F) / 2F; // Adjust for inverted y-axis
color = colors.get(colorCounter);
StarPiece piece = new StarPiece(coordinate[0], coordinate[1], color, starPieceBase, starPieceBaseBorder, starPieceMast, starPieceMastBorder, starPieceHead, starPieceHeadBorder);
piece.setRotateHead(true);
pieces.put(coordinate, piece);
}
colorCounter++;
}
}
......
......@@ -4,6 +4,7 @@ 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 {
......@@ -21,6 +22,8 @@ public class StarPiece {
private boolean rotateHead;
private float headRotation = 1;
Float SCALE_FACTOR;
public StarPiece (float xPos, float yPos, Color color, Texture base, Texture baseBorder, Texture mast, Texture mastBorder, Texture head, Texture headBorder){
this.xPos = xPos;
......@@ -34,9 +37,9 @@ public class StarPiece {
this.head = head;
this.headBorder = headBorder;
this.rotateHead=false;
}
Float SCALE_FACTOR = 0.04F;
this.SCALE_FACTOR = Constants.SCALE_FACTOR_PIECE;
}
public void draw(Batch sb){
Color sbColor = sb.getColor();
......@@ -104,7 +107,6 @@ public class StarPiece {
this.rotateHead = rotateHead;
}
public void setX(float xPos){
this.xPos = xPos;
}
......@@ -129,10 +131,4 @@ public class StarPiece {
this.xPos = xPos;
this.yPos = yPos;
}
}
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