Ben Evans / Mbed 2 deprecated Defender_Game

Dependencies:   mbed

Committer:
evanso
Date:
Sun Feb 23 18:49:56 2020 +0000
Revision:
1:1f2ae263248e
Sart of Project ;

Who changed what in which revision?

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