James Heavey / Mbed 2 deprecated EL17JH

Dependencies:   mbed

Committer:
jamesheavey
Date:
Tue Apr 16 18:58:18 2019 +0000
Revision:
0:7d4d2023ed9c
Game changed to breakout form space invaders (new folder) template initialised, edited paddle, edited direction of movement, edited collision boundaries

Who changed what in which revision?

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