aboutsummaryrefslogtreecommitdiff
path: root/src/ch
diff options
context:
space:
mode:
Diffstat (limited to 'src/ch')
-rw-r--r--src/ch/epfl/xblast/server/painter/BlockImage.java6
-rw-r--r--src/ch/epfl/xblast/server/painter/BoardPainter.java25
-rw-r--r--src/ch/epfl/xblast/server/painter/ExplosionPainter.java32
-rw-r--r--src/ch/epfl/xblast/server/painter/PlayerPainter.java86
4 files changed, 102 insertions, 47 deletions
diff --git a/src/ch/epfl/xblast/server/painter/BlockImage.java b/src/ch/epfl/xblast/server/painter/BlockImage.java
index d5fa593..85a44be 100644
--- a/src/ch/epfl/xblast/server/painter/BlockImage.java
+++ b/src/ch/epfl/xblast/server/painter/BlockImage.java
@@ -1,7 +1,10 @@
1package ch.epfl.xblast.server.painter; 1package ch.epfl.xblast.server.painter;
2 2
3/** 3/**
4 * @author Timothée FLOURE (257420 4 * Block images enumeration.
5 *
6 * @author Timothée FLOURE (257420)
7 * @author Pacien TRAN-GIRARD (261948)
5 */ 8 */
6public enum BlockImage { 9public enum BlockImage {
7 10
@@ -39,4 +42,5 @@ public enum BlockImage {
39 * Bomb Range Bonus. 42 * Bomb Range Bonus.
40 */ 43 */
41 BONUS_RANGE 44 BONUS_RANGE
45
42} 46}
diff --git a/src/ch/epfl/xblast/server/painter/BoardPainter.java b/src/ch/epfl/xblast/server/painter/BoardPainter.java
index 69af129..8378cce 100644
--- a/src/ch/epfl/xblast/server/painter/BoardPainter.java
+++ b/src/ch/epfl/xblast/server/painter/BoardPainter.java
@@ -1,12 +1,18 @@
1package ch.epfl.xblast.server.painter; 1package ch.epfl.xblast.server.painter;
2 2
3import ch.epfl.xblast.*; 3import ch.epfl.xblast.Cell;
4import ch.epfl.xblast.server.*; 4import ch.epfl.xblast.Direction;
5import ch.epfl.xblast.server.Block;
6import ch.epfl.xblast.server.Board;
5 7
8import java.util.Collections;
6import java.util.Map; 9import java.util.Map;
7 10
8/** 11/**
12 * Board painter.
13 *
9 * @author Timothée FLOURE (257420) 14 * @author Timothée FLOURE (257420)
15 * @author Pacien TRAN-GIRARD (261948)
10 */ 16 */
11public final class BoardPainter { 17public final class BoardPainter {
12 18
@@ -16,11 +22,11 @@ public final class BoardPainter {
16 /** 22 /**
17 * Instantiates a new BoardPainter. 23 * Instantiates a new BoardPainter.
18 * 24 *
19 * @param blocksMap map linking block to the images 25 * @param blocksMap map linking block to the images
20 * @param shadowedFreeBlock a "shadowed" block image 26 * @param shadowedFreeBlock a "shadowed" block image
21 */ 27 */
22 public BoardPainter(Map<Block, BlockImage> blocksMap, BlockImage shadowedFreeBlock ) { 28 public BoardPainter(Map<Block, BlockImage> blocksMap, BlockImage shadowedFreeBlock) {
23 this.blocksMap = blocksMap; 29 this.blocksMap = Collections.unmodifiableMap(blocksMap);
24 this.shadowedFreeBlock = shadowedFreeBlock; 30 this.shadowedFreeBlock = shadowedFreeBlock;
25 } 31 }
26 32
@@ -28,13 +34,14 @@ public final class BoardPainter {
28 * Returns the bits sequence of the block related to the given Cell. 34 * Returns the bits sequence of the block related to the given Cell.
29 * 35 *
30 * @param board given board 36 * @param board given board
31 * @param cell given cell 37 * @param cell given cell
32 * @return the bits sequence related to the image of the given cell 38 * @return the bit sequence related to the image of the given cell
33 */ 39 */
34 public byte byteForCell(Board board, Cell cell) { 40 public byte byteForCell(Board board, Cell cell) {
35 if (board.blockAt(cell).isFree() && board.blockAt(cell.neighbor(Direction.W)).castsShadow()) 41 if (board.blockAt(cell).isFree() && board.blockAt(cell.neighbor(Direction.W)).castsShadow())
36 return (byte) shadowedFreeBlock.ordinal(); 42 return (byte) shadowedFreeBlock.ordinal();
37 43 else
38 return (byte) this.blocksMap.get(board.blockAt(cell)).ordinal(); 44 return (byte) this.blocksMap.get(board.blockAt(cell)).ordinal();
39 } 45 }
46
40} 47}
diff --git a/src/ch/epfl/xblast/server/painter/ExplosionPainter.java b/src/ch/epfl/xblast/server/painter/ExplosionPainter.java
index 63181e9..756d3c4 100644
--- a/src/ch/epfl/xblast/server/painter/ExplosionPainter.java
+++ b/src/ch/epfl/xblast/server/painter/ExplosionPainter.java
@@ -1,11 +1,15 @@
1package ch.epfl.xblast.server.painter; 1package ch.epfl.xblast.server.painter;
2 2
3import ch.epfl.xblast.server.*; 3import ch.epfl.xblast.server.Bomb;
4 4
5/** 5/**
6 * Explosion painter.
7 *
6 * @author Timothée FLOURE (257420) 8 * @author Timothée FLOURE (257420)
9 * @author Pacien TRAN-GIRARD (261948)
7 */ 10 */
8public final class ExplosionPainter { 11public final class ExplosionPainter {
12
9 private static final byte BLACK_BOMB_IMAGE = 20; 13 private static final byte BLACK_BOMB_IMAGE = 20;
10 private static final byte WHITE_BOMB_IMAGE = 21; 14 private static final byte WHITE_BOMB_IMAGE = 21;
11 15
@@ -15,41 +19,37 @@ public final class ExplosionPainter {
15 private static final byte WEST_EXPLOSION = 0b0001; 19 private static final byte WEST_EXPLOSION = 0b0001;
16 20
17 /** 21 /**
18 * Return the image corresponding to a bomb depending on its fuse length. 22 * Returns the image corresponding to a bomb depending on its fuse length.
19 * 23 *
20 * @param bomb given bomb 24 * @param bomb given bomb
21 * @return the byte related to the image of the bomb (black or white) 25 * @return the byte related to the image of the bomb (black or white)
22 */ 26 */
23 public static byte byteForBomb(Bomb bomb) 27 public static byte byteForBomb(Bomb bomb) {
24 { 28 return Integer.bitCount(bomb.fuseLength()) == 1 ? WHITE_BOMB_IMAGE : BLACK_BOMB_IMAGE;
25 if (Integer.bitCount(bomb.fuseLength()) == 1 ) {
26 return WHITE_BOMB_IMAGE;
27 } else {
28 return BLACK_BOMB_IMAGE;
29 }
30 } 29 }
31 30
32 /** 31 /**
33 * Return the image corresponding to the explosion on a cell given the explosions of its neighbors. 32 * Return the image corresponding to the explosion on a cell given the explosions of its neighbors.
34 * 33 *
35 * @param north is an explosion on the north cell 34 * @param north is an explosion on the north cell
36 * @param east is an explosion on the east cell 35 * @param east is an explosion on the east cell
37 * @param south is an explosion on the south cell 36 * @param south is an explosion on the south cell
38 * @param west is an explosion on the west cell 37 * @param west is an explosion on the west cell
39 * @return the byte corresponding to the related image 38 * @return the byte corresponding to the related image
40 */ 39 */
41 public static byte byteForBlast(boolean north, boolean east, boolean south, boolean west) { 40 public static byte byteForBlast(boolean north, boolean east, boolean south, boolean west) {
42 byte correspondingByte = 0b0; 41 byte correspondingByte = 0b0000;
43 42
44 if (north) 43 if (north)
45 correspondingByte += NORTH_EXPLOSION; 44 correspondingByte |= NORTH_EXPLOSION;
46 if (east) 45 if (east)
47 correspondingByte += EAST_EXPLOSION; 46 correspondingByte |= EAST_EXPLOSION;
48 if (south) 47 if (south)
49 correspondingByte += SOUTH_EXPLOSION; 48 correspondingByte |= SOUTH_EXPLOSION;
50 if (west) 49 if (west)
51 correspondingByte += WEST_EXPLOSION; 50 correspondingByte |= WEST_EXPLOSION;
52 51
53 return correspondingByte; 52 return correspondingByte;
54 } 53 }
54
55} 55}
diff --git a/src/ch/epfl/xblast/server/painter/PlayerPainter.java b/src/ch/epfl/xblast/server/painter/PlayerPainter.java
index 4f28554..043cb50 100644
--- a/src/ch/epfl/xblast/server/painter/PlayerPainter.java
+++ b/src/ch/epfl/xblast/server/painter/PlayerPainter.java
@@ -1,44 +1,88 @@
1package ch.epfl.xblast.server.painter; 1package ch.epfl.xblast.server.painter;
2 2
3import ch.epfl.xblast.server.*; 3import ch.epfl.xblast.Direction;
4import ch.epfl.xblast.PlayerID;
5import ch.epfl.xblast.server.Player;
4 6
5/** 7/**
8 * Player painter.
9 *
6 * @author Timothée FLOURE (257420) 10 * @author Timothée FLOURE (257420)
11 * @author Pacien TRAN-GIRARD (261948)
7 */ 12 */
8public final class PlayerPainter { 13public final class PlayerPainter {
9 private static final byte DEAD_PLAYER = 16; 14
15 private static final byte DEAD_PLAYER_IMAGE_ID = 16;
10 private static final byte DYING_IMAGE_ID = 12; 16 private static final byte DYING_IMAGE_ID = 12;
11 private static final byte LAST_DYING_IMAGE_ID = 13; 17 private static final byte LAST_DYING_IMAGE_ID = 13;
12 private static final byte PLAYER_MULTIPLIER = 20; 18
19 private static final int PLAYER_MULTIPLIER = 20;
20 private static final int DIRECTION_MULTIPLIER = 3;
21
22 private static final int ANIMATION_TICK_LOOP = 4;
23
24 /**
25 * Computes and returns the animation frame byte for the given tick.
26 *
27 * @param tick the tick
28 * @return the frame byte
29 */
30 private static byte byteForFrame(int tick) {