Mochu Yao explorer game

Dependencies:   mbed

Committer:
el17my
Date:
Wed Apr 15 08:17:18 2020 +0000
Revision:
1:ed745421d8c4
second part of the code 4/13

Who changed what in which revision?

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