Snake vs Block Game to be run upon K64F.

Dependencies:   mbed

Committer:
AhmedPlaymaker
Date:
Fri Apr 26 18:30:25 2019 +0000
Revision:
51:387249f9b333
Parent:
N5110/Bitmap.h@0:4b15c2d4aa58
Sorted my game classes into folders to make it more organized

Who changed what in which revision?

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