diff --git a/core/src/com/monjaro/gamejam/main/Decay.java b/core/src/com/monjaro/gamejam/main/Decay.java new file mode 100644 index 0000000..7fdc0d9 --- /dev/null +++ b/core/src/com/monjaro/gamejam/main/Decay.java @@ -0,0 +1,15 @@ +package com.monjaro.gamejam.main; + +import java.util.List; + +public abstract class Decay { + + protected String description; + + public abstract List getDecayed(List dice); + + public String getDescription() { + return description; + } + +} diff --git a/core/src/com/monjaro/gamejam/main/Die.java b/core/src/com/monjaro/gamejam/main/Die.java index b0a420d..0c98816 100644 --- a/core/src/com/monjaro/gamejam/main/Die.java +++ b/core/src/com/monjaro/gamejam/main/Die.java @@ -61,7 +61,8 @@ public class Die extends Actor { public void decay() { //remove a pip from all faces of this die for (Face face : faces) { List pips = face.getPips(); - Face.Pip decayed = pips.get(random.nextInt()); + if (pips.isEmpty()) continue; + Face.Pip decayed = pips.get(random.nextInt(pips.size())); face.removePip(decayed); } } diff --git a/core/src/com/monjaro/gamejam/main/Game.java b/core/src/com/monjaro/gamejam/main/Game.java index fe20b7c..026c1f2 100644 --- a/core/src/com/monjaro/gamejam/main/Game.java +++ b/core/src/com/monjaro/gamejam/main/Game.java @@ -6,7 +6,6 @@ import com.badlogic.gdx.Input; import com.badlogic.gdx.graphics.Texture; import com.badlogic.gdx.graphics.g2d.BitmapFont; import com.badlogic.gdx.graphics.g2d.SpriteBatch; -import com.badlogic.gdx.math.Vector2; import com.badlogic.gdx.utils.ScreenUtils; import com.monjaro.gamejam.SegmentUI; import com.monjaro.gamejam.segment.DualSegment; @@ -20,7 +19,6 @@ import java.util.List; public class Game extends ApplicationAdapter { private final List dice = new ArrayList<>(); - private final List segments = new ArrayList<>(); private SpriteBatch batch; private BitmapFont font; @@ -29,8 +27,7 @@ public class Game extends ApplicationAdapter { private final static int TICKS_PER_SECOND = 60; private double tickProgress = 0; - - private RoundData roundData; + private Round round; private UI ui; private SegmentUI segUi; @@ -41,55 +38,67 @@ public class Game extends ApplicationAdapter { font.getData().markupEnabled = true; img = new Texture("badlogic.jpg"); - ui = new UI(50, 280, 10); - roundData = new RoundData(10); segUi = new SegmentUI(); + ui = new UI(this, 50, 280); + round = new Round(List.of(new OlympicSegment(1), new OlympicSegment(3), new KinSegment(3), new DualSegment(false)), List.of(new ParityDecay(true)), 5); + 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; for (int i = 0; i < 5; i++) { dice.add(new Die(divide * (i + 1), 350, 64, 64)); } - - for (int i = 1; i <= 5; i++) { - segments.add(new KinSegment(i)); - } - for (int i = 2; i <= 5; i++) { - segments.add(new OlympicSegment(i)); - } - segments.add(new DualSegment(false)); - segments.add(new DualSegment(true)); } public void tick() { processInput(); - ui.setRemainingRerolls(roundData.getRerolls()); + ui.setRerolls(round.getRerolls()); } public void processInput() { Input input = Gdx.input; - 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); + if (input.isKeyJustPressed(Input.Keys.R) && round.getRerolls() > 0) { //reroll dice that aren't locked + reroll(); + round.reduceRerolls(0); } - 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 - int keyCode = Input.Keys.NUM_1 + i; //keycode for the current die, 1, 2...9, 0 on keyboard + if (input.isKeyPressed(Input.Keys.SHIFT_LEFT)) { + for (int i = 0; i < round.getSegments().size(); i++) { + int keyCode = Input.Keys.NUM_1 + i; //keycode for the current segment, shift + 1, 2...9, 0 on keyboard - if (input.isKeyJustPressed(keyCode)) { //if key corresponding to die has been pressed - die.setSelected(!die.isSelected()); //flip lock state + if (input.isKeyJustPressed(keyCode)) { + Segment segment = round.getSegments().get(i); + + if (segment.isDestroyedBy(getSelectedDice())) { //if can be destroyed with selected + segment.destroy(); + round.getDecays().forEach(d -> d.getDecayed(getSelectedDice()).forEach(Die::decay)); //apply all decay rules + dice.forEach(d -> d.setSelected(false)); +// reroll(); + } + } + } + } else { + for (int i = 0; i < dice.size(); i++) { //lock dice, iterating over for each keycode + int keyCode = Input.Keys.NUM_1 + i; //keycode for the current die, 1, 2...9, 0 on keyboard + + if (input.isKeyJustPressed(keyCode)) { //if key corresponding to die has been pressed + Die die = dice.get(i); //die iterator is looking at + die.setSelected(!die.isSelected()); //flip lock state + } } } } + private void reroll() { + dice.stream().filter(d -> !d.isSelected()).forEach(Die::roll); + } + @Override public void render() { tickProgress += Gdx.graphics.getDeltaTime() * TICKS_PER_SECOND; @@ -107,13 +116,17 @@ public class Game extends ApplicationAdapter { } int y = Gdx.graphics.getHeight() - 50; - for (Segment segment : segments) { + for (Segment segment : round.getSegments()) { String prefix = "[#9E65A8]"; if (segment.isDestroyed()) prefix = "[#EBE5EC]"; else if (segment.isDestroyedBy(getSelectedDice())) prefix = "[#528154]"; font.draw(batch, prefix + segment.getName(), 100, y -= 20); } + y -= 50; + for (Decay decay : round.getDecays()) { + font.draw(batch, "[#9E65A8]" + decay.getDescription(), 100, y -= 20); + } //----- ui.render(batch); @@ -122,7 +135,7 @@ public class Game extends ApplicationAdapter { batch.end(); } - + @Override public void dispose() { batch.dispose(); @@ -135,4 +148,8 @@ public class Game extends ApplicationAdapter { .toList(); } + public Round getRound() { + return round; + } + } diff --git a/core/src/com/monjaro/gamejam/main/ParityDecay.java b/core/src/com/monjaro/gamejam/main/ParityDecay.java new file mode 100644 index 0000000..fdc7e6e --- /dev/null +++ b/core/src/com/monjaro/gamejam/main/ParityDecay.java @@ -0,0 +1,22 @@ +package com.monjaro.gamejam.main; + +import java.util.List; + +public class ParityDecay extends Decay { + + private final int parity; + + public ParityDecay(boolean odd) { + parity = odd ? 1 : 0; + description = "All used dice with " + (odd ? "ODD" : "EVEN") + " value decay."; + } + + @Override + public List getDecayed(List dice) { + return dice.stream() + .filter(d -> !d.isFaceBlank()) + .filter(d -> d.getFaceValue() % 2 == parity) + .toList(); + } + +} diff --git a/core/src/com/monjaro/gamejam/main/Round.java b/core/src/com/monjaro/gamejam/main/Round.java new file mode 100644 index 0000000..623daa8 --- /dev/null +++ b/core/src/com/monjaro/gamejam/main/Round.java @@ -0,0 +1,45 @@ +package com.monjaro.gamejam.main; + +import com.monjaro.gamejam.segment.Segment; + +import java.util.List; + +public class Round { + + private final List segments; + private final List decays; + private final int maxRerolls; + private int rerolls; + + public Round(List segments, List decays, int rerolls) { + this.segments = segments; + this.decays = decays; + maxRerolls = rerolls; + this.rerolls = rerolls; + } + + public List getSegments() { + return segments; + } + + public List getDecays() { + return decays; + } + + public int getMaxRerolls() { + return maxRerolls; + } + + 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/main/RoundData.java b/core/src/com/monjaro/gamejam/main/RoundData.java deleted file mode 100644 index 172176f..0000000 --- a/core/src/com/monjaro/gamejam/main/RoundData.java +++ /dev/null @@ -1,21 +0,0 @@ -package com.monjaro.gamejam.main; - -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/main/UI.java b/core/src/com/monjaro/gamejam/main/UI.java index 66db787..241d6ac 100644 --- a/core/src/com/monjaro/gamejam/main/UI.java +++ b/core/src/com/monjaro/gamejam/main/UI.java @@ -5,17 +5,16 @@ import com.badlogic.gdx.graphics.Texture; import com.badlogic.gdx.graphics.g2d.SpriteBatch; public class UI extends Actor{ - private Transform position; + + private final Game game; + private final Transform position; private static Texture rerollTexture; private int rerolls; - private int remainingRerolls; - public UI(int x, int y, int rerolls) - { + public UI(Game game, int x, int y) { + this.game = game; position = new Transform(x, y, 0, 0); - this.rerolls = rerolls; - this.remainingRerolls = rerolls; } public void setPosition(int x, int y){ @@ -23,7 +22,9 @@ public class UI extends Actor{ position.y = y; } - public void setRemainingRerolls(int x){remainingRerolls = x;} + public void setRerolls(int x){ + rerolls = x; + } public static void setRerollTexture(Texture texture){rerollTexture = texture;} @@ -34,8 +35,8 @@ public class UI extends Actor{ @Override public void render(SpriteBatch batch) { - for (int i = 0; i < rerolls; i++) { - if (i > remainingRerolls-1) + for (int i = 0; i < game.getRound().getMaxRerolls(); i++) { + if (i >= game.getRound().getRerolls()) batch.setColor(Color.GRAY); batch.draw(rerollTexture, (position.x + (40f*i)), (position.y)); batch.setColor(Color.WHITE); diff --git a/core/src/com/monjaro/gamejam/segment/OlympicSegment.java b/core/src/com/monjaro/gamejam/segment/OlympicSegment.java index c1fb365..3236ad7 100644 --- a/core/src/com/monjaro/gamejam/segment/OlympicSegment.java +++ b/core/src/com/monjaro/gamejam/segment/OlympicSegment.java @@ -30,15 +30,17 @@ public class OlympicSegment extends Segment { .sorted() .toList(); - int last = -1, run = 1, best = run; + int last = -1, run = 1, best = 0; for (int value : values) { if (value == last + 1) { - if (++run > best) best = run; + run++; } else { run = 1; } + if (run > best) best = run; + last = value; }