created shope (invisible :o)

This commit is contained in:
James 2024-04-21 16:36:30 +01:00
parent 288a67e69d
commit 9b92852b77
3 changed files with 35 additions and 5 deletions

View file

@ -79,6 +79,11 @@ public class Die extends Actor {
return getFaceValue() <= 0; return getFaceValue() <= 0;
} }
public void setFace(Face face) {
faces[faceIndex] = face;
face.setTransform(transform);
}
public boolean isSelected() { public boolean isSelected() {
return selected; return selected;
} }

View file

@ -85,6 +85,10 @@ public class Face extends Actor{
transform.setSize(w, h); transform.setSize(w, h);
} }
public void setTransform(Transform transform) {
this.transform = transform;
}
public static void setBlankFaceSprite(Texture sprite){ public static void setBlankFaceSprite(Texture sprite){
blankFaceSprite = sprite; blankFaceSprite = sprite;
} }
@ -115,6 +119,7 @@ public class Face extends Actor{
face.setOrigin(face.getWidth()/2, face.getHeight()/2); face.setOrigin(face.getWidth()/2, face.getHeight()/2);
face.rotate(transform.getRotation()); face.rotate(transform.getRotation());
face.setPosition(transform.x-face.getWidth()/2, transform.y-face.getHeight()/2); face.setPosition(transform.x-face.getWidth()/2, transform.y-face.getHeight()/2);
face.draw(batch); face.draw(batch);
for(Pip pip : pips){ for(Pip pip : pips){

View file

@ -101,13 +101,29 @@ public class Game extends ApplicationAdapter {
} }
} }
} else { } else {
for (int i = 0; i < dice.size(); i++) { //lock dice, iterating over for each keycode int shopeIndex = -1;
if (input.isKeyJustPressed(Input.Keys.I)) shopeIndex = 0;
else if (input.isKeyJustPressed(Input.Keys.O)) shopeIndex = 1;
else if (input.isKeyJustPressed(Input.Keys.P)) shopeIndex = 2;
List<Die> selected = getSelectedDice();
if (selected.size() == 1 && shopeIndex != -1) {
Face face = getShopeIndex(shopeIndex);
if (face != null) {
Die die = selected.get(0);
die.setFace(face);
removeShopeIndex(shopeIndex);
}
}
for (int i = 0; i < dice.size(); i++) { //buy for or select dice, iterating over for each keycode
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)) continue;
Die die = dice.get(i); //die iterator is looking at
die.setSelected(!die.isSelected()); //flip lock state Die die = dice.get(i); //die iterator is looking at
} die.setSelected(!die.isSelected()); //flip lock state
} }
} }
} }
@ -212,6 +228,10 @@ public class Game extends ApplicationAdapter {
} }
} }
public Face getShopeIndex(int index) {
return shope.get(index);
}
public void removeShopeIndex(int index) { public void removeShopeIndex(int index) {
shope.remove(index); shope.remove(index);
shope.add(index, null); shope.add(index, null);