From 05cfb4a8b3af26d00cbd0c6931ee96a5ad075af2 Mon Sep 17 00:00:00 2001 From: Timothée Floure Date: Mon, 23 May 2016 13:51:42 +0200 Subject: Fix players movements (don't walk if stopped) --- src/ch/epfl/xblast/server/painter/PlayerPainter.java | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) (limited to 'src/ch/epfl') diff --git a/src/ch/epfl/xblast/server/painter/PlayerPainter.java b/src/ch/epfl/xblast/server/painter/PlayerPainter.java index 79b954c..eb450d6 100644 --- a/src/ch/epfl/xblast/server/painter/PlayerPainter.java +++ b/src/ch/epfl/xblast/server/painter/PlayerPainter.java @@ -24,12 +24,17 @@ public final class PlayerPainter { private static final int ANIMATION_TICK_LOOP = 4; /** - * Computes and returns the animation frame byte for the given tick. + * Computes and returns the animation frame byte for the given tick if the player is moving. * * @param tick the tick + * @param player the player * @return the frame byte */ - private static byte byteForFrame(int tick) { + private static byte byteForFrame(Player player,int tick) { + // if the player is stopped + if (player.directedPositions().head().position() == player.directedPositions().tail().head().position()) + return 0; // no byte related to the frame + int cycleTick = tick % ANIMATION_TICK_LOOP; return (byte) (cycleTick % 2 == 0 ? 0 : cycleTick / 2 + 1); } @@ -90,15 +95,15 @@ public final class PlayerPainter { + byteForDyingState(player.lives())); case INVULNERABLE: - if (tick % 2 == 1) + if (tick % 2 == 0) return (byte) (byteForPlayerID() + byteForDirection(player.direction()) - + byteForFrame(tick)); + + byteForFrame(player, tick)); default: return (byte) (byteForPlayerID(player.id()) + byteForDirection(player.direction()) - + byteForFrame(tick)); + + byteForFrame(player, tick)); } } -- cgit v1.2.3