ELEC2645 (2019/20) / Mbed 2 deprecated ELEC2645_Project_el18ac

Dependencies:   mbed

Committer:
ale_carb0ni
Date:
Tue May 26 17:14:44 2020 +0000
Revision:
5:a919651ebf36
working game w/out doxygen

Who changed what in which revision?

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