testing documentation
Dependencies: mbed ll16j23s_test_docs
SnakeBody/SnakeBody.h@4:ea3fa51c4386, 2020-05-23 (annotated)
- Committer:
- JoeShotton
- Date:
- Sat May 23 15:31:30 2020 +0000
- Revision:
- 4:ea3fa51c4386
- Parent:
- 3:fcd6d70e9694
- Child:
- 6:6c9453397f4a
Food and snake collisions implemented, still buggy
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 | 3:fcd6d70e9694 | 9 | class SnakeBody |
JoeShotton | 3:fcd6d70e9694 | 10 | { |
JoeShotton | 3:fcd6d70e9694 | 11 | struct Direction { |
JoeShotton | 4:ea3fa51c4386 | 12 | int delta_x; // increment value for x |
JoeShotton | 4:ea3fa51c4386 | 13 | int delta_y; // increment value for y |
JoeShotton | 4:ea3fa51c4386 | 14 | int nextState[5]; // array of next states |
JoeShotton | 3:fcd6d70e9694 | 15 | }; |
JoeShotton | 3:fcd6d70e9694 | 16 | |
JoeShotton | 3:fcd6d70e9694 | 17 | public: |
JoeShotton | 3:fcd6d70e9694 | 18 | |
JoeShotton | 3:fcd6d70e9694 | 19 | SnakeBody(); |
JoeShotton | 3:fcd6d70e9694 | 20 | ~SnakeBody(); |
JoeShotton | 4:ea3fa51c4386 | 21 | void init(); |
JoeShotton | 4:ea3fa51c4386 | 22 | void snake_movement(Gamepad &pad); |
JoeShotton | 4:ea3fa51c4386 | 23 | void draw_body(N5110 &lcd); |
JoeShotton | 4:ea3fa51c4386 | 24 | void snake_snake_collision(Gamepad &pad, bool &death); //(int _x_head, int _y_head, vector<int> _body_x, vector<int> _body_y, int _length); |
JoeShotton | 4:ea3fa51c4386 | 25 | |
JoeShotton | 4:ea3fa51c4386 | 26 | int _state; |
JoeShotton | 4:ea3fa51c4386 | 27 | int _x_head; |
JoeShotton | 4:ea3fa51c4386 | 28 | int _y_head; |
JoeShotton | 4:ea3fa51c4386 | 29 | int _length; |
JoeShotton | 3:fcd6d70e9694 | 30 | /* |
JoeShotton | 3:fcd6d70e9694 | 31 | void init(int x,int height,int width); |
JoeShotton | 3:fcd6d70e9694 | 32 | void draw(N5110 &lcd); |
JoeShotton | 3:fcd6d70e9694 | 33 | void update(Direction d,float mag); |
JoeShotton | 3:fcd6d70e9694 | 34 | void add_score(); |
JoeShotton | 3:fcd6d70e9694 | 35 | int get_score(); |
JoeShotton | 3:fcd6d70e9694 | 36 | Vector2D get_pos(); |
JoeShotton | 3:fcd6d70e9694 | 37 | */ |
JoeShotton | 3:fcd6d70e9694 | 38 | private: |
JoeShotton | 3:fcd6d70e9694 | 39 | |
JoeShotton | 4:ea3fa51c4386 | 40 | int update_direction(float _angle, int _x_head, int _y_head); //int _angle, int _x_head, int _y_head |
JoeShotton | 4:ea3fa51c4386 | 41 | void update_position(); //int _d, int _state, int &_x_head, int &_y_head |
JoeShotton | 4:ea3fa51c4386 | 42 | void update_body(); |
JoeShotton | 4:ea3fa51c4386 | 43 | |
JoeShotton | 3:fcd6d70e9694 | 44 | std::vector<int> _body_x; |
JoeShotton | 3:fcd6d70e9694 | 45 | std::vector<int> _body_y; |
JoeShotton | 4:ea3fa51c4386 | 46 | float _angle; |
JoeShotton | 4:ea3fa51c4386 | 47 | int _d; |
JoeShotton | 3:fcd6d70e9694 | 48 | |
JoeShotton | 3:fcd6d70e9694 | 49 | /* |
JoeShotton | 3:fcd6d70e9694 | 50 | int _height; |
JoeShotton | 3:fcd6d70e9694 | 51 | int _width; |
JoeShotton | 3:fcd6d70e9694 | 52 | int _x; |
JoeShotton | 3:fcd6d70e9694 | 53 | int _y; |
JoeShotton | 3:fcd6d70e9694 | 54 | int _speed; |
JoeShotton | 3:fcd6d70e9694 | 55 | int _score; |
JoeShotton | 3:fcd6d70e9694 | 56 | */ |
JoeShotton | 3:fcd6d70e9694 | 57 | }; |
JoeShotton | 3:fcd6d70e9694 | 58 | #endif |