
Final Commit
Dependencies: mbed
SnakeEngine/SnakeEngine.h@13:72bc2579e85e, 2018-04-11 (annotated)
- Committer:
- JRM1986
- Date:
- Wed Apr 11 11:42:16 2018 +0000
- Revision:
- 13:72bc2579e85e
- Parent:
- 10:62d8cb7742c3
- Child:
- 14:c3a435597196
draw function, get position, set position work; When game starts, init position of snake head soesn't work, but did before. Also getting direction to determine position doesn't appear to work
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
JRM1986 | 2:ea90cec2489a | 1 | #ifndef SNAKEENGINE_H |
JRM1986 | 2:ea90cec2489a | 2 | #define SNAKEENGINE_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 | 6:f3f508cea1c4 | 8 | #include "Food.h" |
JRM1986 | 6:f3f508cea1c4 | 9 | #include "Snake.h" |
JRM1986 | 2:ea90cec2489a | 10 | |
JRM1986 | 13:72bc2579e85e | 11 | #define SNAKE_X 74 |
JRM1986 | 13:72bc2579e85e | 12 | #define SNAKE_Y 23 |
JRM1986 | 13:72bc2579e85e | 13 | #define SNAKE_DIRECTION W |
JRM1986 | 13:72bc2579e85e | 14 | |
JRM1986 | 2:ea90cec2489a | 15 | /** SnakeEngine Class |
JRM1986 | 1:c3fdbc4b1293 | 16 | * @brief Class that initialises and defines the game charectoristics ready for the main file |
JRM1986 | 1:c3fdbc4b1293 | 17 | * @author Joshua R. Marshall |
JRM1986 | 1:c3fdbc4b1293 | 18 | * @date Feb, 2018 |
JRM1986 | 2:ea90cec2489a | 19 | */ |
JRM1986 | 2:ea90cec2489a | 20 | class SnakeEngine |
JRM1986 | 2:ea90cec2489a | 21 | { |
JRM1986 | 2:ea90cec2489a | 22 | |
JRM1986 | 2:ea90cec2489a | 23 | public: |
JRM1986 | 6:f3f508cea1c4 | 24 | |
JRM1986 | 2:ea90cec2489a | 25 | SnakeEngine(); // constructor |
JRM1986 | 2:ea90cec2489a | 26 | ~SnakeEngine(); // destructor |
JRM1986 | 6:f3f508cea1c4 | 27 | |
JRM1986 | 13:72bc2579e85e | 28 | void init(Direction snake_current_direction, int snake_position_x, int snake_postion_y); // initiallises the position of the food, and snake |
JRM1986 | 6:f3f508cea1c4 | 29 | void draw(N5110 &lcd); // draws snake/food to the lcd |
JRM1986 | 6:f3f508cea1c4 | 30 | void update(Gamepad &pad); // updates depending on gamepad input |
JRM1986 | 13:72bc2579e85e | 31 | void get_input(Gamepad &pad); // gets the input from the gamepad |
JRM1986 | 6:f3f508cea1c4 | 32 | |
JRM1986 | 2:ea90cec2489a | 33 | |
JRM1986 | 2:ea90cec2489a | 34 | private: |
JRM1986 | 2:ea90cec2489a | 35 | |
JRM1986 | 6:f3f508cea1c4 | 36 | void check_wall_reached(); // checks if snake has hit the side |
JRM1986 | 6:f3f508cea1c4 | 37 | void check_food_eaten(); // checks if snake has eaten the food |
JRM1986 | 6:f3f508cea1c4 | 38 | void check_tail_collision(); // checks if snake has collided with its own tail |
JRM1986 | 6:f3f508cea1c4 | 39 | |
JRM1986 | 6:f3f508cea1c4 | 40 | // ----- Food Position ----- |
JRM1986 | 6:f3f508cea1c4 | 41 | |
JRM1986 | 6:f3f508cea1c4 | 42 | int _fx; |
JRM1986 | 6:f3f508cea1c4 | 43 | int _fy; |
JRM1986 | 6:f3f508cea1c4 | 44 | |
JRM1986 | 6:f3f508cea1c4 | 45 | Food _food; |
JRM1986 | 6:f3f508cea1c4 | 46 | |
JRM1986 | 6:f3f508cea1c4 | 47 | Snake _snake; |
JRM1986 | 10:62d8cb7742c3 | 48 | |
JRM1986 | 13:72bc2579e85e | 49 | Direction _snake_current_direction; |
JRM1986 | 13:72bc2579e85e | 50 | int _snake_position_x; |
JRM1986 | 13:72bc2579e85e | 51 | int _snake_position_y; |
JRM1986 | 13:72bc2579e85e | 52 | |
JRM1986 | 13:72bc2579e85e | 53 | Direction _in; |
JRM1986 | 10:62d8cb7742c3 | 54 | Direction _cur; |
JRM1986 | 10:62d8cb7742c3 | 55 | |
JRM1986 | 2:ea90cec2489a | 56 | |
JRM1986 | 2:ea90cec2489a | 57 | }; |
JRM1986 | 2:ea90cec2489a | 58 | #endif |