
Final Commit
Dependencies: mbed
SnakeEngine/SnakeEngine.h@21:63c5590cb2c2, 2018-04-30 (annotated)
- Committer:
- JRM1986
- Date:
- Mon Apr 30 14:37:23 2018 +0000
- Revision:
- 21:63c5590cb2c2
- Parent:
- 20:277e88a8185f
- Child:
- 23:3081be418c89
No longer increments in steps of 2, init functions 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 | |
JRM1986 | 2:ea90cec2489a | 12 | /** SnakeEngine Class |
JRM1986 | 1:c3fdbc4b1293 | 13 | * @brief Class that initialises and defines the game charectoristics ready for the main file |
JRM1986 | 1:c3fdbc4b1293 | 14 | * @author Joshua R. Marshall |
JRM1986 | 1:c3fdbc4b1293 | 15 | * @date Feb, 2018 |
JRM1986 | 2:ea90cec2489a | 16 | */ |
JRM1986 | 16:85ca9feccf3f | 17 | |
JRM1986 | 16:85ca9feccf3f | 18 | int g_tail_length(); |
JRM1986 | 17:94dd8a691d4a | 19 | Vector2D g_tail_position(); |
JRM1986 | 17:94dd8a691d4a | 20 | |
JRM1986 | 17:94dd8a691d4a | 21 | int g_get_even_array(); |
JRM1986 | 17:94dd8a691d4a | 22 | int g_get_odd_array(); |
JRM1986 | 17:94dd8a691d4a | 23 | int g_get_engine_frame_count(); |
JRM1986 | 16:85ca9feccf3f | 24 | |
JRM1986 | 16:85ca9feccf3f | 25 | static Vector2D g_tp; |
JRM1986 | 16:85ca9feccf3f | 26 | static int g_tl; |
JRM1986 | 17:94dd8a691d4a | 27 | static int g_tc; |
JRM1986 | 17:94dd8a691d4a | 28 | static int g_engine_fc; |
JRM1986 | 16:85ca9feccf3f | 29 | |
JRM1986 | 17:94dd8a691d4a | 30 | static int g_odd_array_x[100]; |
JRM1986 | 17:94dd8a691d4a | 31 | static int g_odd_array_y[100]; |
JRM1986 | 17:94dd8a691d4a | 32 | static int g_even_array_x[100]; |
JRM1986 | 17:94dd8a691d4a | 33 | static int g_even_array_y[100]; |
JRM1986 | 17:94dd8a691d4a | 34 | static int g_array_x[100]; |
JRM1986 | 17:94dd8a691d4a | 35 | static int g_array_y[100]; |
JRM1986 | 17:94dd8a691d4a | 36 | |
JRM1986 | 17:94dd8a691d4a | 37 | Vector2D g_holder_pos(); |
JRM1986 | 17:94dd8a691d4a | 38 | |
JRM1986 | 17:94dd8a691d4a | 39 | |
JRM1986 | 16:85ca9feccf3f | 40 | |
JRM1986 | 16:85ca9feccf3f | 41 | |
JRM1986 | 2:ea90cec2489a | 42 | class SnakeEngine |
JRM1986 | 2:ea90cec2489a | 43 | { |
JRM1986 | 2:ea90cec2489a | 44 | |
JRM1986 | 2:ea90cec2489a | 45 | public: |
JRM1986 | 6:f3f508cea1c4 | 46 | |
JRM1986 | 2:ea90cec2489a | 47 | SnakeEngine(); // constructor |
JRM1986 | 2:ea90cec2489a | 48 | ~SnakeEngine(); // destructor |
JRM1986 | 6:f3f508cea1c4 | 49 | |
JRM1986 | 19:b437806e579b | 50 | void init(Direction in, Direction cur, int pos_x, int pos_y); // initiallises the position of the food, and snake |
JRM1986 | 6:f3f508cea1c4 | 51 | void draw(N5110 &lcd); // draws snake/food to the lcd |
JRM1986 | 6:f3f508cea1c4 | 52 | void update(Gamepad &pad); // updates depending on gamepad input |
JRM1986 | 13:72bc2579e85e | 53 | void get_input(Gamepad &pad); // gets the input from the gamepad |
JRM1986 | 6:f3f508cea1c4 | 54 | |
JRM1986 | 16:85ca9feccf3f | 55 | bool detect_food_collision(Gamepad &pad); |
JRM1986 | 19:b437806e579b | 56 | bool detect_wall_collision(Gamepad &pad); |
JRM1986 | 16:85ca9feccf3f | 57 | bool detect_tail_collision(); |
JRM1986 | 16:85ca9feccf3f | 58 | |
JRM1986 | 16:85ca9feccf3f | 59 | void set_tail_length(bool collision_detected); |
JRM1986 | 16:85ca9feccf3f | 60 | int get_tail_length(); |
JRM1986 | 16:85ca9feccf3f | 61 | |
JRM1986 | 17:94dd8a691d4a | 62 | void set_odd_array(Gamepad &pad); |
JRM1986 | 17:94dd8a691d4a | 63 | void set_even_array(Gamepad &pad); |
JRM1986 | 17:94dd8a691d4a | 64 | void set_tail_array(Gamepad &pad); |
JRM1986 | 16:85ca9feccf3f | 65 | |
JRM1986 | 16:85ca9feccf3f | 66 | void draw_tail(N5110 &lcd); |
JRM1986 | 16:85ca9feccf3f | 67 | |
JRM1986 | 2:ea90cec2489a | 68 | |
JRM1986 | 2:ea90cec2489a | 69 | private: |
JRM1986 | 2:ea90cec2489a | 70 | |
JRM1986 | 6:f3f508cea1c4 | 71 | |
JRM1986 | 6:f3f508cea1c4 | 72 | Food _food; |
JRM1986 | 6:f3f508cea1c4 | 73 | |
JRM1986 | 6:f3f508cea1c4 | 74 | Snake _snake; |
JRM1986 | 10:62d8cb7742c3 | 75 | |
JRM1986 | 17:94dd8a691d4a | 76 | //Direction _snake_current_direction; |
JRM1986 | 20:277e88a8185f | 77 | int _snake_pos_x; |
JRM1986 | 20:277e88a8185f | 78 | int _snake_pos_y; |
JRM1986 | 13:72bc2579e85e | 79 | |
JRM1986 | 13:72bc2579e85e | 80 | Direction _in; |
JRM1986 | 10:62d8cb7742c3 | 81 | Direction _cur; |
JRM1986 | 10:62d8cb7742c3 | 82 | |
JRM1986 | 18:406fc298a7c4 | 83 | bool _collision; |
JRM1986 | 18:406fc298a7c4 | 84 | |
JRM1986 | 21:63c5590cb2c2 | 85 | static int _odd_array_x[100]; |
JRM1986 | 21:63c5590cb2c2 | 86 | static int _odd_array_y[100]; |
JRM1986 | 21:63c5590cb2c2 | 87 | static int _even_array_x[100]; |
JRM1986 | 21:63c5590cb2c2 | 88 | static int _even_array_y[100]; |
JRM1986 | 17:94dd8a691d4a | 89 | int _array_x[100]; |
JRM1986 | 17:94dd8a691d4a | 90 | int _array_y[100]; |
JRM1986 | 17:94dd8a691d4a | 91 | |
JRM1986 | 17:94dd8a691d4a | 92 | int _tail_x; |
JRM1986 | 17:94dd8a691d4a | 93 | int _tail_y; |
JRM1986 | 17:94dd8a691d4a | 94 | |
JRM1986 | 21:63c5590cb2c2 | 95 | int _number_food_frames; |
JRM1986 | 21:63c5590cb2c2 | 96 | |
JRM1986 | 2:ea90cec2489a | 97 | |
JRM1986 | 2:ea90cec2489a | 98 | }; |
JRM1986 | 2:ea90cec2489a | 99 | #endif |