From f95a1e9260927ba56413ea6634590c7adc614709 Mon Sep 17 00:00:00 2001 From: James <150948866+jameslaight@users.noreply.github.com> Date: Sun, 21 Apr 2024 11:36:53 +0100 Subject: [PATCH 1/3] add segments to round class --- core/src/com/monjaro/gamejam/main/Game.java | 10 +++++----- .../gamejam/main/{RoundData.java => Round.java} | 12 ++++++++++-- 2 files changed, 15 insertions(+), 7 deletions(-) rename core/src/com/monjaro/gamejam/main/{RoundData.java => Round.java} (58%) diff --git a/core/src/com/monjaro/gamejam/main/Game.java b/core/src/com/monjaro/gamejam/main/Game.java index e86a0de..286ff51 100644 --- a/core/src/com/monjaro/gamejam/main/Game.java +++ b/core/src/com/monjaro/gamejam/main/Game.java @@ -29,7 +29,7 @@ public class Game extends ApplicationAdapter { private double tickProgress = 0; - private RoundData roundData; + private Round round; private UI ui; @Override @@ -40,7 +40,7 @@ public class Game extends ApplicationAdapter { img = new Texture("badlogic.jpg"); ui = new UI(50, 280, 10); - roundData = new RoundData(10); + round = new Round(10); Face.setBlankFaceSprite(new Texture("blank_die_face.png")); Face.setPipSprite(new Texture("pip.png")); @@ -66,15 +66,15 @@ public class Game extends ApplicationAdapter { public void tick() { processInput(); - ui.setRemainingRerolls(roundData.getRerolls()); + ui.setRemainingRerolls(round.getRerolls()); } public void processInput() { Input input = Gdx.input; - if (input.isKeyJustPressed(Input.Keys.R) && roundData.getRerolls() > 0) { //reroll dice that aren't locked + if (input.isKeyJustPressed(Input.Keys.R) && round.getRerolls() > 0) { //reroll dice that aren't locked dice.stream().filter(d -> !d.isSelected()).forEach(Die::roll); - roundData.reduceRerolls(1); + round.reduceRerolls(1); } for (int i = 0; i < dice.size(); i++) { //lock dice, iterating over for each keycode diff --git a/core/src/com/monjaro/gamejam/main/RoundData.java b/core/src/com/monjaro/gamejam/main/Round.java similarity index 58% rename from core/src/com/monjaro/gamejam/main/RoundData.java rename to core/src/com/monjaro/gamejam/main/Round.java index 172176f..ca2bdf3 100644 --- a/core/src/com/monjaro/gamejam/main/RoundData.java +++ b/core/src/com/monjaro/gamejam/main/Round.java @@ -1,10 +1,17 @@ package com.monjaro.gamejam.main; -public class RoundData { +import com.monjaro.gamejam.segment.Segment; + +import java.util.List; + +public class Round { + + private final List segments; private int rerolls; - public RoundData(int rerolls){ + public Round(List segments, int rerolls){ this.rerolls = rerolls; + this.segments = segments; } public int getRerolls() { @@ -18,4 +25,5 @@ public class RoundData { public void reduceRerolls(int i) { rerolls -= i; } + } From 8c5a4f0bea7609bf1a47941f9e84be905fa16740 Mon Sep 17 00:00:00 2001 From: James <150948866+jameslaight@users.noreply.github.com> Date: Sun, 21 Apr 2024 11:39:10 +0100 Subject: [PATCH 2/3] fix argument permutation --- core/src/com/monjaro/gamejam/main/Game.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/core/src/com/monjaro/gamejam/main/Game.java b/core/src/com/monjaro/gamejam/main/Game.java index 286ff51..7bd8986 100644 --- a/core/src/com/monjaro/gamejam/main/Game.java +++ b/core/src/com/monjaro/gamejam/main/Game.java @@ -28,7 +28,6 @@ public class Game extends ApplicationAdapter { private final static int TICKS_PER_SECOND = 60; private double tickProgress = 0; - private Round round; private UI ui; @@ -40,7 +39,7 @@ public class Game extends ApplicationAdapter { img = new Texture("badlogic.jpg"); ui = new UI(50, 280, 10); - round = new Round(10); + round = new Round(new ArrayList<>(), 10); Face.setBlankFaceSprite(new Texture("blank_die_face.png")); Face.setPipSprite(new Texture("pip.png")); From 1779f3d448455849d5b426e43b4d582cf9e618a2 Mon Sep 17 00:00:00 2001 From: James <150948866+jameslaight@users.noreply.github.com> Date: Sun, 21 Apr 2024 12:40:56 +0100 Subject: [PATCH 3/3] add decay (THE THEME OF THE JAM) --- core/src/com/monjaro/gamejam/main/Decay.java | 15 +++++ core/src/com/monjaro/gamejam/main/Die.java | 3 +- core/src/com/monjaro/gamejam/main/Game.java | 65 ++++++++++++------- .../com/monjaro/gamejam/main/ParityDecay.java | 22 +++++++ core/src/com/monjaro/gamejam/main/Round.java | 20 +++++- core/src/com/monjaro/gamejam/main/UI.java | 19 +++--- .../gamejam/segment/OlympicSegment.java | 6 +- 7 files changed, 112 insertions(+), 38 deletions(-) create mode 100644 core/src/com/monjaro/gamejam/main/Decay.java create mode 100644 core/src/com/monjaro/gamejam/main/ParityDecay.java 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 7bd8986..e910a30 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.segment.DualSegment; import com.monjaro.gamejam.segment.KinSegment; @@ -19,7 +18,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; @@ -38,54 +36,65 @@ public class Game extends ApplicationAdapter { font.getData().markupEnabled = true; img = new Texture("badlogic.jpg"); - ui = new UI(50, 280, 10); - round = new Round(new ArrayList<>(), 10); + 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(round.getRerolls()); + ui.setRerolls(round.getRerolls()); } public void processInput() { Input input = Gdx.input; if (input.isKeyJustPressed(Input.Keys.R) && round.getRerolls() > 0) { //reroll dice that aren't locked - dice.stream().filter(d -> !d.isSelected()).forEach(Die::roll); - round.reduceRerolls(1); + 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; @@ -103,20 +112,24 @@ 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); batch.end(); } - + @Override public void dispose() { batch.dispose(); @@ -129,4 +142,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 index ca2bdf3..623daa8 100644 --- a/core/src/com/monjaro/gamejam/main/Round.java +++ b/core/src/com/monjaro/gamejam/main/Round.java @@ -7,11 +7,27 @@ 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, int rerolls){ - this.rerolls = 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() { 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; }