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 new file mode 100644 index 0000000..0ab8175 --- /dev/null +++ b/core/src/com/monjaro/gamejam/main/FallingPip.java @@ -0,0 +1,50 @@ +package com.monjaro.gamejam.main; + +import com.badlogic.gdx.graphics.Texture; +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; + + private final boolean onTop; + + public FallingPip(Transform transform, boolean onTop) { + Random random = new Random(); + + this.transform = transform; + 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; + } + + @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 23378ab..fc83c0e 100644 --- a/core/src/com/monjaro/gamejam/main/Game.java +++ b/core/src/com/monjaro/gamejam/main/Game.java @@ -29,7 +29,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; @@ -71,7 +73,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(); @@ -80,6 +82,8 @@ public class Game extends ApplicationAdapter { public void tick() { processInput(); + + fallingPips.forEach(Actor::tick); } public void processInput() { @@ -156,16 +160,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); @@ -258,4 +264,8 @@ public class Game extends ApplicationAdapter { return Collections.unmodifiableList(shope); } + public void addFallingPip(FallingPip pip) { + fallingPips.add(pip); + } + }