Final Commit

Dependencies:   mbed

Committer:
JRM1986
Date:
Tue May 01 12:20:42 2018 +0000
Revision:
24:4b180348826e
Parent:
23:3081be418c89
Child:
25:f03439ee32c6
Comments done;

Who changed what in which revision?

UserRevisionLine numberNew 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 23:3081be418c89 50
JRM1986 23:3081be418c89 51 /** Initialises the directions for the snake and the position for the food
JRM1986 23:3081be418c89 52 * @param Input direction from pad
JRM1986 23:3081be418c89 53 * @param Current direction of snake
JRM1986 23:3081be418c89 54 * @param pos_x x position
JRM1986 23:3081be418c89 55 * @param pos_y y position
JRM1986 23:3081be418c89 56 */
JRM1986 23:3081be418c89 57
JRM1986 23:3081be418c89 58 void init(Direction in, Direction cur, int pos_x, int pos_y);
JRM1986 23:3081be418c89 59
JRM1986 23:3081be418c89 60 /** Updates the Food and Snake classes from the Gamepad
JRM1986 23:3081be418c89 61 */
JRM1986 23:3081be418c89 62
JRM1986 23:3081be418c89 63 void update(Gamepad &pad);
JRM1986 23:3081be418c89 64
JRM1986 24:4b180348826e 65 /** Draws the game to the lcd */
JRM1986 24:4b180348826e 66
JRM1986 24:4b180348826e 67 void draw(N5110 &lcd);
JRM1986 24:4b180348826e 68
JRM1986 24:4b180348826e 69 /** Draws the tail segments on the lcd */
JRM1986 24:4b180348826e 70
JRM1986 24:4b180348826e 71 void draw_tail(N5110 &lcd);
JRM1986 24:4b180348826e 72
JRM1986 23:3081be418c89 73 /** Gets the updated direction from the Gamepad and stores it in a struct
JRM1986 23:3081be418c89 74 */
JRM1986 23:3081be418c89 75
JRM1986 23:3081be418c89 76 void get_input(Gamepad &pad);
JRM1986 23:3081be418c89 77
JRM1986 23:3081be418c89 78 /** Check if snake has eaten food
JRM1986 23:3081be418c89 79 */
JRM1986 6:f3f508cea1c4 80
JRM1986 16:85ca9feccf3f 81 bool detect_food_collision(Gamepad &pad);
JRM1986 23:3081be418c89 82
JRM1986 23:3081be418c89 83 /** Checks if snake has hit wall
JRM1986 23:3081be418c89 84 */
JRM1986 19:b437806e579b 85 bool detect_wall_collision(Gamepad &pad);
JRM1986 23:3081be418c89 86
JRM1986 23:3081be418c89 87 /** Checks if snake has hit it's own tail
JRM1986 23:3081be418c89 88 */
JRM1986 23:3081be418c89 89
JRM1986 16:85ca9feccf3f 90 bool detect_tail_collision();
JRM1986 16:85ca9feccf3f 91
JRM1986 23:3081be418c89 92 /** Increments the length variable for tail when food is eaten
JRM1986 23:3081be418c89 93 * @param Checks if food and head have collided (been eaten)
JRM1986 23:3081be418c89 94 */
JRM1986 23:3081be418c89 95
JRM1986 16:85ca9feccf3f 96 void set_tail_length(bool collision_detected);
JRM1986 23:3081be418c89 97
JRM1986 23:3081be418c89 98 /** Gets the updated length
JRM1986 23:3081be418c89 99 * @return returns the length of the tail
JRM1986 23:3081be418c89 100 */
JRM1986 23:3081be418c89 101
JRM1986 16:85ca9feccf3f 102 int get_tail_length();
JRM1986 23:3081be418c89 103
JRM1986 23:3081be418c89 104 /** Creates an updated array of tail segments
JRM1986 23:3081be418c89 105 * @details When the engine_frame counter is odd it sets the odd_array,
JRM1986 23:3081be418c89 106 when the engine counter is even it sets the even_array.
JRM1986 23:3081be418c89 107 */
JRM1986 16:85ca9feccf3f 108
JRM1986 23:3081be418c89 109 void set_tail_array(Gamepad &pad);
JRM1986 23:3081be418c89 110
JRM1986 23:3081be418c89 111 /** Updates the odd array with new positions
JRM1986 23:3081be418c89 112 * @details For the odd array it initially sets index 0 of even array to the
JRM1986 23:3081be418c89 113 new position, then makes each odd index equal to the even
JRM1986 23:3081be418c89 114 index -1 starting from the the bottom of the array finally adding
JRM1986 23:3081be418c89 115 the new position to index 0
JRM1986 23:3081be418c89 116 */
JRM1986 23:3081be418c89 117
JRM1986 17:94dd8a691d4a 118 void set_odd_array(Gamepad &pad);
JRM1986 23:3081be418c89 119
JRM1986 23:3081be418c89 120 /** Updates the even array with new positions
JRM1986 23:3081be418c89 121 * @details For the even array it initially sets index 0 of odd array to the
JRM1986 23:3081be418c89 122 new position, then makes each even index equal to the odd
JRM1986 23:3081be418c89 123 index -1 starting from the the bottom of the array finally adding
JRM1986 23:3081be418c89 124 the new position to index 0
JRM1986 23:3081be418c89 125 */
JRM1986 23:3081be418c89 126
JRM1986 17:94dd8a691d4a 127 void set_even_array(Gamepad &pad);
JRM1986 16:85ca9feccf3f 128
JRM1986 2:ea90cec2489a 129 private:
JRM1986 2:ea90cec2489a 130
JRM1986 6:f3f508cea1c4 131
JRM1986 6:f3f508cea1c4 132 Food _food;
JRM1986 6:f3f508cea1c4 133
JRM1986 6:f3f508cea1c4 134 Snake _snake;
JRM1986 10:62d8cb7742c3 135
JRM1986 17:94dd8a691d4a 136 //Direction _snake_current_direction;
JRM1986 20:277e88a8185f 137 int _snake_pos_x;
JRM1986 20:277e88a8185f 138 int _snake_pos_y;
JRM1986 13:72bc2579e85e 139
JRM1986 13:72bc2579e85e 140 Direction _in;
JRM1986 10:62d8cb7742c3 141 Direction _cur;
JRM1986 10:62d8cb7742c3 142
JRM1986 18:406fc298a7c4 143 bool _collision;
JRM1986 18:406fc298a7c4 144
JRM1986 21:63c5590cb2c2 145 static int _odd_array_x[100];
JRM1986 21:63c5590cb2c2 146 static int _odd_array_y[100];
JRM1986 21:63c5590cb2c2 147 static int _even_array_x[100];
JRM1986 21:63c5590cb2c2 148 static int _even_array_y[100];
JRM1986 17:94dd8a691d4a 149 int _array_x[100];
JRM1986 17:94dd8a691d4a 150 int _array_y[100];
JRM1986 17:94dd8a691d4a 151
JRM1986 17:94dd8a691d4a 152 int _tail_x;
JRM1986 17:94dd8a691d4a 153 int _tail_y;
JRM1986 17:94dd8a691d4a 154
JRM1986 21:63c5590cb2c2 155 int _number_food_frames;
JRM1986 21:63c5590cb2c2 156
JRM1986 2:ea90cec2489a 157
JRM1986 2:ea90cec2489a 158 };
JRM1986 2:ea90cec2489a 159 #endif