![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
Game codes for Pokemon Academy Yiu Fai Kwok - 201198802 I have read the University Regulations on Plagiarism and state that the work covered by this declaration is my own and does not contain any unacknowledged work from other sources.
Dependencies: mbed FXOS8700CQ mbed-rtos
N5110/Bitmap.h@0:1da4db5de653, 2019-03-11 (annotated)
- Committer:
- yfkwok
- Date:
- Mon Mar 11 19:48:14 2019 +0000
- Revision:
- 0:1da4db5de653
initial commit
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
yfkwok | 0:1da4db5de653 | 1 | #ifndef BITMAP_H |
yfkwok | 0:1da4db5de653 | 2 | #define BITMAP_H |
yfkwok | 0:1da4db5de653 | 3 | |
yfkwok | 0:1da4db5de653 | 4 | #include <vector> |
yfkwok | 0:1da4db5de653 | 5 | |
yfkwok | 0:1da4db5de653 | 6 | // Forward declarations |
yfkwok | 0:1da4db5de653 | 7 | class N5110; |
yfkwok | 0:1da4db5de653 | 8 | |
yfkwok | 0:1da4db5de653 | 9 | /** |
yfkwok | 0:1da4db5de653 | 10 | * @brief A black & white bitmap that can be rendered on an N5110 screen |
yfkwok | 0:1da4db5de653 | 11 | * @author Alex Valavanis <a.valavanis@leeds.ac.uk> |
yfkwok | 0:1da4db5de653 | 12 | * |
yfkwok | 0:1da4db5de653 | 13 | * @code |
yfkwok | 0:1da4db5de653 | 14 | // First declare the pixel map data using '1' for black, |
yfkwok | 0:1da4db5de653 | 15 | // or '0' for white pixels |
yfkwok | 0:1da4db5de653 | 16 | static int sprite_data[] = { |
yfkwok | 0:1da4db5de653 | 17 | 0,0,1,0,0, |
yfkwok | 0:1da4db5de653 | 18 | 0,1,1,1,0, |
yfkwok | 0:1da4db5de653 | 19 | 0,0,1,0,0, |
yfkwok | 0:1da4db5de653 | 20 | 0,1,1,1,0, |
yfkwok | 0:1da4db5de653 | 21 | 1,1,1,1,1, |
yfkwok | 0:1da4db5de653 | 22 | 1,1,1,1,1, |
yfkwok | 0:1da4db5de653 | 23 | 1,1,0,1,1, |
yfkwok | 0:1da4db5de653 | 24 | 1,1,0,1,1 |
yfkwok | 0:1da4db5de653 | 25 | }; |
yfkwok | 0:1da4db5de653 | 26 | |
yfkwok | 0:1da4db5de653 | 27 | // Instantiate the Bitmap object using the data above |
yfkwok | 0:1da4db5de653 | 28 | Bitmap sprite(sprite_data, 8, 5); // Specify rows and columns in sprite |
yfkwok | 0:1da4db5de653 | 29 | |
yfkwok | 0:1da4db5de653 | 30 | // We can render the bitmap wherever we want on the screen |
yfkwok | 0:1da4db5de653 | 31 | sprite.render(lcd, 20, 6); // x and y locations for rendering |
yfkwok | 0:1da4db5de653 | 32 | sprite.render(lcd, 30, 10); |
yfkwok | 0:1da4db5de653 | 33 | |
yfkwok | 0:1da4db5de653 | 34 | // We can also print its values to the terminal |
yfkwok | 0:1da4db5de653 | 35 | sprite.print(); |
yfkwok | 0:1da4db5de653 | 36 | * @endcode |
yfkwok | 0:1da4db5de653 | 37 | */ |
yfkwok | 0:1da4db5de653 | 38 | class Bitmap |
yfkwok | 0:1da4db5de653 | 39 | { |
yfkwok | 0:1da4db5de653 | 40 | private: |
yfkwok | 0:1da4db5de653 | 41 | /** |
yfkwok | 0:1da4db5de653 | 42 | * @brief The contents of the drawing, with pixels stored in row-major order |
yfkwok | 0:1da4db5de653 | 43 | * @details '1' represents a black pixel; '0' represents white |
yfkwok | 0:1da4db5de653 | 44 | */ |
yfkwok | 0:1da4db5de653 | 45 | std::vector<int> _contents; |
yfkwok | 0:1da4db5de653 | 46 | |
yfkwok | 0:1da4db5de653 | 47 | unsigned int _height; ///< The height of the drawing in pixels |
yfkwok | 0:1da4db5de653 | 48 | unsigned int _width; ///< The width of the drawing in pixels |
yfkwok | 0:1da4db5de653 | 49 | |
yfkwok | 0:1da4db5de653 | 50 | public: |
yfkwok | 0:1da4db5de653 | 51 | Bitmap(int const *contents, |
yfkwok | 0:1da4db5de653 | 52 | unsigned int const height, |
yfkwok | 0:1da4db5de653 | 53 | unsigned int const width); |
yfkwok | 0:1da4db5de653 | 54 | |
yfkwok | 0:1da4db5de653 | 55 | int get_pixel(unsigned int const row, |
yfkwok | 0:1da4db5de653 | 56 | unsigned int const column) const; |
yfkwok | 0:1da4db5de653 | 57 | |
yfkwok | 0:1da4db5de653 | 58 | void print() const; |
yfkwok | 0:1da4db5de653 | 59 | |
yfkwok | 0:1da4db5de653 | 60 | void render(N5110 &lcd, |
yfkwok | 0:1da4db5de653 | 61 | unsigned int const x0, |
yfkwok | 0:1da4db5de653 | 62 | unsigned int const y0) const; |
yfkwok | 0:1da4db5de653 | 63 | }; |
yfkwok | 0:1da4db5de653 | 64 | |
yfkwok | 0:1da4db5de653 | 65 | #endif // BITMAP_H |