summaryrefslogtreecommitdiff
path: root/source/presentation/BitmapStore.h
blob: b551698818439a35ce874edb42de0cacfd2d267e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
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