Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Mechanics/Mechanics.h
- Committer:
- HenryWTriff
- Date:
- 2020-03-28
- Revision:
- 20:f8d7b04471b8
- Parent:
- 19:0245df53e919
- Child:
- 22:9065c457a45d
File content as of revision 20:f8d7b04471b8:
#ifndef MECHANICS_H #define MECHANICS_H #include "mbed.h" #include "Gamepad.h" #include "N5110.h" #include "FXOS8700CQ.h" #include "Graphics.h" #include "Mechanics.h" #include "Menu.h" #include "LEDs.h" #include "Ghost.h" #include <string> /** Mechanics Class * @brief Operates the game. * @author Henry W Triff * @date Mar, 2020 */ #ifndef STRUCTS #define STRUCTS //STRUCTS struct Point_2D { float x; float y; }; struct Line_2D { Point_2D from; Point_2D to; }; struct Square_2D { Point_2D TL; Point_2D BR; }; struct Triangle_2D { Point_2D TL; Point_2D BR; int Type; }; struct Map_Data { int number_of_track_lines; int number_of_dotted_lines; int number_of_flags; int number_of_walls; int number_of_off_track_squares; int number_of_off_track_triangles; int number_of_out_of_bounds_squares; int number_of_out_of_bounds_triangles; int number_of_gates; int number_of_boost_plates; }; struct Time { int mins; int secs; int milis; }; struct Gyro_Data { float ax; float ay; float az; float mx; float my; float mz; }; #endif #ifndef ENUMS #define ENUMS enum track {Small, Medium, Large}; enum cars {Basic, Offroad, Drifter, Sportscar, Racecar, Stupid}; #endif class Mechanics { public: /** Constructor */ Mechanics(); /** Destructor */ ~Mechanics(); /** 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 * @param gates[] The array containing all the gates (Square_2D) * @param number_of_gates Number of gates in the array (int) * @param position This is the current position of the player (Point_2D) * @param current_gate The current gate that has been driven over (int) * @return Current gate number (int) */ int Get_Gate(const Square_2D gates[], int number_of_gates, Point_2D position, int current_gate); /** Checks the current position of the player to see if they are about to complete a lap * @param laps The current number of laps (int) * @param gates[] The array containing all the gates (Square_2D) * @param number_of_gates Number of gates in the array (int) * @param position This is the current position of the player (Point_2D) * @param current_gate The current gate that has been driven over (int) * @return The new current number of laps (int) */ int Get_Laps(int laps, const Square_2D gates[], int number_of_gates, Point_2D position, int current_gate); /** Converts between the number of elapsed frames to time in min,sec,mili * @param game_fps The fps of the game (int) * @param number_of_frames The number of frames elapsed so far during the current race (int) * @return The time in minutes, seconds, miliseconds format (Time) */ Time Convert_To_Time(int game_fps, int number_of_frames); /** Returns the current angle of rotation of the map using the previos rotation * @param angle The currrent angle of roatation of the map (int) * @param handling The maximum number of degrees of rotation for that given cars handling (int) * @param gyro_enabled Has gyroscope steering been enabled in settings (bool) * @param Gyro The gyroscope class object (object) * @param Device The gamepad class object (Device) * @return The new current angle of map rotation (int) */ int Get_Angle(int angle, int handling, bool gyro_enabled, FXOS8700CQ &Gyro, Gamepad &Device); /** Returns the current map translation usung the previos translation * @param in The currrent map translation(Point_2D) * @param angle The current angle of roataion of the map [Drection of travel] (float) * @param speed The current of the player (float) * @param *out_of_bounds_square The pointer for the array of square out of bounds areas(Square_2D) * @param *out_of_bounds_triangle The pointer for the array of triange out of bounds areas(Triangle_2D) * @param map_info The number of elements in each array above (Map_Data) * @param Device The gamepad class object (Device) * @return The new current translation (Point_2D) */ Point_2D Get_Translation( Point_2D in, float angle, float speed, const Square_2D *out_of_bounds_square, const Triangle_2D *out_of_bounds_triangle, const Map_Data map_info, Gamepad &Device ); /** Returns the current speed using the previos speed * @param speed The currrent speed(float) * @param max_speed The maximum speed of the chosen car (float) * @param acceleration The acceleration of the chosen car (float) * @param deceleration The deceleration of the chosen car (float) * @param off_track_speed The maximum speed when off track of the chosen car (float) * @param position The current position of the car (Point_2D) * @param *offtrack_square The pointer for the array of square of off track areas(Square_2D) * @param *offtrack_triangle The pointer for the array of triange of off track areas(Triangle_2D) * @param *out_of_bounds_square The pointer for the array of square out of bounds areas(Square_2D) * @param *out_of_bounds_triangle The pointer for the array of triange out of bounds areas(Triangle_2D) * @param *plates The pointer for the boost plates array (Triangle_2D) * @param map_info The number of elements in each array above (Map_Data) * @param Device The gamepad class object (Device) * @return The new current speed (float) */ float Get_Speed( float speed, float max_speed, float acceleration, float deceleration, float off_track_speed, Point_2D position, const Square_2D *offtrack_square, const Triangle_2D *offtrack_triangle, const Square_2D *out_of_bounds_square, const Triangle_2D *out_of_bounds_triangle, const Triangle_2D *plates, const Map_Data map_info, Gamepad &Device ); /** Returns the max speed for the chosen vehicle * @param car_model The chosen car model (int) * @return The maximum speed (float) */ float Get_Max_Speed(int car_model); /** Returns the acceleration for the chosen vehicle * @param car_model The chosen car model (int) * @return The acceleration (float) */ float Get_Acceleration(int car_model); /** Returns the decleration for the chosen vehicle * @param car_model The chosen car model (int) * @return The deceleration (float) */ float Get_Deceleration(int car_model); /** Returns the max speed when off road for the chosen vehicle * @param car_model The chosen car model (int) * @return The maximum speed when off road (float) */ float Get_Off_Road_Speed(int car_model); /** Returns the handling of the chosen vehicle * @param car_model The chosen car model (int) * @return The handling (float) */ int Get_Handling(int car_model); private: //SPEED bool Is_Offtrack(Point_2D position, const Square_2D offtrack_square[], const Triangle_2D offtrack_triangle[], const Map_Data map_info); bool Is_Out_Of_Bounds(Point_2D position, const Square_2D offtrack_square[], const Triangle_2D offtrack_triangle[], const Map_Data map_info); bool Is_Offtrack_Square(const Square_2D offtrack[], int size, Point_2D position); bool Is_Offtrack_Triangle(const Triangle_2D offtrack[], int size, Point_2D position); bool Is_Out_Of_Bounds_Square(const Square_2D out_of_bounds[], int size, Point_2D position); bool Is_Out_Of_Bounds_Triangle(const Triangle_2D out_of_bounds[], int size, Point_2D position); float Get_Boost_Speed(const Triangle_2D plates[], int number_of_plates, Point_2D position, float speed); }; #endif