Henry Triff / Mbed 2 deprecated ELEC2645_Project_el18ht

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers Graphics.h Source File

Graphics.h

00001 #ifndef GRAPHICS_H
00002 #define GRAPHICS_H
00003 
00004 #include "mbed.h"
00005 #include "Gamepad.h"
00006 #include "N5110.h"
00007 #include "FXOS8700CQ.h"
00008 #include "Graphics.h"
00009 #include "Mechanics.h"
00010 #include "Menu.h"
00011 #include "LEDs.h"
00012 #include "Ghost.h"
00013 #include <string>
00014 
00015 #ifndef STRUCTS
00016 #define STRUCTS
00017 
00018 //STRUCTS
00019 
00020 /** 2D point Struct */
00021 struct Point_2D {
00022     float x; /**< X Coordinate */
00023     float y; /**< Y Coordinate */
00024 };
00025 /** 2D line Struct */
00026 struct Line_2D {
00027     Point_2D from; /**< Coordinates of 'from' point */
00028     Point_2D to; /**< Coordinates of 'to' point */
00029 };
00030 
00031 /** 2D square Struct */
00032 struct Square_2D {
00033     Point_2D TL; /**< Coordinates of Top Left point */
00034     Point_2D BR; /**< Coordinates of Bottom Right point */
00035 };
00036 
00037 /** 2D triangle Struct */
00038 struct Triangle_2D {
00039     Point_2D TL; /**< Coordinates of Top Left point */
00040     Point_2D BR; /**< Coordinates of Bottom Right point */
00041     int Type; /**< The type of triangle (Direction of the hypotenuse */
00042 };
00043 
00044 struct Sprite_2D {
00045     float x; 
00046     float y;
00047     int type;
00048 };
00049 
00050 /** 2D Map data Struct */
00051 struct Map_Data {
00052     int number_of_track_lines; /**< Number of elements in the track lines array */
00053     int number_of_dotted_lines; /**< Number of elements in the dotted lines array */
00054     int number_of_sprites; /**< Number of elements in the sprites array */
00055     int number_of_walls; /**< Number of elements in the walls array */
00056     int number_of_off_track_squares; /**< Number of elements in the off track squares array */
00057     int number_of_off_track_triangles; /**< Number of elements in the off track triangles array */
00058     int number_of_out_of_bounds_squares; /**< Number of elements in the out of bounds squares array */
00059     int number_of_out_of_bounds_triangles; /**< Number of elements in the out of bounds triangles array */
00060     int number_of_gates; /**< Number of elements in the gates array */
00061     int number_of_boost_plates; /**< Number of elements in the boost plates array */
00062 };
00063 
00064 /** Time Struct */
00065 struct Time {
00066     int mins; /**< Number of minutes */
00067     int secs; /**< Number of seconds */
00068     int milis; /**< Number of miliseconds */
00069 };
00070 
00071 /** Gyro Data Struct */
00072 struct Gyro_Data {
00073     float ax; /**< Accelerometer X */
00074     float ay; /**< Accelerometer Y */
00075     float az; /**< Accelerometer Z */
00076     float mx; /**< Magnetometer X */
00077     float my; /**< Magnetometer Y */
00078     float mz; /**< Magnetometer Z */
00079 };
00080 
00081 #endif
00082 
00083 #ifndef ENUMS
00084 #define ENUMS
00085 enum track {Small, Medium, Large}; //Track Names
00086 enum cars {Basic, Offroad, Drifter, Sportscar, Racecar, Stupid}; //Car Names (Stupid is now the alien space ship)
00087 enum sprites {Flag, Helicopter, People_Standing_1, People_Standing_2, People_Cheering};
00088 #endif
00089 
00090 /** Graphics Class
00091 * @brief Creates all game graphics.
00092 * @author Henry W Triff
00093 * @date Mar, 2020
00094 */
00095 
00096 class Graphics
00097 {
00098 public:
00099     
00100     /** Constructor */
00101     Graphics();
00102     
00103     /** Destructor */
00104     ~Graphics();
00105     
00106     /** Changes the contrast of the LCD using the left potentiometer
00107     * @param LCD The object for the N5110 class (object)
00108     * @param Device The object for the gamepad class (object)
00109     */
00110     void Change_Contrast(N5110 &LCD, Gamepad &Device);
00111     
00112     
00113     /** Draws all graphics required for the game (excluding lap counter, time, start count down and finishing trophy)
00114     * @param translation The translation of the map. See Mechanics class. (Point_2D)
00115     * @param angle The rotation of the map. See Mechanics class. (int)
00116     * @param squish The y-axis squish of the map to get the 3D effect. (float)
00117     * @param horizon_factor This is the squishing on x-axis points depending on their y-position to make it look more 3D
00118     * @param *Track_Lines Pointer for the array for track lines. (Line_2D)
00119     * @param *Track_Dotted_Lines Pointer for the array for dotted lines. (Line_2D)
00120     * @param *Track_Walls Pointer for the array for walls. (Line_2D)
00121     * @param *Track_Sprites Pointer for the array for sprite positions. (Sprite_2D)
00122     * @param *Track_Boost_Plates Pointer for the array for boost plate positions. (Triangle_2D)
00123     * @param map_info Struct containing the number of elements in each array above (Map_Data)
00124     * @param car_type The car selected. (int)
00125     * @param ghost_position The current position of the ghost. (Point_2D)
00126     * @param LCD The object for the N5110 class (object)
00127     */
00128     void Draw_Map(
00129         Point_2D translation,
00130         int angle, 
00131         float squish,
00132         float horizon_factor,
00133         Line_2D *Track_Lines,
00134         Line_2D *Track_Dotted_Lines,
00135         Line_2D *Track_Walls,
00136         Sprite_2D *Track_Sprites,
00137         Triangle_2D *Track_Boost_Plates,
00138         Map_Data map_info,
00139         int car_type,
00140         Point_2D ghost_position,
00141         N5110 &LCD
00142     );
00143     
00144     /** Draws the current lap count
00145     * @param laps The current lap count (int)
00146     * @param LCD The object for the N5110 class (object)
00147     */
00148     void Draw_Laps(int laps, N5110 &LCD);
00149     
00150     /** Draws the race time
00151     * @param finised The current lap count (bool)
00152     * @param time The time elapsed from the race so far (Time)
00153     * @param LCD The object for the N5110 class (object)
00154     */
00155     void Draw_Time(bool finished, Time time, N5110 &LCD);
00156     
00157     /** Draws the count down numbers before the race
00158     * @param state The current count down number (int)
00159     * @param LCD The object for the N5110 class (object)
00160     */
00161     void Start_Sequence(int state, N5110 &LCD);
00162     
00163     /** Draws the finishing trophy
00164     * @param LCD The object for the N5110 class (object)
00165     */
00166     void Finish(N5110 &LCD);
00167     
00168     /** Draws the game logo on startup
00169     * @param LCD The object for the N5110 class (object)
00170     */
00171     void Draw_Logo(N5110 &LCD);
00172     
00173 
00174 private:
00175     //TRANSFORM
00176     Point_2D Rotate_Point(Point_2D point, float angle);
00177     Point_2D Translate_Point(Point_2D point, int translate_x, int translate_y);
00178     Point_2D Squish_Point(Point_2D point, float squish);
00179     Point_2D Graphics::Horizon_Point(Point_2D point, float horizon_factor);
00180     //MATH
00181     int Round(float number);
00182     float Gradient(Point_2D from, Point_2D to);
00183     bool Gradient_Check_Infinate(Point_2D from, Point_2D to);
00184     //DRAW
00185     void Graphics_Draw_Line(Point_2D from, Point_2D to, bool solid, N5110 &LCD);
00186     void Graphics_Draw_Wall(Point_2D from, Point_2D to, int height, N5110 &LCD);
00187     void Graphics_Draw_Boost_Plate(Triangle_2D boost_plate, Point_2D translation, int angle, float squish, N5110 &LCD);
00188     void Graphics_Draw_Sprite(Point_2D point, int x_size, int y_size, int *sprite, N5110 &LCD);
00189 };
00190 
00191 #endif