refactors dice face code, adds sprites

This commit is contained in:
Rosia E Evans 2024-04-20 16:14:47 +01:00
parent 808b1a8d65
commit 1eba84645e

View file

@ -3,9 +3,12 @@ import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.SpriteBatch; import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.graphics.glutils.ShapeRenderer; import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
import com.badlogic.gdx.math.Rectangle; import com.badlogic.gdx.math.Rectangle;
import com.badlogic.gdx.math.Vector2;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.Vector;
public class Face extends Actor{ public class Face extends Actor{
@ -47,21 +50,22 @@ public class Face extends Actor{
public static class Pip { public static class Pip {
private final float x, y; private final Vector2 location;
public Pip(float x, float y) { public Pip(float x, float y) {
this.x = x; location = new Vector2(x, y);
this.y = y;
} }
public float getX() { public float getX() {
return x; return location.x;
} }
public float getY() { public float getY() {
return y; return location.y;
} }
public Vector2 getVectorLocation(){return location;}
} }
public void setPosition(float x, float y){ public void setPosition(float x, float y){
@ -73,6 +77,20 @@ public class Face extends Actor{
shape.setSize(w, h); shape.setSize(w, h);
} }
public void setBlankFaceSprite(Texture sprite){
blankFaceSprite = sprite;
}
public 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);
}
@Override @Override
public void tick() { public void tick() {
@ -82,9 +100,10 @@ public class Face extends Actor{
public void render(SpriteBatch batch) { public void render(SpriteBatch batch) {
batch.draw(blankFaceSprite, shape.x, shape.y, shape.width, shape.height); batch.draw(blankFaceSprite, shape.x, shape.y, shape.width, shape.height);
for(Pip pip : pips){ for(Pip pip : pips){
Vector2 position = getPipLocationFromPercentage(pip.getVectorLocation());
batch.draw(pipSprite, batch.draw(pipSprite,
shape.x + (shape.width*pip.x/100f), position.x,
shape.y + (shape.width*pip.y/100f)); position.y);
} }
} }