From eb526de0fa95d25935b161724eeab97c43236dd6 Mon Sep 17 00:00:00 2001 From: Rosia E Evans Date: Sun, 21 Apr 2024 02:37:52 +0100 Subject: [PATCH] rerolls --- core/src/com/monjaro/gamejam/Game.java | 15 ++++++++++++- core/src/com/monjaro/gamejam/RoundData.java | 21 +++++++++++++++++ core/src/com/monjaro/gamejam/UI.java | 25 +++++++++++++++++++-- 3 files changed, 58 insertions(+), 3 deletions(-) create mode 100644 core/src/com/monjaro/gamejam/RoundData.java diff --git a/core/src/com/monjaro/gamejam/Game.java b/core/src/com/monjaro/gamejam/Game.java index e4d4462..45de8fe 100644 --- a/core/src/com/monjaro/gamejam/Game.java +++ b/core/src/com/monjaro/gamejam/Game.java @@ -27,6 +27,10 @@ public class Game extends ApplicationAdapter { private final static int TICKS_PER_SECOND = 60; private double tickProgress = 0; + + private RoundData roundData; + private UI ui; + @Override public void create() { batch = new SpriteBatch(); @@ -34,9 +38,13 @@ public class Game extends ApplicationAdapter { font.getData().markupEnabled = true; img = new Texture("badlogic.jpg"); + ui = new UI(50, 280, 10); + roundData = new RoundData(10); + Face.setBlankFaceSprite(new Texture("blank_die_face.png")); Face.setPipSprite(new Texture("pip.png")); Die.setLockedSprite(new Texture("locked_die_border.png")); + UI.setRerollTexture(new Texture("reroll_symbol.png")); Vector2 dieSize = new Vector2(); float divide = Gdx.graphics.getWidth() / 6f; @@ -53,13 +61,16 @@ public class Game extends ApplicationAdapter { public void tick() { processInput(); + + ui.setRemainingRerolls(roundData.getRerolls()); } public void processInput() { Input input = Gdx.input; - if (input.isKeyJustPressed(Input.Keys.R)) { //reroll dice that aren't locked + if (input.isKeyJustPressed(Input.Keys.R) && roundData.getRerolls() > 0) { //reroll dice that aren't locked dice.stream().filter(d -> !d.isSelected()).forEach(Die::roll); + roundData.reduceRerolls(1); System.out.println("=".repeat(100)); for (Segment segment : segments) { @@ -103,6 +114,8 @@ public class Game extends ApplicationAdapter { } //----- + ui.render(batch); + batch.end(); } diff --git a/core/src/com/monjaro/gamejam/RoundData.java b/core/src/com/monjaro/gamejam/RoundData.java new file mode 100644 index 0000000..ddad07d --- /dev/null +++ b/core/src/com/monjaro/gamejam/RoundData.java @@ -0,0 +1,21 @@ +package com.monjaro.gamejam; + +public class RoundData { + private int rerolls; + + public RoundData(int rerolls){ + this.rerolls = rerolls; + } + + public int getRerolls() { + return rerolls; + } + + public void setRerolls(int rerolls) { + this.rerolls = rerolls; + } + + public void reduceRerolls(int i) { + rerolls -= i; + } +} diff --git a/core/src/com/monjaro/gamejam/UI.java b/core/src/com/monjaro/gamejam/UI.java index 6d3efbd..7e0b1cc 100644 --- a/core/src/com/monjaro/gamejam/UI.java +++ b/core/src/com/monjaro/gamejam/UI.java @@ -1,16 +1,32 @@ package com.monjaro.gamejam; +import com.badlogic.gdx.graphics.Color; +import com.badlogic.gdx.graphics.Texture; import com.badlogic.gdx.graphics.g2d.SpriteBatch; public class UI extends Actor{ private Transform position; - private Texture + private static Texture rerollTexture; + + private int rerolls; + private int remainingRerolls; + + public UI(int x, int y, int rerolls) + { + position = new Transform(x, y, 0, 0); + this.rerolls = rerolls; + this.remainingRerolls = rerolls; + } public void setPosition(int x, int y){ position.x = x; position.y = y; } + public void setRemainingRerolls(int x){remainingRerolls = x;} + + public static void setRerollTexture(Texture texture){rerollTexture = texture;} + @Override public void tick() { @@ -18,6 +34,11 @@ public class UI extends Actor{ @Override public void render(SpriteBatch batch) { - + for (int i = 0; i < rerolls; i++) { + if (i > remainingRerolls-1) + batch.setColor(Color.GRAY); + batch.draw(rerollTexture, (position.x + (40f*i)), (position.y)); + batch.setColor(Color.WHITE); + } } }