diff options
Diffstat (limited to 'test/src/ch/asynk/gdx')
-rw-r--r-- | test/src/ch/asynk/gdx/boardgame/test/AnimationsScreen.java | 17 | ||||
-rw-r--r-- | test/src/ch/asynk/gdx/boardgame/test/Assets.java | 6 | ||||
-rw-r--r-- | test/src/ch/asynk/gdx/boardgame/test/Dice.java | 76 |
3 files changed, 98 insertions, 1 deletions
diff --git a/test/src/ch/asynk/gdx/boardgame/test/AnimationsScreen.java b/test/src/ch/asynk/gdx/boardgame/test/AnimationsScreen.java index 48c1991..92791d0 100644 --- a/test/src/ch/asynk/gdx/boardgame/test/AnimationsScreen.java +++ b/test/src/ch/asynk/gdx/boardgame/test/AnimationsScreen.java @@ -28,6 +28,7 @@ public class AnimationsScreen extends AbstractScreen private final Piece panzer; private final Piece other0; private final Piece other1; + private final Dice dice; private final Camera cam; private final Board board; private final Path path; @@ -47,6 +48,9 @@ public class AnimationsScreen extends AbstractScreen this.other0.setAlpha(0f); this.other1.setAlpha(0f); + this.dice = getDice(app, 6, 1, 1); + this.dice.rollTo(6); + cam.zoom(-0.3f); cam.centerOnWorld(); @@ -79,13 +83,22 @@ public class AnimationsScreen extends AbstractScreen batch.add(FadeAnimation.obtain(other1, 0f, 1f, 1f)); animations.add(batch); animations.add(getFireAnimationBatch()); - animations.add(DelayAnimation.obtain(1f)); batch = AnimationBatch.obtain(2); batch.add(FadeAnimation.obtain(other0, 1f, 0f, 1f)); batch.add(FadeAnimation.obtain(other1, 1f, 0f, 1f)); animations.add(batch); } + private Dice getDice(final GdxBoardTest app, int col, int row, int side) + { + Dice d = new Dice(app.assets.getTexture(app.assets.DICE), 9, 16, 0.1f); + Vector2 v = new Vector2(); + this.board.centerOf(col, row, v); + d.centerOn(v.x, v.y); + d.setSide(side); + return d; + } + private Piece getPiece(final GdxBoardTest app, int col, int row, Orientation o) { Piece p = new Piece(app.assets.getTexture(app.assets.PANZER)); @@ -152,6 +165,7 @@ public class AnimationsScreen extends AbstractScreen inputBlocked = false; } + dice.animate(delta); if (animations.animate(delta)) { app.switchToMenu(); return; @@ -170,6 +184,7 @@ public class AnimationsScreen extends AbstractScreen panzer.draw(batch); other0.draw(batch); other1.draw(batch); + dice.draw(batch); animations.draw(batch); batch.end(); } diff --git a/test/src/ch/asynk/gdx/boardgame/test/Assets.java b/test/src/ch/asynk/gdx/boardgame/test/Assets.java index e1b4023..1ffece3 100644 --- a/test/src/ch/asynk/gdx/boardgame/test/Assets.java +++ b/test/src/ch/asynk/gdx/boardgame/test/Assets.java @@ -29,6 +29,8 @@ public class Assets extends ch.asynk.gdx.boardgame.Assets public static final String SHELL_FIRE_SND = "shell_fire.ogg"; public static final String EXPLOSIONS = "explosions.png"; public static final String EXPLOSION_SND = "explosion.ogg"; + public static final String DICE = "dice.png"; + public static final String DICE_SND = "dice.ogg"; private final FreeTypeFontLoaderParameter params20; private final FreeTypeFontLoaderParameter params25; @@ -79,6 +81,8 @@ public class Assets extends ch.asynk.gdx.boardgame.Assets load(SHELL_FIRE_SND, Sound.class); load(EXPLOSIONS, Texture.class); load(EXPLOSION_SND, Sound.class); + load(DICE, Texture.class); + load(DICE_SND, Sound.class); } public void unloadApp() @@ -96,5 +100,7 @@ public class Assets extends ch.asynk.gdx.boardgame.Assets unload(SHELL_FIRE_SND); unload(EXPLOSIONS); unload(EXPLOSION_SND); + unload(DICE); + unload(DICE_SND); } } diff --git a/test/src/ch/asynk/gdx/boardgame/test/Dice.java b/test/src/ch/asynk/gdx/boardgame/test/Dice.java new file mode 100644 index 0000000..b0640a5 --- /dev/null +++ b/test/src/ch/asynk/gdx/boardgame/test/Dice.java @@ -0,0 +1,76 @@ +package ch.asynk.gdx.boardgame.test; + +import com.badlogic.gdx.graphics.Texture; + +import ch.asynk.gdx.boardgame.FramedSprite; +import ch.asynk.gdx.boardgame.Drawable; +import ch.asynk.gdx.boardgame.animations.Animation; + +public class Dice extends FramedSprite implements Drawable, Animation +{ + private static int[] sides = new int[] { 64, 68, 128, 0, 76, 72 }; + private static int[][] rolls = new int[][]{ + { 25, 40, 55, 70, 85, 100, 115, 99, 83, 67, 51, 36, 37, 52, 67, 66, 65, 64 }, + { 58, 74, 59, 60, 45, 62, 78, 94, 109, 108, 123, 106, 89, 71, 70, 69, 68 }, + { 106, 121, 120, 103, 86, 70, 54, 37, 20, 19, 18, 34, 50, 51, 52, 69, 86, 103, 119, 128 }, + { 95, 79, 93, 92, 91, 90, 104, 103, 102, 85, 84, 67, 66, 65, 49, 32, 16, 0 }, + { 22, 39, 56, 73, 90, 107, 124, 128, 113, 98, 83, 68, 53, 38, 23, 0, 25, 42, 59, 76 }, + { 79, 78, 61, 76, 91, 106, 121, 120, 119, 102, 101, 84, 68, 52, 37, 38, 39, 40, 41, 58, 75, 74, 73, 72 }, + }; + private int[] roll; + private int x; + private int last; + private float dt; + private float elapsed; + + public Dice(Texture texture, int rows, int cols, float dt) + { + super(texture, rows, cols); + this.roll = null; + this.dt = dt; + } + + public void setSide(int i) + { + setFrame(sides[i - 1]); + } + + public void setFrame(int frame) + { + int row = (frame / cols); + setFrame(row, frame - (row * cols)); + } + + public void rollTo(int n) + { + roll = rolls[n - 1]; + x = 0; + last = roll.length - 1; + elapsed = 0f; + setFrame(roll[x]); + } + + @Override public void dispose() { } + + @Override public boolean completed() + { + return (roll == null); + } + + @Override public boolean animate(float delta) + { + if (roll != null) { + elapsed += delta; + if (elapsed >= dt) { + elapsed -= dt; + if (x == last) { + roll = null; + } else { + x += 1; + setFrame(roll[x]); + } + } + } + return completed(); + } +} |