
Final Commit
Dependencies: mbed
Snake/Snake.h@19:b437806e579b, 2018-04-30 (annotated)
- Committer:
- JRM1986
- Date:
- Mon Apr 30 10:13:35 2018 +0000
- Revision:
- 19:b437806e579b
- Parent:
- 18:406fc298a7c4
- Child:
- 21:63c5590cb2c2
exeptions for set direction debugged, function for set direction seperated into smaller blocks;
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 | 19:b437806e579b | 37 | void init(Direction in, Direction cur, 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 | 19:b437806e579b | 43 | void set_current(Direction input, Direction current); |
JRM1986 | 19:b437806e579b | 44 | void set_north(Direction input, Direction current); |
JRM1986 | 19:b437806e579b | 45 | void set_east(Direction input, Direction current); |
JRM1986 | 19:b437806e579b | 46 | void set_south(Direction input, Direction current); |
JRM1986 | 19:b437806e579b | 47 | void set_west(Direction input, Direction current); |
JRM1986 | 19:b437806e579b | 48 | |
JRM1986 | 9:561e5681b7a6 | 49 | Direction get_snake_direction(); |
JRM1986 | 13:72bc2579e85e | 50 | |
JRM1986 | 14:c3a435597196 | 51 | void set_current_direction(Direction input); |
JRM1986 | 11:e260c17a0489 | 52 | Direction get_current_direction(); |
JRM1986 | 13:72bc2579e85e | 53 | |
JRM1986 | 10:62d8cb7742c3 | 54 | void set_snake_position(Direction next); |
JRM1986 | 9:561e5681b7a6 | 55 | Vector2D get_snake_position(); |
JRM1986 | 14:c3a435597196 | 56 | |
JRM1986 | 14:c3a435597196 | 57 | |
JRM1986 | 2:ea90cec2489a | 58 | |
JRM1986 | 2:ea90cec2489a | 59 | private: |
JRM1986 | 9:561e5681b7a6 | 60 | |
JRM1986 | 13:72bc2579e85e | 61 | // Direction _direction; |
JRM1986 | 10:62d8cb7742c3 | 62 | Direction _next; |
JRM1986 | 13:72bc2579e85e | 63 | Direction _current; |
JRM1986 | 13:72bc2579e85e | 64 | Vector2D _pos; |
JRM1986 | 9:561e5681b7a6 | 65 | int _x; |
JRM1986 | 9:561e5681b7a6 | 66 | int _y; |
JRM1986 | 9:561e5681b7a6 | 67 | |
JRM1986 | 2:ea90cec2489a | 68 | }; |
JRM1986 | 2:ea90cec2489a | 69 | #endif |