This commit is contained in:
Rosia E Evans 2024-04-21 01:31:46 +01:00
commit aef7e2c955
3 changed files with 22 additions and 26 deletions

View file

@ -16,13 +16,12 @@ public class Die extends Actor {
*/ */
private final Face[] faces = new Face[6]; private final Face[] faces = new Face[6];
private int faceIndex = 3; private int faceIndex = 3;
private boolean locked = false; private boolean selected = false;
private static Texture lockedSprite; private static Texture lockedSprite;
private final Random random = new Random(); //TODO use central random private final Random random = new Random(); //TODO use central random
public Die(float x, float y, float width, float height) { public Die(float x, float y, float width, float height) {
transform = new Transform(x, y, width, height); transform = new Transform(x, y, width, height);
@ -79,14 +78,14 @@ public class Die extends Actor {
return getFaceValue() <= 0; return getFaceValue() <= 0;
} }
public boolean isLocked() { public boolean isSelected() {
return locked; return selected;
} }
public void setLocked(boolean locked) { public void setSelected(boolean selected) {
if (locked != this.locked) if (selected != this.selected)
{ {
if (locked) { if (selected) {
transform.y += 64; transform.y += 64;
transform.rotation = 20; transform.rotation = 20;
} }
@ -96,7 +95,7 @@ public class Die extends Actor {
} }
} // terrible } // terrible
this.locked = locked; this.selected = selected;
} }
} }

View file

@ -13,14 +13,10 @@ import com.monjaro.gamejam.segment.KinSegment;
import com.monjaro.gamejam.segment.Segment; import com.monjaro.gamejam.segment.Segment;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Set;
public class Game extends ApplicationAdapter { public class Game extends ApplicationAdapter {
private final Set<Actor> actors = new HashSet<>();
private final List<Die> dice = new ArrayList<>(); private final List<Die> dice = new ArrayList<>();
private final List<Segment> segments = new ArrayList<>(); private final List<Segment> segments = new ArrayList<>();
@ -57,15 +53,13 @@ public class Game extends ApplicationAdapter {
public void tick() { public void tick() {
processInput(); processInput();
actors.forEach(Actor::tick);
} }
public void processInput() { public void processInput() {
Input input = Gdx.input; Input input = Gdx.input;
if (input.isKeyJustPressed(Input.Keys.R)) { //reroll dice that aren't locked 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)); System.out.println("=".repeat(100));
for (Segment segment : segments) { for (Segment segment : segments) {
@ -78,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 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 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
} }
} }
} }
@ -94,8 +88,6 @@ public class Game extends ApplicationAdapter {
ScreenUtils.clear(0, 0, 0, 1); ScreenUtils.clear(0, 0, 0, 1);
batch.begin(); batch.begin();
actors.forEach(a -> a.render(batch));
//TODO debug //TODO debug
for (Die die : dice) { for (Die die : dice) {
die.render(batch); die.render(batch);
@ -105,7 +97,7 @@ public class Game extends ApplicationAdapter {
for (Segment segment : segments) { for (Segment segment : segments) {
String prefix = "[#9E65A8]"; String prefix = "[#9E65A8]";
if (segment.isDestroyed()) prefix = "[#EBE5EC]"; 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); font.draw(batch, prefix + segment.getName(), x += 75, Gdx.graphics.getHeight() - 100);
} }
@ -120,12 +112,10 @@ public class Game extends ApplicationAdapter {
img.dispose(); img.dispose();
} }
private void addActor(Actor actor) { public List<Die> getSelectedDice() {
actors.add(actor); return dice.stream()
} .filter(d -> !d.isSelected())
.toList();
private void removeActor(Actor actor) {
actors.remove(actor);
} }
} }

View file

@ -3,7 +3,14 @@ package com.monjaro.gamejam;
import com.badlogic.gdx.graphics.g2d.SpriteBatch; import com.badlogic.gdx.graphics.g2d.SpriteBatch;
public class UI extends Actor{ public class UI extends Actor{
Transform transform private Transform position;
private Texture
public void setPosition(int x, int y){
position.x = x;
position.y = y;
}
@Override @Override
public void tick() { public void tick() {