aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorTimothée Floure2016-05-23 13:51:42 +0200
committerTimothée Floure2016-05-23 13:51:42 +0200
commit05cfb4a8b3af26d00cbd0c6931ee96a5ad075af2 (patch)
tree3d3b80c94c0b52ed5344fa2f3136c03d6b201e7a /src
parente37aeb0eb425d6227e8c832b0bb5f5c9f79b0e64 (diff)
downloadxblast-05cfb4a8b3af26d00cbd0c6931ee96a5ad075af2.tar.gz
Fix players movements (don't walk if stopped)
Diffstat (limited to 'src')
-rw-r--r--src/ch/epfl/xblast/server/painter/PlayerPainter.java15
1 files changed, 10 insertions, 5 deletions
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 {
24 private static final int ANIMATION_TICK_LOOP = 4; 24 private static final int ANIMATION_TICK_LOOP = 4;
25 25
26 /** 26 /**
27 * Computes and returns the animation frame byte for the given tick. 27 * Computes and returns the animation frame byte for the given tick if the player is moving.
28 * 28 *
29 * @param tick the tick 29 * @param tick the tick
30 * @param player the player
30 * @return the frame byte 31 * @return the frame byte
31 */ 32 */
32 private static byte byteForFrame(int tick) { 33 private static byte byteForFrame(Player player,int tick) {
34 // if the player is stopped
35 if (player.directedPositions().head().position() == player.directedPositions().tail().head().position())
36 return 0; // no byte related to the frame
37
33 int cycleTick = tick % ANIMATION_TICK_LOOP; 38 int cycleTick = tick % ANIMATION_TICK_LOOP;
34 return (byte) (cycleTick % 2 == 0 ? 0 : cycleTick / 2 + 1); 39 return (byte) (cycleTick % 2 == 0 ? 0 : cycleTick / 2 + 1);
35 } 40 }
@@ -90,15 +95,15 @@ public final class PlayerPainter {
90 + byteForDyingState(player.lives())); 95 + byteForDyingState(player.lives()));
91 96
92 case INVULNERABLE: 97 case INVULNERABLE:
93 if (tick % 2 == 1) 98 if (tick % 2 == 0)
94 return (byte) (byteForPlayerID() 99 return (byte) (byteForPlayerID()
95 + byteForDirection(player.direction()) 100 + byteForDirection(player.direction())
96 + byteForFrame(tick)); 101 + byteForFrame(player, tick));
97 102
98 default: 103 default:
99 return (byte) (byteForPlayerID(player.id()) 104 return (byte) (byteForPlayerID(player.id())
100 + byteForDirection(player.direction()) 105 + byteForDirection(player.direction())
101 + byteForFrame(tick)); 106 + byteForFrame(player, tick));
102 } 107 }
103 } 108 }
104 109