contains my game for the embedded systems project 2645

Dependencies:   mbed FXOS8700CQQQ

Committer:
OmarAlebiary
Date:
Tue May 07 15:17:21 2019 +0000
Revision:
40:13b8467526d0
Parent:
39:822b66b1c935
Final Submission. I have read and agreed with Statement of Academic Integrity

Who changed what in which revision?

UserRevisionLine numberNew contents of line
OmarAlebiary 39:822b66b1c935 1 #ifndef BITMAP_H
OmarAlebiary 39:822b66b1c935 2 #define BITMAP_H
OmarAlebiary 39:822b66b1c935 3
OmarAlebiary 39:822b66b1c935 4 #include <vector>
OmarAlebiary 39:822b66b1c935 5
OmarAlebiary 39:822b66b1c935 6 // Forward declarations
OmarAlebiary 39:822b66b1c935 7 class N5110;
OmarAlebiary 39:822b66b1c935 8
OmarAlebiary 39:822b66b1c935 9 /**
OmarAlebiary 39:822b66b1c935 10 * @brief A black & white bitmap that can be rendered on an N5110 screen
OmarAlebiary 39:822b66b1c935 11 * @author Alex Valavanis <a.valavanis@leeds.ac.uk>
OmarAlebiary 39:822b66b1c935 12 *
OmarAlebiary 39:822b66b1c935 13 * @code
OmarAlebiary 39:822b66b1c935 14 // First declare the pixel map data using '1' for black,
OmarAlebiary 39:822b66b1c935 15 // or '0' for white pixels
OmarAlebiary 39:822b66b1c935 16 static int sprite_data[] = {
OmarAlebiary 39:822b66b1c935 17 0,0,1,0,0,
OmarAlebiary 39:822b66b1c935 18 0,1,1,1,0,
OmarAlebiary 39:822b66b1c935 19 0,0,1,0,0,
OmarAlebiary 39:822b66b1c935 20 0,1,1,1,0,
OmarAlebiary 39:822b66b1c935 21 1,1,1,1,1,
OmarAlebiary 39:822b66b1c935 22 1,1,1,1,1,
OmarAlebiary 39:822b66b1c935 23 1,1,0,1,1,
OmarAlebiary 39:822b66b1c935 24 1,1,0,1,1
OmarAlebiary 39:822b66b1c935 25 };
OmarAlebiary 39:822b66b1c935 26
OmarAlebiary 39:822b66b1c935 27 // Instantiate the Bitmap object using the data above
OmarAlebiary 39:822b66b1c935 28 Bitmap sprite(sprite_data, 8, 5); // Specify rows and columns in sprite
OmarAlebiary 39:822b66b1c935 29
OmarAlebiary 39:822b66b1c935 30 // We can render the bitmap wherever we want on the screen
OmarAlebiary 39:822b66b1c935 31 sprite.render(lcd, 20, 6); // x and y locations for rendering
OmarAlebiary 39:822b66b1c935 32 sprite.render(lcd, 30, 10);
OmarAlebiary 39:822b66b1c935 33
OmarAlebiary 39:822b66b1c935 34 // We can also print its values to the terminal
OmarAlebiary 39:822b66b1c935 35 sprite.print();
OmarAlebiary 39:822b66b1c935 36 * @endcode
OmarAlebiary 39:822b66b1c935 37 */
OmarAlebiary 39:822b66b1c935 38 class Bitmap
OmarAlebiary 39:822b66b1c935 39 {
OmarAlebiary 39:822b66b1c935 40 private:
OmarAlebiary 39:822b66b1c935 41 /**
OmarAlebiary 39:822b66b1c935 42 * @brief The contents of the drawing, with pixels stored in row-major order
OmarAlebiary 39:822b66b1c935 43 * @details '1' represents a black pixel; '0' represents white
OmarAlebiary 39:822b66b1c935 44 */
OmarAlebiary 39:822b66b1c935 45 std::vector<int> _contents;
OmarAlebiary 39:822b66b1c935 46
OmarAlebiary 39:822b66b1c935 47 unsigned int _height; ///< The height of the drawing in pixels
OmarAlebiary 39:822b66b1c935 48 unsigned int _width; ///< The width of the drawing in pixels
OmarAlebiary 39:822b66b1c935 49
OmarAlebiary 39:822b66b1c935 50 public:
OmarAlebiary 39:822b66b1c935 51 Bitmap(int const *contents,
OmarAlebiary 39:822b66b1c935 52 unsigned int const height,
OmarAlebiary 39:822b66b1c935 53 unsigned int const width);
OmarAlebiary 39:822b66b1c935 54
OmarAlebiary 39:822b66b1c935 55 int get_pixel(unsigned int const row,
OmarAlebiary 39:822b66b1c935 56 unsigned int const column) const;
OmarAlebiary 39:822b66b1c935 57
OmarAlebiary 39:822b66b1c935 58 void print() const;
OmarAlebiary 39:822b66b1c935 59
OmarAlebiary 39:822b66b1c935 60 void render(N5110 &lcd,
OmarAlebiary 39:822b66b1c935 61 unsigned int const x0,
OmarAlebiary 39:822b66b1c935 62 unsigned int const y0) const;
OmarAlebiary 39:822b66b1c935 63 };
OmarAlebiary 39:822b66b1c935 64
OmarAlebiary 39:822b66b1c935 65 #endif // BITMAP_H