From f947e25af72478a080ba27d6df556fd0818829f0 Mon Sep 17 00:00:00 2001 From: James <150948866+jameslaight@users.noreply.github.com> Date: Sun, 21 Apr 2024 01:30:46 +0100 Subject: [PATCH] only selected dice beat segments --- core/src/com/monjaro/gamejam/Die.java | 15 +++++++-------- core/src/com/monjaro/gamejam/Game.java | 12 +++++++++--- 2 files changed, 16 insertions(+), 11 deletions(-) diff --git a/core/src/com/monjaro/gamejam/Die.java b/core/src/com/monjaro/gamejam/Die.java index a2cf27c..ac0f81d 100644 --- a/core/src/com/monjaro/gamejam/Die.java +++ b/core/src/com/monjaro/gamejam/Die.java @@ -16,13 +16,12 @@ public class Die extends Actor { */ private final Face[] faces = new Face[6]; private int faceIndex = 3; - private boolean locked = false; + private boolean selected = false; private static Texture lockedSprite; private final Random random = new Random(); //TODO use central random - public Die(float x, float y, float width, float height) { transform = new Transform(x, y, width, height); @@ -79,14 +78,14 @@ public class Die extends Actor { return getFaceValue() <= 0; } - public boolean isLocked() { - return locked; + public boolean isSelected() { + return selected; } - public void setLocked(boolean locked) { - if (locked != this.locked) + public void setSelected(boolean selected) { + if (selected != this.selected) { - if (locked) { + if (selected) { transform.y += 64; transform.rotation = 20; } @@ -96,7 +95,7 @@ public class Die extends Actor { } } // terrible - this.locked = locked; + this.selected = selected; } } diff --git a/core/src/com/monjaro/gamejam/Game.java b/core/src/com/monjaro/gamejam/Game.java index 6c54ca8..e4d4462 100644 --- a/core/src/com/monjaro/gamejam/Game.java +++ b/core/src/com/monjaro/gamejam/Game.java @@ -59,7 +59,7 @@ public class Game extends ApplicationAdapter { Input input = Gdx.input; if (input.isKeyJustPressed(Input.Keys.R)) { //reroll dice that aren't locked - dice.stream().filter(d -> !d.isLocked()).forEach(Die::roll); + dice.stream().filter(d -> !d.isSelected()).forEach(Die::roll); System.out.println("=".repeat(100)); for (Segment segment : segments) { @@ -72,7 +72,7 @@ public class Game extends ApplicationAdapter { 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.setLocked(!die.isLocked()); //flip lock state + die.setSelected(!die.isSelected()); //flip lock state } } } @@ -97,7 +97,7 @@ public class Game extends ApplicationAdapter { for (Segment segment : segments) { String prefix = "[#9E65A8]"; if (segment.isDestroyed()) prefix = "[#EBE5EC]"; - else if (segment.isDestroyedBy(dice)) prefix = "[#528154]"; + else if (segment.isDestroyedBy(getSelectedDice())) prefix = "[#528154]"; font.draw(batch, prefix + segment.getName(), x += 75, Gdx.graphics.getHeight() - 100); } @@ -112,4 +112,10 @@ public class Game extends ApplicationAdapter { img.dispose(); } + public List getSelectedDice() { + return dice.stream() + .filter(d -> !d.isSelected()) + .toList(); + } + }