diff --git a/core/src/com/monjaro/gamejam/Die.java b/core/src/com/monjaro/gamejam/Die.java index 809de37..afa6416 100644 --- a/core/src/com/monjaro/gamejam/Die.java +++ b/core/src/com/monjaro/gamejam/Die.java @@ -14,11 +14,13 @@ public class Die extends Actor { 1 2 3 4 5 */ + private final Face[] faces = new Face[6]; private int faceIndex = 3; private final Random random = new Random(); //TODO use central random + public Die() { int[] pips = {4, 6, 5, 1, 2, 3}; for (int i = 0; i < faces.length; i++) { @@ -43,9 +45,7 @@ public class Die extends Actor { @Override public void render(SpriteBatch batch) { - for (Face face : faces) { - face.render(batch); - } + faces[faceIndex].render(batch); } public void roll() { diff --git a/core/src/com/monjaro/gamejam/Face.java b/core/src/com/monjaro/gamejam/Face.java index c80aa45..a037166 100644 --- a/core/src/com/monjaro/gamejam/Face.java +++ b/core/src/com/monjaro/gamejam/Face.java @@ -1,5 +1,7 @@ package com.monjaro.gamejam; +import com.badlogic.gdx.graphics.Texture; import com.badlogic.gdx.graphics.g2d.SpriteBatch; +import com.badlogic.gdx.graphics.glutils.ShapeRenderer; import com.badlogic.gdx.math.Rectangle; import java.util.ArrayList; import java.util.Collections; @@ -11,8 +13,24 @@ public class Face extends Actor{ private final List pips = new ArrayList<>(); + private static Texture blankFaceSprite; + private static Texture pipSprite; + public Face(int pipCount) { - //ro adds pips here + addPipsForValue(pipCount); + } + + private void addPipsForValue(int value){ + int[][] positions = {{25, 25}, {75, 75}, {25, 75}, {75, 25}, {25, 50}, {75, 50}}; + + if (value%2 == 0) { + pips.add(new Pip(50, 50)); + value--; + } + + for (int i = 0; i < value ; i++) { + pips.add(new Pip(positions[i][0], positions[i][1])); + } } public int getValue() { @@ -29,18 +47,18 @@ public class Face extends Actor{ public static class Pip { - private final double x, y; + private final float x, y; - public Pip(double x, double y) { + public Pip(float x, float y) { this.x = x; this.y = y; } - public double getX() { + public float getX() { return x; } - public double getY() { + public float getY() { return y; } @@ -62,7 +80,12 @@ public class Face extends Actor{ @Override public void render(SpriteBatch batch) { - + batch.draw(blankFaceSprite, shape.x, shape.y, shape.width, shape.height); + for(Pip pip : pips){ + batch.draw(pipSprite, + shape.x + (shape.width*pip.x/100f), + shape.y + (shape.width*pip.y/100f)); + } } } diff --git a/core/src/com/monjaro/gamejam/Game.java b/core/src/com/monjaro/gamejam/Game.java index f1fab6c..1afdb46 100644 --- a/core/src/com/monjaro/gamejam/Game.java +++ b/core/src/com/monjaro/gamejam/Game.java @@ -26,6 +26,7 @@ public class Game extends ApplicationAdapter { private final static int TICKS_PER_SECOND = 60; private double tickProgress = 0; + @Override public void create() { batch = new SpriteBatch();