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.
Graphics/Graphics.h
- Committer:
- HenryWTriff
- Date:
- 2020-03-28
- Revision:
- 18:5fcb0514fb70
- Parent:
- 17:4c5f25d5c4d5
- Child:
- 22:9065c457a45d
File content as of revision 18:5fcb0514fb70:
#ifndef GRAPHICS_H
#define GRAPHICS_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>
/** Graphics Class
* @brief Creates all game graphics.
* @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
class Graphics
{
public:
/** Constructor */
Graphics();
/** Destructor */
~Graphics();
/** Changes the contrast of the LCD using the left potentiometer
* @param LCD The object for the N5110 class (object)
* @param Device The object for the gamepad class (object)
*/
void Change_Contrast(N5110 &LCD, Gamepad &Device);
/** Draws all graphics required for the game (excluding lap counter, time, start count down and finishing trophy)
* @param translation The translation of the map. See Mechanics class. (Point_2D)
* @param angle The rotation of the map. See Mechanics class. (int)
* @param squish The y-axis squish of the map to get the 3D effect. (float)
* @param *Track_Lines Pointer for the array for track lines. (Line_2D)
* @param *Track_Dotted_Lines Pointer for the array for dotted lines. (Line_2D)
* @param *Track_Walls Pointer for the array for walls. (Line_2D)
* @param *Track_Flags Pointer for the array for flag positions. (Point_2D)
* @param *Track_Boost_Plates Pointer for the array for boost plate positions. (Triangle_2D)
* @param map_info Struct containing the number of elements in each array above (Map_Data)
* @param car_type The car selected. (int)
* @param ghost_position The current position of the ghost. (Point_2D)
* @param LCD The object for the N5110 class (object)
*/
void Draw_Map(
Point_2D translation,
int angle,
float squish,
Line_2D *Track_Lines,
Line_2D *Track_Dotted_Lines,
Line_2D *Track_Walls,
Point_2D *Track_Flags,
Triangle_2D *Track_Boost_Plates,
Map_Data map_info,
int car_type,
Point_2D ghost_position,
N5110 &LCD
);
/** Draws the current lap count
* @param laps The current lap count (int)
* @param LCD The object for the N5110 class (object)
*/
void Draw_Laps(int laps, N5110 &LCD);
/** Draws the race time
* @param finised The current lap count (bool)
* @param time The time elapsed from the race so far (Time)
* @param LCD The object for the N5110 class (object)
*/
void Draw_Time(bool finished, Time time, N5110 &LCD);
/** Draws the count down numbers before the race
* @param state The current count down number (int)
* @param LCD The object for the N5110 class (object)
*/
void Start_Sequence(int state, N5110 &LCD);
/** Draws the finishing trophy
* @param LCD The object for the N5110 class (object)
*/
void Finish(N5110 &LCD);
/** Draws the game logo on startup
* @param LCD The object for the N5110 class (object)
*/
void Draw_Logo(N5110 &LCD);
private:
//TRANSFORM
Point_2D Rotate_Point(Point_2D point, float angle);
Point_2D Translate_Point(Point_2D point, int translate_x, int translate_y);
Point_2D Squish_Point(Point_2D point, float squish);
//MATH
int Round(float number);
float Gradient(Point_2D from, Point_2D to);
bool Gradient_Check_Infinate(Point_2D from, Point_2D to);
//DRAW
void Graphics_Draw_Line(Point_2D from, Point_2D to, bool solid, N5110 &LCD);
void Graphics_Draw_Wall(Point_2D from, Point_2D to, int height, N5110 &LCD);
void Graphics_Draw_Boost_Plate(Triangle_2D boost_plate, Point_2D translation, int angle, float squish, N5110 &LCD);
void Graphics_Draw_Sprite(Point_2D point, int x_size, int y_size, int *sprite, N5110 &LCD);
};
#endif