add coloured segments

This commit is contained in:
James 2024-04-21 00:29:18 +01:00
parent 64b12d17a6
commit 01cc43540c
2 changed files with 21 additions and 5 deletions

View file

@ -4,6 +4,7 @@ import com.badlogic.gdx.ApplicationAdapter;
import com.badlogic.gdx.Gdx; import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Input; import com.badlogic.gdx.Input;
import com.badlogic.gdx.graphics.Texture; import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.BitmapFont;
import com.badlogic.gdx.graphics.g2d.SpriteBatch; import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.utils.ScreenUtils; import com.badlogic.gdx.utils.ScreenUtils;
import com.monjaro.gamejam.segment.DualSegment; import com.monjaro.gamejam.segment.DualSegment;
@ -23,6 +24,7 @@ public class Game extends ApplicationAdapter {
private final List<Segment> segments = new ArrayList<>(); private final List<Segment> segments = new ArrayList<>();
private SpriteBatch batch; private SpriteBatch batch;
private BitmapFont font;
private Texture img; private Texture img;
private final static int TICKS_PER_SECOND = 60; private final static int TICKS_PER_SECOND = 60;
@ -31,6 +33,8 @@ public class Game extends ApplicationAdapter {
@Override @Override
public void create() { public void create() {
batch = new SpriteBatch(); batch = new SpriteBatch();
font = new BitmapFont();
font.getData().markupEnabled = true;
img = new Texture("badlogic.jpg"); img = new Texture("badlogic.jpg");
Face.setBlankFaceSprite(new Texture("blank_die_face.png")); Face.setBlankFaceSprite(new Texture("blank_die_face.png"));
@ -65,7 +69,6 @@ public class Game extends ApplicationAdapter {
} }
} }
for (int i = 0; i < dice.size(); i++) { //lock dice, iterating over for each keycode for (int i = 0; i < dice.size(); i++) { //lock dice, iterating over for each keycode
Die die = dice.get(i); //die iterator is looking at Die die = dice.get(i); //die iterator is looking at
int keyCode = Input.Keys.NUM_1 + i; //keycode for the current die, 1, 2...9, 0 on keyboard int keyCode = Input.Keys.NUM_1 + i; //keycode for the current die, 1, 2...9, 0 on keyboard
@ -93,6 +96,15 @@ public class Game extends ApplicationAdapter {
for (Die die : dice) { for (Die die : dice) {
die.render(batch); die.render(batch);
} }
int x = 50;
for (Segment segment : segments) {
String prefix = "[#9E65A8]";
if (segment.isDestroyed()) prefix = "[#EBE5EC]";
else if (segment.isDestroyedBy(dice)) prefix = "[#528154]";
font.draw(batch, prefix + segment.getName(), x += 75, Gdx.graphics.getHeight() - 100);
}
//----- //-----
batch.end(); batch.end();

View file

@ -18,10 +18,6 @@ public abstract class Segment {
public abstract boolean isDestroyedBy(List<Die> die); public abstract boolean isDestroyedBy(List<Die> die);
public String getName() {
return name;
}
protected Map<Integer, Integer> countValues(List<Die> dice) { protected Map<Integer, Integer> countValues(List<Die> dice) {
Map<Integer, Integer> counts = new HashMap<>(); Map<Integer, Integer> counts = new HashMap<>();
@ -35,4 +31,12 @@ public abstract class Segment {
return counts; return counts;
} }
public String getName() {
return name;
}
public boolean isDestroyed() {
return destroyed;
}
} }