From 1eba84645ea8710fe3db61d077220fe551d740c1 Mon Sep 17 00:00:00 2001 From: Rosia E Evans Date: Sat, 20 Apr 2024 16:14:47 +0100 Subject: [PATCH] refactors dice face code, adds sprites --- core/src/com/monjaro/gamejam/Face.java | 33 ++++++++++++++++++++------ 1 file changed, 26 insertions(+), 7 deletions(-) diff --git a/core/src/com/monjaro/gamejam/Face.java b/core/src/com/monjaro/gamejam/Face.java index a037166..42d7a43 100644 --- a/core/src/com/monjaro/gamejam/Face.java +++ b/core/src/com/monjaro/gamejam/Face.java @@ -3,9 +3,12 @@ import com.badlogic.gdx.graphics.Texture; import com.badlogic.gdx.graphics.g2d.SpriteBatch; import com.badlogic.gdx.graphics.glutils.ShapeRenderer; import com.badlogic.gdx.math.Rectangle; +import com.badlogic.gdx.math.Vector2; + import java.util.ArrayList; import java.util.Collections; import java.util.List; +import java.util.Vector; public class Face extends Actor{ @@ -47,21 +50,22 @@ public class Face extends Actor{ public static class Pip { - private final float x, y; + private final Vector2 location; public Pip(float x, float y) { - this.x = x; - this.y = y; + location = new Vector2(x, y); } public float getX() { - return x; + return location.x; } public float getY() { - return y; + return location.y; } + public Vector2 getVectorLocation(){return location;} + } public void setPosition(float x, float y){ @@ -73,6 +77,20 @@ public class Face extends Actor{ 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 public void tick() { @@ -82,9 +100,10 @@ public class Face extends Actor{ public void render(SpriteBatch batch) { batch.draw(blankFaceSprite, shape.x, shape.y, shape.width, shape.height); for(Pip pip : pips){ + Vector2 position = getPipLocationFromPercentage(pip.getVectorLocation()); batch.draw(pipSprite, - shape.x + (shape.width*pip.x/100f), - shape.y + (shape.width*pip.y/100f)); + position.x, + position.y); } }