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