diff options
56 files changed, 5435 insertions, 0 deletions
diff --git a/img/Animal/Bear.png b/img/Animal/Bear.png new file mode 100644 index 0000000..1ba6ec6 --- /dev/null +++ b/img/Animal/Bear.png | |||
Binary files differ | |||
diff --git a/img/Animal/Hamster.png b/img/Animal/Hamster.png new file mode 100644 index 0000000..3aadd70 --- /dev/null +++ b/img/Animal/Hamster.png | |||
Binary files differ | |||
diff --git a/img/Animal/Monkey.png b/img/Animal/Monkey.png new file mode 100644 index 0000000..bcea339 --- /dev/null +++ b/img/Animal/Monkey.png | |||
Binary files differ | |||
diff --git a/img/Animal/Mouse.png b/img/Animal/Mouse.png new file mode 100644 index 0000000..6b9e95d --- /dev/null +++ b/img/Animal/Mouse.png | |||
Binary files differ | |||
diff --git a/img/Animal/Panda.png b/img/Animal/Panda.png new file mode 100644 index 0000000..199238a --- /dev/null +++ b/img/Animal/Panda.png | |||
Binary files differ | |||
diff --git a/img/Animal/SpaceInvader.png b/img/Animal/SpaceInvader.png new file mode 100644 index 0000000..cd9ebe8 --- /dev/null +++ b/img/Animal/SpaceInvader.png | |||
Binary files differ | |||
diff --git a/img/Predator/Blinky.png b/img/Predator/Blinky.png new file mode 100644 index 0000000..7143fd2 --- /dev/null +++ b/img/Predator/Blinky.png | |||
Binary files differ | |||
diff --git a/img/Predator/Clyde.png b/img/Predator/Clyde.png new file mode 100644 index 0000000..04c7c30 --- /dev/null +++ b/img/Predator/Clyde.png | |||
Binary files differ | |||
diff --git a/img/Predator/Inky.png b/img/Predator/Inky.png new file mode 100644 index 0000000..f6efa4a --- /dev/null +++ b/img/Predator/Inky.png | |||
Binary files differ | |||
diff --git a/img/Predator/Pinky.png b/img/Predator/Pinky.png new file mode 100644 index 0000000..d50102e --- /dev/null +++ b/img/Predator/Pinky.png | |||
Binary files differ | |||
diff --git a/img/Prey/PacMan.big.png b/img/Prey/PacMan.big.png new file mode 100644 index 0000000..c1b0e17 --- /dev/null +++ b/img/Prey/PacMan.big.png | |||
Binary files differ | |||
diff --git a/img/Prey/PacMan.png b/img/Prey/PacMan.png new file mode 100644 index 0000000..d766f25 --- /dev/null +++ b/img/Prey/PacMan.png | |||
Binary files differ | |||
diff --git a/img/tiles/exit.png b/img/tiles/exit.png new file mode 100644 index 0000000..5286a5a --- /dev/null +++ b/img/tiles/exit.png | |||
Binary files differ | |||
diff --git a/img/tiles/free.png b/img/tiles/free.png new file mode 100644 index 0000000..1804c42 --- /dev/null +++ b/img/tiles/free.png | |||
Binary files differ | |||
diff --git a/img/tiles/nothing.png b/img/tiles/nothing.png new file mode 100644 index 0000000..5219d54 --- /dev/null +++ b/img/tiles/nothing.png | |||
Binary files differ | |||
diff --git a/img/tiles/start.png b/img/tiles/start.png new file mode 100644 index 0000000..ff429b6 --- /dev/null +++ b/img/tiles/start.png | |||
Binary files differ | |||
diff --git a/img/tiles/wall.png b/img/tiles/wall.png new file mode 100644 index 0000000..c216e26 --- /dev/null +++ b/img/tiles/wall.png | |||
Binary files differ | |||
diff --git a/img/unknown.png b/img/unknown.png new file mode 100644 index 0000000..97c58b8 --- /dev/null +++ b/img/unknown.png | |||
Binary files differ | |||
diff --git a/labyrinth.txt b/labyrinth.txt new file mode 100644 index 0000000..4b7a42b --- /dev/null +++ b/labyrinth.txt | |||
@@ -0,0 +1,16 @@ | |||
1 | |||
2 | To load this labyrinth, write : | ||
3 | |||
4 | int[][] labyrinth = LabyrinthGenerator.readFromFile("labyrinth.txt"); | ||
5 | |||
6 | 1 2 1 1 1 1 1 1 1 1 1 | ||
7 | 1 0 0 0 0 1 0 0 0 0 1 | ||
8 | 1 0 1 1 1 1 1 0 1 0 1 | ||
9 | 1 0 1 0 0 0 0 0 1 0 1 | ||
10 | 1 0 1 0 1 1 1 0 1 0 1 | ||
11 | 1 0 0 0 1 0 1 0 1 1 1 | ||
12 | 1 1 1 1 1 0 1 0 1 0 3 | ||
13 | 1 0 0 0 0 0 1 0 1 0 1 | ||
14 | 1 0 1 1 1 1 1 0 1 0 1 | ||
15 | 1 0 0 0 0 0 0 0 0 0 1 | ||
16 | 1 1 1 1 1 1 1 1 1 1 1 \ No newline at end of file | ||
diff --git a/src/ch/epfl/maze/graphics/Animation.java b/src/ch/epfl/maze/graphics/Animation.java new file mode 100644 index 0000000..0502a92 --- /dev/null +++ b/src/ch/epfl/maze/graphics/Animation.java | |||
@@ -0,0 +1,245 @@ | |||
1 | package ch.epfl.maze.graphics; | ||
2 | |||
3 | import java.awt.Graphics2D; | ||
4 | import java.awt.image.BufferedImage; | ||
5 | import java.awt.image.ImageObserver; | ||
6 | import java.io.File; | ||
7 | import java.io.IOException; | ||
8 | import java.util.HashMap; | ||
9 | import java.util.List; | ||
10 | import java.util.Map; | ||
11 | import java.util.TreeMap; | ||
12 | |||
13 | import javax.imageio.ImageIO; | ||
14 | |||
15 | import ch.epfl.maze.physical.Animal; | ||
16 | import ch.epfl.maze.util.Action; | ||
17 | import ch.epfl.maze.util.Direction; | ||
18 | import ch.epfl.maze.util.Vector2D; | ||
19 | |||
20 | /** | ||
21 | * Handles the animation of a {@code Simulation} by extrapolating the positions | ||
22 | * of animals. | ||
23 | * | ||
24 | */ | ||
25 | |||
26 | public final class Animation { | ||
27 | |||
28 | /** Default number of waiting frames to display when animation is aborting. */ | ||
29 | public static final int DEFAULT_WAITING_FRAMES = 2; | ||
30 | |||
31 | /** Maps animals identity to graphical components that will be animated. */ | ||
32 | private Map<Integer, GraphicComponent> mGraphMap; | ||
33 | |||
34 | /** Buffer of images of animals. Key format: "superclass.class" */ | ||
35 | private Map<String, BufferedImage> mImages; | ||
36 | |||
37 | /** Drawing ratio variable. */ | ||
38 | private float mRatio; | ||
39 | |||
40 | /** Control variable. */ | ||
41 | private boolean mDone; | ||
42 | |||
43 | /** Current number of waiting frames, to prevent screen from flashing. */ | ||
44 | private int mWaitingFrames; | ||
45 | |||
46 | /** | ||
47 | * Constructs an animation handler that will animate animals on a graphic | ||
48 | * environment by extrapolating their position. | ||
49 | * | ||
50 | * @param animals | ||
51 | * The {@code List} of animals that will be shown on the first | ||
52 | * frame | ||
53 | */ | ||
54 | |||
55 | public Animation(List<Animal> animals) { | ||
56 | mGraphMap = new TreeMap<Integer, GraphicComponent>(); | ||
57 | mImages = new HashMap<String, BufferedImage>(); | ||
58 | |||
59 | // sanity check | ||
60 | if (animals != null) { | ||
61 | // puts default action to draw animals and loads corresponding image | ||
62 | Action none = new Action(Direction.NONE); | ||
63 | for (int i = 0; i < animals.size(); i++) { | ||
64 | Animal animal = animals.get(i); | ||
65 | BufferedImage img = loadImage(animal); | ||
66 | Vector2D position = animal.getPosition().mul(Display.SQUARE_SIZE); | ||
67 | |||
68 | mGraphMap.put(i, new GraphicComponent(img, position, none)); | ||
69 | } | ||
70 | } | ||
71 | |||
72 | // default values | ||
73 | mDone = true; | ||
74 | mWaitingFrames = 0; | ||
75 | } | ||
76 | |||
77 | /** | ||
78 | * Asks the animation to update an animal on the screen with a corresponding | ||
79 | * action. The animal is identified by a number, so it can be overwritten in | ||
80 | * case of a future update. | ||
81 | * | ||
82 | * @param animal | ||
83 | * Animal to update with action | ||
84 | * @param id | ||
85 | * Unique identifier for animal | ||
86 | * @param action | ||
87 | * Action that animal needs to perform | ||
88 | */ | ||
89 | |||
90 | public void update(Animal animal, int id, Action action) { | ||
91 | // sanity checks | ||
92 | if (action == null) { | ||
93 | action = new Action(Direction.NONE, false); | ||