This commit is contained in:
Rosia E Evans 2024-04-20 15:47:21 +01:00
commit 808b1a8d65
3 changed files with 27 additions and 7 deletions

View file

@ -4,6 +4,7 @@ package com.monjaro.gamejam;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
public abstract class Actor {
public abstract void tick();
public abstract void render(SpriteBatch batch);

View file

@ -1,19 +1,25 @@
package com.monjaro.gamejam;
import com.badlogic.gdx.math.Rectangle;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.math.Rectangle;
import java.util.List;
import java.util.Random;
public class Die extends Actor {
private Rectangle shape;
private final Rectangle shape;
/*
0
1 2 3 4
5
*/
private Face[] faces = new Face[6];
private int topFace = 0;
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};
@ -39,6 +45,19 @@ public class Die extends Actor {
@Override
public void render(SpriteBatch batch) {
faces[topFace].render(batch);
faces[faceIndex].render(batch);
}
public void roll() {
faceIndex = random.nextInt(6);
}
public void decay() { //remove a pip from all faces of this die
for (Face face : faces) {
List<Face.Pip> pips = face.getPips();
Face.Pip decayed = pips.get(random.nextInt());
face.removePip(decayed);
}
}
}