diff options
Diffstat (limited to 'src/ch/epfl/xblast/server/painter/PlayerPainter.java')
-rw-r--r-- | src/ch/epfl/xblast/server/painter/PlayerPainter.java | 42 |
1 files changed, 34 insertions, 8 deletions
diff --git a/src/ch/epfl/xblast/server/painter/PlayerPainter.java b/src/ch/epfl/xblast/server/painter/PlayerPainter.java index 043cb50..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 | /** |
@@ -16,19 +17,29 @@ public final class PlayerPainter { | |||
16 | private static final byte DYING_IMAGE_ID = 12; | 17 | private static final byte DYING_IMAGE_ID = 12; |
17 | private static final byte LAST_DYING_IMAGE_ID = 13; | 18 | private static final byte LAST_DYING_IMAGE_ID = 13; |
18 | 19 | ||
20 | private static final int BLANK_PLAYER_GROUP = 4; | ||
21 | |||
19 | private static final int PLAYER_MULTIPLIER = 20; | 22 | private static final int PLAYER_MULTIPLIER = 20; |
20 | private static final int DIRECTION_MULTIPLIER = 3; | 23 | private static final int DIRECTION_MULTIPLIER = 3; |
21 | 24 | ||
22 | private static final int ANIMATION_TICK_LOOP = 4; | 25 | private static final int ANIMATION_POSITION_LOOP = 4; |
23 | 26 | ||
24 | /** | 27 | /** |
25 | * Computes and returns the animation frame byte for the given tick. | 28 | * Computes and returns the animation frame byte for the given tick if the player is moving. |
26 | * | 29 | * |
27 | * @param tick the tick | 30 | * @param dir the direction |
28 | * @return the frame byte | 31 | * @param pos the position |
32 | * @return the position byte | ||
29 | */ | 33 | */ |
30 | private static byte byteForFrame(int tick) { | 34 | private static byte byteForPosition(Direction dir, SubCell pos) { |
31 | int cycleTick = tick % ANIMATION_TICK_LOOP; | 35 | int axialPosition; |
36 | |||
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; | ||
32 | return (byte) (cycleTick % 2 == 0 ? 0 : cycleTick / 2 + 1); | 43 | return (byte) (cycleTick % 2 == 0 ? 0 : cycleTick / 2 + 1); |
33 | } | 44 | } |
34 | 45 | ||
@@ -53,13 +64,22 @@ public final class PlayerPainter { | |||
53 | } | 64 | } |
54 | 65 | ||
55 | /** | 66 | /** |
67 | * Returns the player image byte for the blank player. | ||
68 | * | ||
69 | * @return the image byte for the player | ||
70 | */ | ||
71 | private static byte byteForPlayerID() { | ||
72 | return (byte) (BLANK_PLAYER_GROUP * PLAYER_MULTIPLIER); | ||
73 | } | ||
74 | |||
75 | /** | ||
56 | * Returns the image ID for the dying state according to the number of remaining lives. | 76 | * Returns the image ID for the dying state according to the number of remaining lives. |
57 | * | 77 | * |
58 | * @param lives the number of remaining lives | 78 | * @param lives the number of remaining lives |
59 | * @return the dying image ID | 79 | * @return the dying image ID |
60 | */ | 80 | */ |
61 | private static byte byteForDyingState(int lives) { | 81 | private static byte byteForDyingState(int lives) { |
62 | return lives == 0 ? LAST_DYING_IMAGE_ID : DYING_IMAGE_ID; | 82 | return lives == 1 ? LAST_DYING_IMAGE_ID : DYING_IMAGE_ID; |
63 | } | 83 | } |
64 | 84 | ||
65 | /** | 85 | /** |
@@ -78,10 +98,16 @@ public final class PlayerPainter { | |||
78 | return (byte) (byteForPlayerID(player.id()) | 98 | return (byte) (byteForPlayerID(player.id()) |
79 | + byteForDyingState(player.lives())); | 99 | + byteForDyingState(player.lives())); |
80 | 100 | ||
101 | case INVULNERABLE: | ||
102 | if (tick % 2 == 0) | ||
103 | return (byte) (byteForPlayerID() | ||
104 | + byteForDirection(player.direction()) | ||
105 | + byteForPosition(player.direction(), player.position())); | ||
106 | |||
81 | default: | 107 | default: |
82 | return (byte) (byteForPlayerID(player.id()) | 108 | return (byte) (byteForPlayerID(player.id()) |
83 | + byteForDirection(player.direction()) | 109 | + byteForDirection(player.direction()) |
84 | + byteForFrame(tick)); | 110 | + byteForPosition(player.direction(), player.position())); |
85 | } | 111 | } |
86 | } | 112 | } |
87 | 113 | ||