From 1953e95ba22aeb568992aeadd6b1e41ea9e97676 Mon Sep 17 00:00:00 2001 From: James <150948866+jameslaight@users.noreply.github.com> Date: Sun, 21 Apr 2024 16:47:31 +0100 Subject: [PATCH 1/2] adding fallingpip --- .../com/monjaro/gamejam/main/FallingPip.java | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 core/src/com/monjaro/gamejam/main/FallingPip.java diff --git a/core/src/com/monjaro/gamejam/main/FallingPip.java b/core/src/com/monjaro/gamejam/main/FallingPip.java new file mode 100644 index 0000000..2b4a8f2 --- /dev/null +++ b/core/src/com/monjaro/gamejam/main/FallingPip.java @@ -0,0 +1,34 @@ +package com.monjaro.gamejam.main; + +import com.badlogic.gdx.graphics.g2d.SpriteBatch; +import com.badlogic.gdx.math.Vector2; + +import java.util.Random; + +public class FallingPip extends Actor { + + private final Transform transform; + private final Vector2 velocity; + private final float rotationalVelocity; + + public FallingPip(Transform transform) { + Random random = new Random(); + + this.transform = transform; + velocity = new Vector2(-1 + random.nextFloat() * 2, random.nextFloat() * 2); + rotationalVelocity = 40 * (-0.5f + random.nextFloat()); + } + + @Override + public void tick() { + transform.x += velocity.x; + transform.y += velocity.y; + transform.rotation += rotationalVelocity; + } + + @Override + public void render(SpriteBatch batch) { + + } + +} From 8d664684da1c2d599f39c6b2f1fbee8cbcca5874 Mon Sep 17 00:00:00 2001 From: James <150948866+jameslaight@users.noreply.github.com> Date: Sun, 21 Apr 2024 17:10:58 +0100 Subject: [PATCH 2/2] add falling pips woo --- core/src/com/monjaro/gamejam/main/Die.java | 9 +++++++-- core/src/com/monjaro/gamejam/main/Face.java | 4 ++++ .../com/monjaro/gamejam/main/FallingPip.java | 20 +++++++++++++++++-- core/src/com/monjaro/gamejam/main/Game.java | 18 +++++++++++++---- 4 files changed, 43 insertions(+), 8 deletions(-) diff --git a/core/src/com/monjaro/gamejam/main/Die.java b/core/src/com/monjaro/gamejam/main/Die.java index f503352..6340035 100644 --- a/core/src/com/monjaro/gamejam/main/Die.java +++ b/core/src/com/monjaro/gamejam/main/Die.java @@ -7,7 +7,8 @@ import java.util.Random; public class Die extends Actor { - private Transform transform; + private final Game game; + private final Transform transform; /* 0 @@ -22,7 +23,9 @@ public class Die extends Actor { private final Random random = new Random(); //TODO use central random - public Die(float x, float y, float width, float height) { + public Die(Game game, float x, float y, float width, float height) { + this.game = game; + transform = new Transform(x, y, width, height); int[] pips = {4, 6, 5, 1, 2, 3}; @@ -64,6 +67,8 @@ public class Die extends Actor { if (pips.isEmpty()) continue; Face.Pip decayed = pips.get(random.nextInt(pips.size())); face.removePip(decayed); + + game.addFallingPip(new FallingPip(new Transform(transform.getX(), transform.getY(), 0, 0), face.equals(getFace()))); } } diff --git a/core/src/com/monjaro/gamejam/main/Face.java b/core/src/com/monjaro/gamejam/main/Face.java index 1013b88..618170e 100644 --- a/core/src/com/monjaro/gamejam/main/Face.java +++ b/core/src/com/monjaro/gamejam/main/Face.java @@ -95,6 +95,10 @@ public class Face extends Actor{ this.transform = transform; } + public static Texture getPipSprite() { + return pipSprite; + } + public static void setBlankFaceSprite(Texture sprite){ blankFaceSprite = sprite; } diff --git a/core/src/com/monjaro/gamejam/main/FallingPip.java b/core/src/com/monjaro/gamejam/main/FallingPip.java index 2b4a8f2..0ab8175 100644 --- a/core/src/com/monjaro/gamejam/main/FallingPip.java +++ b/core/src/com/monjaro/gamejam/main/FallingPip.java @@ -1,5 +1,6 @@ package com.monjaro.gamejam.main; +import com.badlogic.gdx.graphics.Texture; import com.badlogic.gdx.graphics.g2d.SpriteBatch; import com.badlogic.gdx.math.Vector2; @@ -11,16 +12,22 @@ public class FallingPip extends Actor { private final Vector2 velocity; private final float rotationalVelocity; - public FallingPip(Transform transform) { + private final boolean onTop; + + public FallingPip(Transform transform, boolean onTop) { Random random = new Random(); this.transform = transform; - velocity = new Vector2(-1 + random.nextFloat() * 2, random.nextFloat() * 2); + velocity = new Vector2(5 * (-0.5f + random.nextFloat()), 2 + random.nextFloat() * 3); rotationalVelocity = 40 * (-0.5f + random.nextFloat()); + + this.onTop = onTop; } @Override public void tick() { + velocity.y -= 9.81 / 60; //gravity + transform.x += velocity.x; transform.y += velocity.y; transform.rotation += rotationalVelocity; @@ -28,7 +35,16 @@ public class FallingPip extends Actor { @Override public void render(SpriteBatch batch) { + Texture sprite = Face.getPipSprite(); + batch.draw(sprite, transform.x, transform.y); + } + public boolean isOffScreen() { + return transform.y <= 25; + } + + public boolean isOnTop() { + return onTop; } } diff --git a/core/src/com/monjaro/gamejam/main/Game.java b/core/src/com/monjaro/gamejam/main/Game.java index afdd364..7262bdc 100644 --- a/core/src/com/monjaro/gamejam/main/Game.java +++ b/core/src/com/monjaro/gamejam/main/Game.java @@ -27,7 +27,9 @@ public class Game extends ApplicationAdapter { private Round round; private int roundNumber = 0; - private List shope = new ArrayList<>(); + private final List shope = new ArrayList<>(); + + private final List fallingPips = new ArrayList<>(); private UI ui; private SegmentUI segUi; @@ -66,7 +68,7 @@ public class Game extends ApplicationAdapter { float divide = Gdx.graphics.getWidth() / 6f; for (int i = 0; i < 5; i++) { - dice.add(new Die(divide * (i + 1), 350, 64, 64)); + dice.add(new Die(this, divide * (i + 1), 350, 64, 64)); } reroll(); @@ -75,6 +77,8 @@ public class Game extends ApplicationAdapter { public void tick() { processInput(); + + fallingPips.forEach(Actor::tick); } public void processInput() { @@ -149,16 +153,18 @@ public class Game extends ApplicationAdapter { ScreenUtils.clear(0, 0, 0, 1); batch.begin(); - //TODO debug + for (FallingPip pip : fallingPips) if (!pip.isOnTop()) pip.render(batch); + for (Die die : dice) { die.render(batch); } + for (FallingPip pip : fallingPips) if (pip.isOnTop()) pip.render(batch); //on top + int y = Gdx.graphics.getHeight() / 3 * 2 - 25; for (Decay decay : round.getDecays()) { font.draw(batch, "[#9E65A8]" + decay.getDescription(), 100, y -= 20); } - //----- ui.render(batch); @@ -249,4 +255,8 @@ public class Game extends ApplicationAdapter { return Collections.unmodifiableList(shope); } + public void addFallingPip(FallingPip pip) { + fallingPips.add(pip); + } + }