summaryrefslogtreecommitdiff
path: root/source/presentation/BitmapStore.h
diff options
context:
space:
mode:
Diffstat (limited to 'source/presentation/BitmapStore.h')
-rw-r--r--source/presentation/BitmapStore.h140
1 files changed, 140 insertions, 0 deletions
diff --git a/source/presentation/BitmapStore.h b/source/presentation/BitmapStore.h
new file mode 100644
index 0000000..b551698
--- /dev/null
+++ b/source/presentation/BitmapStore.h
@@ -0,0 +1,140 @@
+#ifndef BITMAPSTORE_H
+#define BITMAPSTORE_H
+
+#include <string>
+#include <map>
+using namespace std;
+
+#include <allegro5/allegro.h>
+#include <allegro5/allegro_primitives.h>
+#include <allegro5/allegro_font.h>
+#include <allegro5/allegro_ttf.h>
+#include <allegro5/allegro_native_dialog.h>
+
+#include "../logic/AllegroWrappers.h"
+
+/**
+* @brief Class for accessing images in ALLEGRO_BITMAP format and low level drawing.
+*
+* The store ensures that only one copy of identical images are created.
+* This is done through a map, that caches the images that have already been requested.
+* If an uncached image is requested, it is added to the cache before being returned.
+* The store provides an enumerated type, Image, for other classes to reference which image
+* should represent the object on the screen.
+*
+* All images are square, to allow easy rotation and placement on the screen.
+*
+* @author Justin Wernick
+* @author David Schneider
+*/
+class BitmapStore
+{
+ public:
+ /**
+ * @brief Constructor for creating a BitmapStore with a set image size.
+ *
+ * @param [in] blockWidth The width (and height) of an image returned by the store in pixels.
+ */
+ BitmapStore(unsigned int blockWidth);
+ /**
+ * @brief Destructor for clearing cache.
+ */
+ ~BitmapStore();
+
+ /**
+ * @brief Type used to define which image should be returned.
+ */
+ enum Image {PLAYER, ENEMY, ROCK, CHECKPOINT, MAZE_WALL, MAZE_FLOOR, SMOKE, CRASHED_CAR, CLAIMED_CHECKPOINT};
+
+ /**
+ * @brief Function to get image for drawing to the screen.
+ *
+ * @param [in] image Image to be returned.
+ * @return Requested image in ALLEGRO_BITMAP format.
+ */
+ ALLEGRO_BITMAP* getBitmap(Image image);
+
+ private:
+ /**
+ * @brief Unimplemented copy constructor, prevents copying of BitmapStore objects.
+ *
+ * Copying a BitmapStore is unneccesary as there should only be a single BitmapStore object.
+ */
+ BitmapStore(const BitmapStore& ref);
+ /**
+ * @brief Unimplemented assignment operator.
+ *
+ * @see BitmapStore(const BitmapStore& ref);
+ */
+ BitmapStore& operator=(const BitmapStore& rhs);
+
+ /**
+ * @brief Draws the image representing the player.
+ *
+ * @param [out] canvas ALLEGRO_BITMAP onto which the image is drawn.
+ */
+ void drawPlayerCar(ALLEGRO_BITMAP* canvas);
+ /**
+ * @brief Draws the image representing an enemy.
+ *
+ * @param [out] canvas ALLEGRO_BITMAP onto which the image is drawn.
+ */
+ void drawEnemyCar(ALLEGRO_BITMAP* canvas);
+ /**
+ * @brief Draws the image representing a rock.
+ *
+ * @param [out] canvas ALLEGRO_BITMAP onto which the image is drawn.
+ */
+ void drawRock(ALLEGRO_BITMAP* canvas);
+ /**
+ * @brief Draws the image representing a checkpoint.
+ *
+ * @param [out] canvas ALLEGRO_BITMAP onto which the image is drawn.
+ */
+ void drawCheckpoint(ALLEGRO_BITMAP* canvas);
+ /**
+ * @brief Draws the image representing a solid part of the maze.
+ *
+ * @param [out] canvas ALLEGRO_BITMAP onto which the image is drawn.
+ */
+ void drawMazeWall(ALLEGRO_BITMAP* canvas);
+ /**
+ * @brief Draws the image representing a non-solid part of the maze.
+ *
+ * @param [out] canvas ALLEGRO_BITMAP onto which the image is drawn.
+ */
+ void drawMazeFloor(ALLEGRO_BITMAP* canvas);
+ /**
+ * @brief Draws the image representing a smokescreen.
+ *
+ * @param [out] canvas ALLEGRO_BITMAP onto which the image is drawn.
+ */
+ void drawSmoke(ALLEGRO_BITMAP* canvas);
+ /**
+ * @brief Draws the popup that appears when a car crashes.
+ *
+ * @param [out] canvas ALLEGRO_BITMAP onto which the image is drawn.
+ */
+ void drawCrashedCar(ALLEGRO_BITMAP* canvas);
+ /**
+ * @brief Draws the popup that appears when a checkpoint is collected.
+ *
+ * @param [out] canvas ALLEGRO_BITMAP onto which the image is drawn.
+ */
+ void drawClaimedCheckpoint(ALLEGRO_BITMAP* canvas);
+
+ AllegroDrawingInit _drawingInstalls; ///< Ensures that Allegro is initialized while an object of this class exists
+
+ ALLEGRO_FONT* _bitmapFont; ///< Font used for writing text on bitmaps.
+
+ /**
+ * @brief map containing pairs of Images (the enumerated type) and the actual images.
+ *
+ * Creates a cache for images once they have been drawn.
+ */
+ map<Image, ALLEGRO_BITMAP*> _bitmaps;
+
+ unsigned int _blockWidth; ///< The width of a square image in the store
+};
+
+#endif // BITMAPSTORE_H