fixes and finalises die faces
This commit is contained in:
parent
2544da0313
commit
65377d8384
4 changed files with 25 additions and 9 deletions
|
@ -29,6 +29,17 @@ public class Die extends Actor {
|
|||
shape = new Rectangle();
|
||||
}
|
||||
|
||||
public Die(float x, float y, float width, float height) {
|
||||
int[] pips = {4, 6, 5, 1, 2, 3};
|
||||
for (int i = 0; i < faces.length; i++) {
|
||||
faces[i] = new Face(pips[i]);
|
||||
faces[i].setPosition(x, y);
|
||||
faces[i].setSize(width, height);
|
||||
}
|
||||
shape = new Rectangle(x, y, width, height);
|
||||
|
||||
}
|
||||
|
||||
public void setPosition(float x, float y){
|
||||
shape.setX(x);
|
||||
shape.setY(y);
|
||||
|
|
|
@ -12,7 +12,7 @@ import java.util.List;
|
|||
|
||||
public class Face extends Actor{
|
||||
|
||||
private Rectangle shape;
|
||||
private Rectangle shape = new Rectangle();
|
||||
|
||||
private final List<Pip> pips = new ArrayList<>();
|
||||
|
||||
|
@ -77,18 +77,19 @@ public class Face extends Actor{
|
|||
shape.setSize(w, h);
|
||||
}
|
||||
|
||||
public void setBlankFaceSprite(Texture sprite){
|
||||
public static void setBlankFaceSprite(Texture sprite){
|
||||
blankFaceSprite = sprite;
|
||||
}
|
||||
|
||||
public void setPipSprite(Texture sprite){
|
||||
public static void setPipSprite(Texture sprite){
|
||||
pipSprite = sprite;
|
||||
}
|
||||
|
||||
public Vector2 getPipLocationFromPercentage(Vector2 percentages)
|
||||
{
|
||||
Vector2 position = new Vector2(shape.x + (shape.width*percentages.x/100f) + (float)pipSprite.getWidth()/2,
|
||||
shape.y + shape.width*percentages.y/100f + (float)pipSprite.getHeight()/2);
|
||||
Vector2 position = new Vector2(
|
||||
shape.x + (shape.width*percentages.x/100f) - (float)pipSprite.getWidth()/2,
|
||||
shape.y + shape.width*percentages.y/100f - (float)pipSprite.getHeight()/2);
|
||||
|
||||
return position;
|
||||
}
|
||||
|
|
|
@ -33,8 +33,11 @@ public class Game extends ApplicationAdapter {
|
|||
font = new BitmapFont();
|
||||
img = new Texture("badlogic.jpg");
|
||||
|
||||
for (int i = 0; i < 5; i++) {
|
||||
dice.add(new Die());
|
||||
Face.setBlankFaceSprite(new Texture("blank_die_face.png"));
|
||||
Face.setPipSprite(new Texture("pip.png"));
|
||||
|
||||
for (int i = 1; i <= 5; i++) {
|
||||
dice.add(new Die((i*80), 20, 64, 64));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -68,8 +71,7 @@ public class Game extends ApplicationAdapter {
|
|||
//TODO debug
|
||||
int x = 100;
|
||||
for (Die die : dice) {
|
||||
batch.setColor(Color.WHITE);
|
||||
font.draw(batch, String.valueOf(die.getFaceValue()), x += 50, 100);
|
||||
die.render(batch);
|
||||
}
|
||||
//-----
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue