![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
testing documentation
Dependencies: mbed ll16j23s_test_docs
SnakeBody/SnakeBody.h@12:33a5cff31339, 2020-05-26 (annotated)
- Committer:
- JoeShotton
- Date:
- Tue May 26 23:57:47 2020 +0000
- Revision:
- 12:33a5cff31339
- Parent:
- 10:a2d643b3c782
documentation test 3
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
JoeShotton | 3:fcd6d70e9694 | 1 | #ifndef SNAKEBODY_H |
JoeShotton | 3:fcd6d70e9694 | 2 | #define SNAKEBODY_H |
JoeShotton | 3:fcd6d70e9694 | 3 | |
JoeShotton | 3:fcd6d70e9694 | 4 | #include "mbed.h" |
JoeShotton | 3:fcd6d70e9694 | 5 | #include "N5110.h" |
JoeShotton | 3:fcd6d70e9694 | 6 | #include "Gamepad.h" |
JoeShotton | 3:fcd6d70e9694 | 7 | #include <vector> |
JoeShotton | 3:fcd6d70e9694 | 8 | |
JoeShotton | 10:a2d643b3c782 | 9 | /** SnakeBody Class |
JoeShotton | 10:a2d643b3c782 | 10 | @author Joseph Shotton |
JoeShotton | 10:a2d643b3c782 | 11 | @brief All functions that exclusively control the snake body |
JoeShotton | 10:a2d643b3c782 | 12 | @date May 2020 |
JoeShotton | 10:a2d643b3c782 | 13 | @version V1.0 |
JoeShotton | 10:a2d643b3c782 | 14 | */ |
JoeShotton | 10:a2d643b3c782 | 15 | |
JoeShotton | 10:a2d643b3c782 | 16 | |
JoeShotton | 3:fcd6d70e9694 | 17 | class SnakeBody |
JoeShotton | 3:fcd6d70e9694 | 18 | { |
JoeShotton | 3:fcd6d70e9694 | 19 | struct Direction { |
JoeShotton | 12:33a5cff31339 | 20 | int delta_x; // increment value for x /**< x incrementation of the body in this state */ |
JoeShotton | 12:33a5cff31339 | 21 | int delta_y; // increment value for y /**< y incrementation of the body in this state */ |
JoeShotton | 12:33a5cff31339 | 22 | int nextState[5]; // array of next states /**< array of next states */ |
JoeShotton | 3:fcd6d70e9694 | 23 | }; |
JoeShotton | 3:fcd6d70e9694 | 24 | |
JoeShotton | 3:fcd6d70e9694 | 25 | public: |
JoeShotton | 3:fcd6d70e9694 | 26 | |
JoeShotton | 3:fcd6d70e9694 | 27 | SnakeBody(); |
JoeShotton | 3:fcd6d70e9694 | 28 | ~SnakeBody(); |
JoeShotton | 12:33a5cff31339 | 29 | |
JoeShotton | 12:33a5cff31339 | 30 | |
JoeShotton | 12:33a5cff31339 | 31 | /** Initialises the body |
JoeShotton | 12:33a5cff31339 | 32 | */ |
JoeShotton | 4:ea3fa51c4386 | 33 | void init(); |
JoeShotton | 12:33a5cff31339 | 34 | |
JoeShotton | 12:33a5cff31339 | 35 | |
JoeShotton | 12:33a5cff31339 | 36 | /** Adjusts the _length_increase variable so the snake's length gradually increases |
JoeShotton | 12:33a5cff31339 | 37 | *@param The body units that the snake will eventually grow to |
JoeShotton | 12:33a5cff31339 | 38 | */ |
JoeShotton | 9:0571880085cc | 39 | void add_length(int increase); |
JoeShotton | 12:33a5cff31339 | 40 | |
JoeShotton | 12:33a5cff31339 | 41 | |
JoeShotton | 12:33a5cff31339 | 42 | /** Runs the appropriate functions for the body |
JoeShotton | 12:33a5cff31339 | 43 | *@param Gamepad |
JoeShotton | 12:33a5cff31339 | 44 | *@param LCD |
JoeShotton | 12:33a5cff31339 | 45 | *@param _death is the flag for if there is a collision (in this case snake-snake) |
JoeShotton | 12:33a5cff31339 | 46 | */ |
JoeShotton | 12:33a5cff31339 | 47 | void run(Gamepad &pad, N5110 &lcd, bool &_death); |
JoeShotton | 12:33a5cff31339 | 48 | |
JoeShotton | 12:33a5cff31339 | 49 | |
JoeShotton | 12:33a5cff31339 | 50 | /** Resets body variables so game can be replayed |
JoeShotton | 12:33a5cff31339 | 51 | */ |
JoeShotton | 10:a2d643b3c782 | 52 | void reset(); |
JoeShotton | 4:ea3fa51c4386 | 53 | |
JoeShotton | 4:ea3fa51c4386 | 54 | int _x_head; |
JoeShotton | 4:ea3fa51c4386 | 55 | int _y_head; |
JoeShotton | 6:6c9453397f4a | 56 | |
JoeShotton | 6:6c9453397f4a | 57 | std::vector<int> _body_x; |
JoeShotton | 6:6c9453397f4a | 58 | std::vector<int> _body_y; |
JoeShotton | 7:dd84e0fab346 | 59 | |
JoeShotton | 3:fcd6d70e9694 | 60 | private: |
JoeShotton | 3:fcd6d70e9694 | 61 | |
JoeShotton | 12:33a5cff31339 | 62 | |
JoeShotton | 12:33a5cff31339 | 63 | /** Controls all movement functions |
JoeShotton | 12:33a5cff31339 | 64 | *@param Gamepad |
JoeShotton | 12:33a5cff31339 | 65 | */ |
JoeShotton | 9:0571880085cc | 66 | void snake_movement(Gamepad &pad); |
JoeShotton | 12:33a5cff31339 | 67 | |
JoeShotton | 12:33a5cff31339 | 68 | |
JoeShotton | 12:33a5cff31339 | 69 | /** Draws body |
JoeShotton | 12:33a5cff31339 | 70 | *@param LCD |
JoeShotton | 12:33a5cff31339 | 71 | */ |
JoeShotton | 9:0571880085cc | 72 | void draw_body(N5110 &lcd); |
JoeShotton | 12:33a5cff31339 | 73 | |
JoeShotton | 12:33a5cff31339 | 74 | /** Detects snake-snake collision |
JoeShotton | 12:33a5cff31339 | 75 | *@param Gamepad |
JoeShotton | 12:33a5cff31339 | 76 | *@param _death is the flag for if there is a collision (in this case snake-snake) |
JoeShotton | 12:33a5cff31339 | 77 | */ |
JoeShotton | 9:0571880085cc | 78 | void snake_snake_collision(Gamepad &pad, bool &_death); |
JoeShotton | 9:0571880085cc | 79 | |
JoeShotton | 12:33a5cff31339 | 80 | |
JoeShotton | 12:33a5cff31339 | 81 | /** Updates direction of snake |
JoeShotton | 12:33a5cff31339 | 82 | */ |
JoeShotton | 10:a2d643b3c782 | 83 | void update_direction(); |
JoeShotton | 12:33a5cff31339 | 84 | |
JoeShotton | 12:33a5cff31339 | 85 | |
JoeShotton | 12:33a5cff31339 | 86 | /** Updates position of snake |
JoeShotton | 12:33a5cff31339 | 87 | */ |
JoeShotton | 10:a2d643b3c782 | 88 | void update_position(); |
JoeShotton | 12:33a5cff31339 | 89 | |
JoeShotton | 12:33a5cff31339 | 90 | |
JoeShotton | 12:33a5cff31339 | 91 | /** Updates body coordinates of whole snake |
JoeShotton | 12:33a5cff31339 | 92 | */ |
JoeShotton | 4:ea3fa51c4386 | 93 | void update_body(); |
JoeShotton | 10:a2d643b3c782 | 94 | |
JoeShotton | 4:ea3fa51c4386 | 95 | float _angle; |
JoeShotton | 4:ea3fa51c4386 | 96 | int _d; |
JoeShotton | 10:a2d643b3c782 | 97 | int _move_state; |
JoeShotton | 10:a2d643b3c782 | 98 | int _length; |
JoeShotton | 9:0571880085cc | 99 | int _length_increase; |
JoeShotton | 3:fcd6d70e9694 | 100 | |
JoeShotton | 3:fcd6d70e9694 | 101 | }; |
JoeShotton | 3:fcd6d70e9694 | 102 | #endif |