From a82a8ba2611378ff6fb1cd226fb3d579d43d6e89 Mon Sep 17 00:00:00 2001 From: Timothée Floure Date: Fri, 27 May 2016 13:46:27 +0200 Subject: Fix player walk --- .../epfl/xblast/server/painter/PlayerPainter.java | 26 +++++++++++++--------- 1 file changed, 15 insertions(+), 11 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 eb450d6..9fb0647 100644 --- a/src/ch/epfl/xblast/server/painter/PlayerPainter.java +++ b/src/ch/epfl/xblast/server/painter/PlayerPainter.java @@ -2,6 +2,7 @@ package ch.epfl.xblast.server.painter; import ch.epfl.xblast.Direction; import ch.epfl.xblast.PlayerID; +import ch.epfl.xblast.SubCell; import ch.epfl.xblast.server.Player; /** @@ -21,21 +22,24 @@ public final class PlayerPainter { private static final int PLAYER_MULTIPLIER = 20; private static final int DIRECTION_MULTIPLIER = 3; - private static final int ANIMATION_TICK_LOOP = 4; + private static final int ANIMATION_POSITION_LOOP = 4; /** * 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 + * @param dir the direction + * @param pos the position + * @return the position byte */ - 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 + private static byte byteForPosition(Direction dir, SubCell pos) { + int axialPosition; - int cycleTick = tick % ANIMATION_TICK_LOOP; + if (dir == Direction.E || dir == Direction.W) + axialPosition = pos.x(); + else + axialPosition = pos.y(); + + int cycleTick = axialPosition % ANIMATION_POSITION_LOOP; return (byte) (cycleTick % 2 == 0 ? 0 : cycleTick / 2 + 1); } @@ -98,12 +102,12 @@ public final class PlayerPainter { if (tick % 2 == 0) return (byte) (byteForPlayerID() + byteForDirection(player.direction()) - + byteForFrame(player, tick)); + + byteForPosition(player.direction(), player.position())); default: return (byte) (byteForPlayerID(player.id()) + byteForDirection(player.direction()) - + byteForFrame(player, tick)); + + byteForPosition(player.direction(), player.position())); } } -- cgit v1.2.3