
Final Commit
Dependencies: mbed
Snake/Snake.h@14:c3a435597196, 2018-04-12 (annotated)
- Committer:
- JRM1986
- Date:
- Thu Apr 12 11:20:27 2018 +0000
- Revision:
- 14:c3a435597196
- Parent:
- 13:72bc2579e85e
- Child:
- 18:406fc298a7c4
Snake movement & position incrementation works and is drawn on lcd; Crashes when NE, SE, SW, & NW are selected
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
JRM1986 | 2:ea90cec2489a | 1 | #ifndef SNAKE_H |
JRM1986 | 2:ea90cec2489a | 2 | #define SNAKE_H |
JRM1986 | 2:ea90cec2489a | 3 | |
JRM1986 | 2:ea90cec2489a | 4 | #include "mbed.h" |
JRM1986 | 3:50f01159c61d | 5 | #include "FXOS8700CQ.h" |
JRM1986 | 3:50f01159c61d | 6 | #include "Gamepad.h" |
JRM1986 | 2:ea90cec2489a | 7 | #include "N5110.h" |
JRM1986 | 13:72bc2579e85e | 8 | /* |
JRM1986 | 9:561e5681b7a6 | 9 | struct StateDirection { |
JRM1986 | 9:561e5681b7a6 | 10 | |
JRM1986 | 9:561e5681b7a6 | 11 | Direction output; |
JRM1986 | 9:561e5681b7a6 | 12 | Direction nextState[4]; |
JRM1986 | 9:561e5681b7a6 | 13 | |
JRM1986 | 9:561e5681b7a6 | 14 | }; |
JRM1986 | 13:72bc2579e85e | 15 | */ |
JRM1986 | 13:72bc2579e85e | 16 | Vector2D g_snake_position(); // global function to increment/decrement the position of the snake |
JRM1986 | 13:72bc2579e85e | 17 | Direction g_current_direction(); // global variable to hold the current direction |
JRM1986 | 12:9f2f64016f56 | 18 | |
JRM1986 | 13:72bc2579e85e | 19 | static Vector2D g_p; // global variable to increment/decrement the position of the snake |
JRM1986 | 13:72bc2579e85e | 20 | static Direction g_d; // global variable to hold the current direction |
JRM1986 | 12:9f2f64016f56 | 21 | |
JRM1986 | 9:561e5681b7a6 | 22 | |
JRM1986 | 2:ea90cec2489a | 23 | /** Snake Class |
JRM1986 | 1:c3fdbc4b1293 | 24 | * @brief Describes the methods and functions for the snake |
JRM1986 | 1:c3fdbc4b1293 | 25 | * @author Joshua R. Marshall |
JRM1986 | 1:c3fdbc4b1293 | 26 | * @date Feb, 2018 |
JRM1986 | 2:ea90cec2489a | 27 | */ |
JRM1986 | 9:561e5681b7a6 | 28 | |
JRM1986 | 2:ea90cec2489a | 29 | class Snake |
JRM1986 | 2:ea90cec2489a | 30 | { |
JRM1986 | 2:ea90cec2489a | 31 | |
JRM1986 | 2:ea90cec2489a | 32 | public: |
JRM1986 | 9:561e5681b7a6 | 33 | |
JRM1986 | 2:ea90cec2489a | 34 | Snake(); // constructor |
JRM1986 | 2:ea90cec2489a | 35 | ~Snake(); // destructor |
JRM1986 | 13:72bc2579e85e | 36 | |
JRM1986 | 14:c3a435597196 | 37 | void init(int pos_x, int pos_y); |
JRM1986 | 13:72bc2579e85e | 38 | |
JRM1986 | 10:62d8cb7742c3 | 39 | void update(Direction in, Direction cur); |
JRM1986 | 9:561e5681b7a6 | 40 | void draw(N5110 &lcd); |
JRM1986 | 9:561e5681b7a6 | 41 | |
JRM1986 | 10:62d8cb7742c3 | 42 | void set_snake_direction(Direction input, Direction current); |
JRM1986 | 9:561e5681b7a6 | 43 | Direction get_snake_direction(); |
JRM1986 | 13:72bc2579e85e | 44 | |
JRM1986 | 14:c3a435597196 | 45 | void set_current_direction(Direction input); |
JRM1986 | 11:e260c17a0489 | 46 | Direction get_current_direction(); |
JRM1986 | 13:72bc2579e85e | 47 | |
JRM1986 | 10:62d8cb7742c3 | 48 | void set_snake_position(Direction next); |
JRM1986 | 9:561e5681b7a6 | 49 | Vector2D get_snake_position(); |
JRM1986 | 14:c3a435597196 | 50 | |
JRM1986 | 14:c3a435597196 | 51 | |
JRM1986 | 2:ea90cec2489a | 52 | |
JRM1986 | 2:ea90cec2489a | 53 | private: |
JRM1986 | 9:561e5681b7a6 | 54 | |
JRM1986 | 13:72bc2579e85e | 55 | // Direction _direction; |
JRM1986 | 10:62d8cb7742c3 | 56 | Direction _next; |
JRM1986 | 13:72bc2579e85e | 57 | Direction _current; |
JRM1986 | 13:72bc2579e85e | 58 | Vector2D _pos; |
JRM1986 | 9:561e5681b7a6 | 59 | int _x; |
JRM1986 | 9:561e5681b7a6 | 60 | int _y; |
JRM1986 | 9:561e5681b7a6 | 61 | |
JRM1986 | 2:ea90cec2489a | 62 | }; |
JRM1986 | 2:ea90cec2489a | 63 | #endif |