Game
Embed:
(wiki syntax)
Show/hide line numbers
Mechanics.h
00001 //#define DEBUG_SPEED 00002 //#define DEBUG_POSITION 00003 //#define DEBUG_ANGLE 00004 //#define DEBUG_GATE 00005 //#define DEBUG_OFF_TRACK 00006 //#define DEBUG_OUT_OF_BOUNDS 00007 00008 #ifndef MECHANICS_H 00009 #define MECHANICS_H 00010 00011 #include "mbed.h" 00012 #include "Gamepad.h" 00013 #include "N5110.h" 00014 #include "FXOS8700CQ.h" 00015 #include "Graphics.h" 00016 #include "Mechanics.h" 00017 #include "Menu.h" 00018 #include "LEDs.h" 00019 #include "Ghost.h" 00020 #include <string> 00021 00022 #ifndef STRUCTS 00023 #define STRUCTS 00024 00025 //STRUCTS 00026 struct Point_2D { 00027 float x; 00028 float y; 00029 }; 00030 struct Line_2D { 00031 Point_2D from; 00032 Point_2D to; 00033 }; 00034 00035 struct Square_2D { 00036 Point_2D TL; 00037 Point_2D BR; 00038 }; 00039 struct Triangle_2D { 00040 Point_2D TL; 00041 Point_2D BR; 00042 int Type; 00043 }; 00044 00045 struct Sprite_2D { 00046 float x; 00047 float y; 00048 int type; 00049 }; 00050 00051 struct Map_Data { 00052 int number_of_track_lines; 00053 int number_of_dotted_lines; 00054 int number_of_sprites; 00055 int number_of_walls; 00056 int number_of_off_track_squares; 00057 int number_of_off_track_triangles; 00058 int number_of_out_of_bounds_squares; 00059 int number_of_out_of_bounds_triangles; 00060 int number_of_gates; 00061 int number_of_boost_plates; 00062 }; 00063 00064 struct Time { 00065 int mins; 00066 int secs; 00067 int milis; 00068 }; 00069 00070 struct Gyro_Data { 00071 float ax; 00072 float ay; 00073 float az; 00074 float mx; 00075 float my; 00076 float mz; 00077 }; 00078 00079 #endif 00080 00081 #ifndef ENUMS 00082 #define ENUMS 00083 enum track {Small, Medium, Large}; //Track Names 00084 enum cars {Basic, Offroad, Drifter, Sportscar, Racecar, Stupid}; //Car Names (Stupid is now the alien space ship) 00085 enum sprites {Flag, Helicopter, People_Standing_1, People_Standing_2, People_Cheering}; 00086 #endif 00087 00088 /** Mechanics Class 00089 * @brief Operates the game. 00090 * @author Henry W Triff 00091 * @date Mar, 2020 00092 */ 00093 00094 class Mechanics 00095 { 00096 public: 00097 00098 /** Constructor */ 00099 Mechanics(); 00100 00101 /** Destructor */ 00102 ~Mechanics(); 00103 00104 /** Checks the current position of the player to see if they are in the next gate, returns either the current gate or increases the gate 00105 * @param gates[] The array containing all the gates (Square_2D) 00106 * @param number_of_gates Number of gates in the array (int) 00107 * @param position This is the current position of the player (Point_2D) 00108 * @param current_gate The current gate that has been driven over (int) 00109 * @return Current gate number (int) 00110 */ 00111 int Get_Gate(const Square_2D gates[], int number_of_gates, Point_2D position, int current_gate); 00112 00113 /** Checks the current position of the player to see if they are about to complete a lap 00114 * @param laps The current number of laps (int) 00115 * @param gates[] The array containing all the gates (Square_2D) 00116 * @param number_of_gates Number of gates in the array (int) 00117 * @param position This is the current position of the player (Point_2D) 00118 * @param current_gate The current gate that has been driven over (int) 00119 * @return The new current number of laps (int) 00120 */ 00121 int Get_Laps(int laps, const Square_2D gates[], int number_of_gates, Point_2D position, int current_gate); 00122 00123 /** Converts between the number of elapsed frames to time in min,sec,mili 00124 * @param game_fps The fps of the game (int) 00125 * @param number_of_frames The number of frames elapsed so far during the current race (int) 00126 * @return The time in minutes, seconds, miliseconds format (Time) 00127 */ 00128 Time Convert_To_Time(int game_fps, int number_of_frames); 00129 00130 /** Returns the current angle of rotation of the map using the previos rotation 00131 * @param angle The currrent angle of roatation of the map (int) 00132 * @param handling The maximum number of degrees of rotation for that given cars handling (int) 00133 * @param gyro_enabled Has gyroscope steering been enabled in settings (bool) 00134 * @param Gyro The gyroscope class object (object) 00135 * @param Device The gamepad class object (Device) 00136 * @return The new current angle of map rotation (int) 00137 */ 00138 int Get_Angle(int angle, int handling, bool gyro_enabled, FXOS8700CQ &Gyro, Gamepad &Device); 00139 00140 /** Returns the current map translation usung the previos translation 00141 * @param in The currrent map translation(Point_2D) 00142 * @param angle The current angle of roataion of the map [Drection of travel] (float) 00143 * @param speed The current of the player (float) 00144 * @param *out_of_bounds_square The pointer for the array of square out of bounds areas(Square_2D) 00145 * @param *out_of_bounds_triangle The pointer for the array of triange out of bounds areas(Triangle_2D) 00146 * @param map_info The number of elements in each array above (Map_Data) 00147 * @param Device The gamepad class object (Device) 00148 * @return The new current translation (Point_2D) 00149 */ 00150 Point_2D Get_Translation( 00151 Point_2D in, 00152 float angle, 00153 float speed, 00154 const Square_2D *out_of_bounds_square, 00155 const Triangle_2D *out_of_bounds_triangle, 00156 const Map_Data map_info, 00157 Gamepad &Device 00158 ); 00159 00160 /** Returns the current speed using the previos speed 00161 * @param speed The currrent speed(float) 00162 * @param max_speed The maximum speed of the chosen car (float) 00163 * @param acceleration The acceleration of the chosen car (float) 00164 * @param deceleration The deceleration of the chosen car (float) 00165 * @param off_track_speed The maximum speed when off track of the chosen car (float) 00166 * @param position The current position of the car (Point_2D) 00167 * @param *offtrack_square The pointer for the array of square of off track areas(Square_2D) 00168 * @param *offtrack_triangle The pointer for the array of triange of off track areas(Triangle_2D) 00169 * @param *out_of_bounds_square The pointer for the array of square out of bounds areas(Square_2D) 00170 * @param *out_of_bounds_triangle The pointer for the array of triange out of bounds areas(Triangle_2D) 00171 * @param *plates The pointer for the boost plates array (Triangle_2D) 00172 * @param map_info The number of elements in each array above (Map_Data) 00173 * @param Device The gamepad class object (Device) 00174 * @return The new current speed (float) 00175 */ 00176 float Get_Speed( 00177 float speed, 00178 float max_speed, 00179 float acceleration, 00180 float deceleration, 00181 float off_track_speed, 00182 Point_2D position, 00183 const Square_2D *offtrack_square, 00184 const Triangle_2D *offtrack_triangle, 00185 const Square_2D *out_of_bounds_square, 00186 const Triangle_2D *out_of_bounds_triangle, 00187 const Triangle_2D *plates, 00188 const Map_Data map_info, 00189 Gamepad &Device 00190 ); 00191 00192 /** Returns the max speed for the chosen vehicle 00193 * @param car_model The chosen car model (int) 00194 * @return The maximum speed (float) 00195 */ 00196 float Get_Max_Speed(int car_model); 00197 00198 /** Returns the acceleration for the chosen vehicle 00199 * @param car_model The chosen car model (int) 00200 * @return The acceleration (float) 00201 */ 00202 float Get_Acceleration(int car_model); 00203 00204 /** Returns the decleration for the chosen vehicle 00205 * @param car_model The chosen car model (int) 00206 * @return The deceleration (float) 00207 */ 00208 float Get_Deceleration(int car_model); 00209 00210 /** Returns the max speed when off road for the chosen vehicle 00211 * @param car_model The chosen car model (int) 00212 * @return The maximum speed when off road (float) 00213 */ 00214 float Get_Off_Road_Speed(int car_model); 00215 00216 /** Returns the handling of the chosen vehicle 00217 * @param car_model The chosen car model (int) 00218 * @return The handling (float) 00219 */ 00220 int Get_Handling(int car_model); 00221 00222 private: 00223 //SPEED 00224 bool Is_Offtrack(Point_2D position, const Square_2D offtrack_square[], const Triangle_2D offtrack_triangle[], const Map_Data map_info); 00225 bool Is_Out_Of_Bounds(Point_2D position, const Square_2D offtrack_square[], const Triangle_2D offtrack_triangle[], const Map_Data map_info); 00226 bool Is_Offtrack_Square(const Square_2D offtrack[], int size, Point_2D position); 00227 bool Is_Offtrack_Triangle(const Triangle_2D offtrack[], int size, Point_2D position); 00228 bool Is_Out_Of_Bounds_Square(const Square_2D out_of_bounds[], int size, Point_2D position); 00229 bool Is_Out_Of_Bounds_Triangle(const Triangle_2D out_of_bounds[], int size, Point_2D position); 00230 float Get_Boost_Speed(const Triangle_2D plates[], int number_of_plates, Point_2D position, float speed); 00231 00232 }; 00233 00234 #endif
Generated on Wed Jul 20 2022 17:42:24 by
1.7.2