From 65377d83843a82073dba4acc9cc683c3329db8eb Mon Sep 17 00:00:00 2001 From: Rosia E Evans Date: Sat, 20 Apr 2024 16:38:07 +0100 Subject: [PATCH 1/2] fixes and finalises die faces --- core/src/com/monjaro/gamejam/Die.java | 11 +++++++++++ core/src/com/monjaro/gamejam/Face.java | 11 ++++++----- core/src/com/monjaro/gamejam/Game.java | 10 ++++++---- desktop/src/com/monjaro/gamejam/DesktopLauncher.java | 2 ++ 4 files changed, 25 insertions(+), 9 deletions(-) diff --git a/core/src/com/monjaro/gamejam/Die.java b/core/src/com/monjaro/gamejam/Die.java index afa6416..ce11c7d 100644 --- a/core/src/com/monjaro/gamejam/Die.java +++ b/core/src/com/monjaro/gamejam/Die.java @@ -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); diff --git a/core/src/com/monjaro/gamejam/Face.java b/core/src/com/monjaro/gamejam/Face.java index e975c4c..fd7b482 100644 --- a/core/src/com/monjaro/gamejam/Face.java +++ b/core/src/com/monjaro/gamejam/Face.java @@ -12,7 +12,7 @@ import java.util.List; public class Face extends Actor{ - private Rectangle shape; + private Rectangle shape = new Rectangle(); private final List 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; } diff --git a/core/src/com/monjaro/gamejam/Game.java b/core/src/com/monjaro/gamejam/Game.java index d323f63..811bc01 100644 --- a/core/src/com/monjaro/gamejam/Game.java +++ b/core/src/com/monjaro/gamejam/Game.java @@ -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); } //----- diff --git a/desktop/src/com/monjaro/gamejam/DesktopLauncher.java b/desktop/src/com/monjaro/gamejam/DesktopLauncher.java index d2b9578..628e91e 100644 --- a/desktop/src/com/monjaro/gamejam/DesktopLauncher.java +++ b/desktop/src/com/monjaro/gamejam/DesktopLauncher.java @@ -11,6 +11,8 @@ public class DesktopLauncher { Lwjgl3ApplicationConfiguration config = new Lwjgl3ApplicationConfiguration(); config.setForegroundFPS(60); config.setTitle("GameJam"); + config.setWindowedMode(800, 480); + config.setResizable(false); new Lwjgl3Application(new Game(), config); } From a428fc7a87852f6d48e5195b4e4276fdc04f453c Mon Sep 17 00:00:00 2001 From: Rosia E Evans Date: Sat, 20 Apr 2024 16:49:01 +0100 Subject: [PATCH 2/2] adds variation to die faces --- core/src/com/monjaro/gamejam/Face.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/core/src/com/monjaro/gamejam/Face.java b/core/src/com/monjaro/gamejam/Face.java index fd7b482..e7e853d 100644 --- a/core/src/com/monjaro/gamejam/Face.java +++ b/core/src/com/monjaro/gamejam/Face.java @@ -8,6 +8,7 @@ import com.badlogic.gdx.math.Vector2; import java.util.ArrayList; import java.util.Collections; import java.util.List; +import java.util.Random; public class Face extends Actor{ @@ -19,6 +20,7 @@ public class Face extends Actor{ private static Texture blankFaceSprite; private static Texture pipSprite; + public Face(int pipCount) { addPipsForValue(pipCount); } @@ -53,7 +55,9 @@ public class Face extends Actor{ private final Vector2 location; public Pip(float x, float y) { - location = new Vector2(x, y); + Random rand = new Random(); + int range = 2; + location = new Vector2(x + rand.nextInt(-range, range + 1), y+ rand.nextInt(-range, range + 1)); } public float getX() {