adds die face logic and face rendering

This commit is contained in:
Rosia E Evans 2024-04-20 15:45:41 +01:00
parent beb88e80be
commit 53d2f02bae
3 changed files with 32 additions and 9 deletions

View file

@ -13,6 +13,7 @@ public class Die extends Actor {
5 5
*/ */
private Face[] faces = new Face[6]; private Face[] faces = new Face[6];
private int topFace = 0;
public Die() { public Die() {
int[] pips = {4, 6, 5, 1, 2, 3}; int[] pips = {4, 6, 5, 1, 2, 3};
@ -38,8 +39,6 @@ public class Die extends Actor {
@Override @Override
public void render(SpriteBatch batch) { public void render(SpriteBatch batch) {
for (Face face : faces) { faces[topFace].render(batch);
face.render(batch);
}
} }
} }

View file

@ -1,5 +1,7 @@
package com.monjaro.gamejam; package com.monjaro.gamejam;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.SpriteBatch; import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
import com.badlogic.gdx.math.Rectangle; import com.badlogic.gdx.math.Rectangle;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
@ -11,8 +13,24 @@ public class Face extends Actor{
private final List<Pip> pips = new ArrayList<>(); private final List<Pip> pips = new ArrayList<>();
private static Texture blankFaceSprite;
private static Texture pipSprite;
public Face(int pipCount) { 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() { public int getValue() {
@ -29,18 +47,18 @@ public class Face extends Actor{
public static class Pip { 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.x = x;
this.y = y; this.y = y;
} }
public double getX() { public float getX() {
return x; return x;
} }
public double getY() { public float getY() {
return y; return y;
} }
@ -62,7 +80,12 @@ public class Face extends Actor{
@Override @Override
public void render(SpriteBatch batch) { 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));
}
} }
} }

View file

@ -21,6 +21,7 @@ public class Game extends ApplicationAdapter {
private final static int TICKS_PER_SECOND = 60; private final static int TICKS_PER_SECOND = 60;
private double tickProgress = 0; private double tickProgress = 0;
@Override @Override
public void create() { public void create() {