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

Scaled pieces

parent 7b2a6d5f
......@@ -5,6 +5,7 @@ import com.mygdx.game.model.Game;
import com.mygdx.game.views.PlayView;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
public class GameController {
......@@ -17,6 +18,8 @@ public class GameController {
this.view = view;
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<>();
......@@ -24,7 +27,13 @@ public class GameController {
List<Float[]> coordinateSetPixel = new ArrayList<>();
for (Vector3 coordinate : coordinateSet) {
coordinateSetPixel.add(UtilsKt.cubeToPixel(coordinate, 100F));
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)));
}
}
startFieldCoordinatesPixel.add(coordinateSetPixel);
......
......@@ -17,6 +17,7 @@ import com.mygdx.game.views.tokens.AnimatedSprite;
import com.mygdx.game.views.tokens.StarPiece;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
......@@ -82,7 +83,7 @@ public class PlayView extends View{
int y = Gdx.input.getY() - (Gdx.graphics.getHeight() / 2);
System.out.println("Midtstilt: " + x + ", " + y);
System.out.println("Vanlig: " + Gdx.input.getX());
System.out.println("Vanlig: " + Gdx.input.getX() + " " + Gdx.input.getY());
}
}
......@@ -101,16 +102,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));
for (List<Float[]> coordinateSet : coordinates) {
for (Float[] coordinate : coordinateSet) {
StarPiece piece = new StarPiece(coordinate[0], coordinate[1], Color.RED, starPieceBase, starPieceBaseBorder, starPieceMast, starPieceMastBorder, starPieceHead, starPieceHeadBorder);
//piece.setRotateHead(true);
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;
}
StarPiece piece = new StarPiece(coordinate[0], coordinate[1], color, starPieceBase, starPieceBaseBorder, starPieceMast, starPieceMastBorder, starPieceHead, starPieceHeadBorder);
piece.setRotateHead(true);
pieces.put(coordinate, piece);
}
}
......
......@@ -36,32 +36,33 @@ public class StarPiece {
this.rotateHead=false;
}
Float SCALE_FACTOR = 0.04F;
public void draw(Batch sb){
Color sbColor = sb.getColor();
sb.begin();
sb.setColor(color);
sb.draw(base, xPos, yPos);
sb.draw(base, xPos, yPos, base.getWidth() * SCALE_FACTOR, base.getHeight() * SCALE_FACTOR);
sb.setColor(Color.BLACK);
sb.draw(baseBorder, xPos, yPos);
sb.draw(baseBorder, xPos, yPos, baseBorder.getWidth() * SCALE_FACTOR, baseBorder.getHeight() * SCALE_FACTOR);
sb.setColor(color);
sb.draw(mast, xPos+base.getWidth()/2-mast.getWidth()/2, yPos+base.getHeight()*0.35f);
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()/2-mast.getWidth()/2, yPos+base.getHeight()*0.35f);
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()/2-head.getWidth()/2,
yPos+base.getHeight()-head.getWidth()/2,
head.getWidth()/2,
head.getHeight()/2,
head.getWidth(),
head.getHeight(),
1f,
1f,
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++,
0,
0,
......@@ -72,14 +73,14 @@ public class StarPiece {
sb.setColor(Color.BLACK);
sb.draw(headBorder,
xPos+base.getWidth()/2-head.getWidth()/2,
yPos+base.getHeight()-head.getWidth()/2,
head.getWidth()/2,
head.getHeight()/2,
head.getWidth(),
head.getHeight(),
1f,
1f,
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++,
0,
0,
......@@ -90,9 +91,9 @@ public class StarPiece {
}
else{
sb.setColor(color);
sb.draw(head, xPos+base.getWidth()/2-head.getWidth()/2, yPos+base.getHeight()-head.getWidth()/2);
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()/2-head.getWidth()/2, yPos+base.getHeight()-head.getWidth()/2);
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);
......@@ -120,6 +121,10 @@ public class StarPiece {
return yPos;
}
public float getWidth() { return base.getWidth() * SCALE_FACTOR;}
public float getHeight() { return base.getHeight() * SCALE_FACTOR;}
public void setPosition(float xPos, float yPos){
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