diff options
author | Timothée Floure | 2016-05-27 13:46:27 +0200 |
---|---|---|
committer | Timothée Floure | 2016-05-27 13:46:27 +0200 |
commit | a82a8ba2611378ff6fb1cd226fb3d579d43d6e89 (patch) | |
tree | 68b75b4968f74ddde01d012cccc5cf596a823ec0 /src/ch | |
parent | 8552fca003490e61aa65cbc746731e1047af9a25 (diff) | |
download | xblast-a82a8ba2611378ff6fb1cd226fb3d579d43d6e89.tar.gz |
Fix player walk
Diffstat (limited to 'src/ch')
-rw-r--r-- | src/ch/epfl/xblast/server/painter/PlayerPainter.java | 26 |
1 files changed, 15 insertions, 11 deletions
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; | |||
2 | 2 | ||
3 | import ch.epfl.xblast.Direction; | 3 | import ch.epfl.xblast.Direction; |
4 | import ch.epfl.xblast.PlayerID; | 4 | import ch.epfl.xblast.PlayerID; |
5 | import ch.epfl.xblast.SubCell; | ||
5 | import ch.epfl.xblast.server.Player; | 6 | import ch.epfl.xblast.server.Player; |
6 | 7 | ||
7 | /** | 8 | /** |
@@ -21,21 +22,24 @@ public final class PlayerPainter { | |||
21 | private static final int PLAYER_MULTIPLIER = 20; | 22 | private static final int PLAYER_MULTIPLIER = 20; |
22 | private static final int DIRECTION_MULTIPLIER = 3; | 23 | private static final int DIRECTION_MULTIPLIER = 3; |
23 | 24 | ||
24 | private static final int ANIMATION_TICK_LOOP = 4; | 25 | private static final int ANIMATION_POSITION_LOOP = 4; |
25 | 26 | ||
26 | /** | 27 | /** |
27 | * Computes and returns the animation frame byte for the given tick if the player is moving. | 28 | * Computes and returns the animation frame byte for the given tick if the player is moving. |
28 | * | 29 | * |
29 | * @param tick the tick | 30 | * @param dir the direction |
30 | * @param player the player | 31 | * @param pos the position |
31 | * @return the frame byte | 32 | * @return the position byte |
32 | */ | 33 | */ |
33 | private static byte byteForFrame(Player player,int tick) { | 34 | private static byte byteForPosition(Direction dir, SubCell pos) { |
34 | // if the player is stopped | 35 | int axialPosition; |
35 | if (player.directedPositions().head().position() == player.directedPositions().tail().head().position()) | ||
36 | return 0; // no byte related to the frame | ||
37 | 36 | ||
38 | int cycleTick = tick % ANIMATION_TICK_LOOP; | 37 | if (dir == Direction.E || dir == Direction.W) |
38 | axialPosition = pos.x(); | ||
39 | else | ||
40 | axialPosition = pos.y(); | ||
41 | |||
42 | int cycleTick = axialPosition % ANIMATION_POSITION_LOOP; | ||
39 | return (byte) (cycleTick % 2 == 0 ? 0 : cycleTick / 2 + 1); | 43 | return (byte) (cycleTick % 2 == 0 ? 0 : cycleTick / 2 + 1); |
40 | } | 44 | } |
41 | 45 | ||
@@ -98,12 +102,12 @@ public final class PlayerPainter { | |||
98 | if (tick % 2 == 0) | 102 | if (tick % 2 == 0) |
99 | return (byte) (byteForPlayerID() | 103 | return (byte) (byteForPlayerID() |
100 | + byteForDirection(player.direction()) | 104 | + byteForDirection(player.direction()) |
101 | + byteForFrame(player, tick)); | 105 | + byteForPosition(player.direction(), player.position())); |
102 | 106 | ||
103 | default: | 107 | default: |
104 | return (byte) (byteForPlayerID(player.id()) | 108 | return (byte) (byteForPlayerID(player.id()) |
105 | + byteForDirection(player.direction()) | 109 | + byteForDirection(player.direction()) |
106 | + byteForFrame(player, tick)); | 110 | + byteForPosition(player.direction(), player.position())); |
107 | } | 111 | } |
108 | } | 112 | } |
109 | 113 | ||