
Simon Atkinson 201255483
Dependencies: mbed
Snake Game
Summary
Hello and welcome to my Snake Game. Snake is a simple game where you control a snake and eat an apple which increases your size. Normally touching the walls will kill you, always touching yourself will make you die!
Controls
The Controls for this game are simple the Start button starts the game (who would have thought) this button is the left button on the bottom of the gamepad next to the two blue potentiometers. The Reset button on the right of the potentiometers resets the game. Once the game starts use the left thumbstick to control the movement of the snake.
If you hit the wall with your snake you will die and the game will end.
Bugs/Missing Features
Unfortunatley I wasn't able to get the game eating the apple to work, when I tried I could never get it to detect the collisions I tried a few different ways but ran out of time. Because that doesn't work the score doesn't increase and the apple doesn't spawn in a different place. I will try continue to work on this when I have time as I enjoyed doing this project even though it was very frustrating at times!
Gamepad2/Bitmap.h@21:e8d66c5f68cc, 2020-06-05 (annotated)
- Committer:
- Psy1990
- Date:
- Fri Jun 05 22:57:33 2020 +0000
- Revision:
- 21:e8d66c5f68cc
- Parent:
- 0:7423345f87c5
Final Submission. I have read and agreed with Statement of Academic Integrity.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
eencae | 0:7423345f87c5 | 1 | #ifndef BITMAP_H |
eencae | 0:7423345f87c5 | 2 | #define BITMAP_H |
eencae | 0:7423345f87c5 | 3 | |
eencae | 0:7423345f87c5 | 4 | #include <vector> |
eencae | 0:7423345f87c5 | 5 | |
eencae | 0:7423345f87c5 | 6 | // Forward declarations |
eencae | 0:7423345f87c5 | 7 | class N5110; |
eencae | 0:7423345f87c5 | 8 | |
eencae | 0:7423345f87c5 | 9 | /** |
eencae | 0:7423345f87c5 | 10 | * @brief A black & white bitmap that can be rendered on an N5110 screen |
eencae | 0:7423345f87c5 | 11 | * @author Alex Valavanis <a.valavanis@leeds.ac.uk> |
eencae | 0:7423345f87c5 | 12 | * |
eencae | 0:7423345f87c5 | 13 | * @code |
eencae | 0:7423345f87c5 | 14 | // First declare the pixel map data using '1' for black, |
eencae | 0:7423345f87c5 | 15 | // or '0' for white pixels |
eencae | 0:7423345f87c5 | 16 | static int sprite_data[] = { |
eencae | 0:7423345f87c5 | 17 | 0,0,1,0,0, |
eencae | 0:7423345f87c5 | 18 | 0,1,1,1,0, |
eencae | 0:7423345f87c5 | 19 | 0,0,1,0,0, |
eencae | 0:7423345f87c5 | 20 | 0,1,1,1,0, |
eencae | 0:7423345f87c5 | 21 | 1,1,1,1,1, |
eencae | 0:7423345f87c5 | 22 | 1,1,1,1,1, |
eencae | 0:7423345f87c5 | 23 | 1,1,0,1,1, |
eencae | 0:7423345f87c5 | 24 | 1,1,0,1,1 |
eencae | 0:7423345f87c5 | 25 | }; |
eencae | 0:7423345f87c5 | 26 | |
eencae | 0:7423345f87c5 | 27 | // Instantiate the Bitmap object using the data above |
eencae | 0:7423345f87c5 | 28 | Bitmap sprite(sprite_data, 8, 5); // Specify rows and columns in sprite |
eencae | 0:7423345f87c5 | 29 | |
eencae | 0:7423345f87c5 | 30 | // We can render the bitmap wherever we want on the screen |
eencae | 0:7423345f87c5 | 31 | sprite.render(lcd, 20, 6); // x and y locations for rendering |
eencae | 0:7423345f87c5 | 32 | sprite.render(lcd, 30, 10); |
eencae | 0:7423345f87c5 | 33 | |
eencae | 0:7423345f87c5 | 34 | // We can also print its values to the terminal |
eencae | 0:7423345f87c5 | 35 | sprite.print(); |
eencae | 0:7423345f87c5 | 36 | * @endcode |
eencae | 0:7423345f87c5 | 37 | */ |
eencae | 0:7423345f87c5 | 38 | class Bitmap |
eencae | 0:7423345f87c5 | 39 | { |
eencae | 0:7423345f87c5 | 40 | private: |
eencae | 0:7423345f87c5 | 41 | /** |
eencae | 0:7423345f87c5 | 42 | * @brief The contents of the drawing, with pixels stored in row-major order |
eencae | 0:7423345f87c5 | 43 | * @details '1' represents a black pixel; '0' represents white |
eencae | 0:7423345f87c5 | 44 | */ |
eencae | 0:7423345f87c5 | 45 | std::vector<int> _contents; |
eencae | 0:7423345f87c5 | 46 | |
eencae | 0:7423345f87c5 | 47 | unsigned int _height; ///< The height of the drawing in pixels |
eencae | 0:7423345f87c5 | 48 | unsigned int _width; ///< The width of the drawing in pixels |
eencae | 0:7423345f87c5 | 49 | |
eencae | 0:7423345f87c5 | 50 | public: |
eencae | 0:7423345f87c5 | 51 | Bitmap(int const *contents, |
eencae | 0:7423345f87c5 | 52 | unsigned int const height, |
eencae | 0:7423345f87c5 | 53 | unsigned int const width); |
eencae | 0:7423345f87c5 | 54 | |
eencae | 0:7423345f87c5 | 55 | int get_pixel(unsigned int const row, |
eencae | 0:7423345f87c5 | 56 | unsigned int const column) const; |
eencae | 0:7423345f87c5 | 57 | |
eencae | 0:7423345f87c5 | 58 | void print() const; |
eencae | 0:7423345f87c5 | 59 | |
eencae | 0:7423345f87c5 | 60 | void render(N5110 &lcd, |
eencae | 0:7423345f87c5 | 61 | unsigned int const x0, |
eencae | 0:7423345f87c5 | 62 | unsigned int const y0) const; |
eencae | 0:7423345f87c5 | 63 | }; |
eencae | 0:7423345f87c5 | 64 | |
eencae | 0:7423345f87c5 | 65 | #endif // BITMAP_H |