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.
Ghost/Ghost.h
- Committer:
- HenryWTriff
- Date:
- 2020-05-22
- Revision:
- 26:f1d3b7e31091
- Parent:
- 25:31761087a83f
File content as of revision 26:f1d3b7e31091:
//#define DEBUG_GHOST_READ //#define DEBUG_GHOST_WRITE #ifndef GHOST_H #define GHOST_H #include "mbed.h" #include "Gamepad.h" #include "N5110.h" #include "FXOS8700CQ.h" #include "SDFileSystem.h" #include "Graphics.h" #include "Mechanics.h" #include "Menu.h" #include "LEDs.h" #include "Ghost.h" #include <string> #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 Sprite_2D { float x; float y; int type; }; struct Map_Data { int number_of_track_lines; int number_of_dotted_lines; int number_of_sprites; 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 static Point_2D Ghost_Data[6000]; static int Ghost_Held_Data_Time = 0; static Point_2D Ghost_Held_Data[6000]; #ifndef ENUMS #define ENUMS enum track {Small, Medium, Large}; //Track Names enum cars {Basic, Offroad, Drifter, Sportscar, Racecar, Stupid}; //Car Names (Stupid is now the alien space ship) enum sprites {Flag, Helicopter, People_Standing_1, People_Standing_2, People_Cheering}; #endif /** Ghost Class * @brief Records the current position of the player so that it can be played back later during ghost mode. * @brief The best race (so far) is copied to the SD card when the race is over. * @brief Before each race, the previos best ghost data is read from the SD card to internal memory to allow the game to run faster. * @author Henry W Triff * @date Mar, 2020 */ class Ghost { public: /** Constructor */ Ghost(); /** Destructor */ ~Ghost(); /** Formats the SD card with the correct text files and fills them with temporary data. * @param SD The object for the SDFileSystem class (object). */ void SD_init(SDFileSystem &SD, N5110 &LCD); /** Copies the ghost data int the txt file associated with the track-car combination to RAM * @param track The user selected track (int) * @param car The user selected car (int) * @param SD The object for the SDFileSystem class (object) */ void SD_Read(int track, int car, SDFileSystem &SD); /** Adds the current position of the car to a Ghost_Data array * @param position The current coordinate position of the players car (Point_2D) * @param race_time The current number of frames elapsed during race */ void Record(Point_2D position, int race_time); /** If the race that was just run was faster than previos races, this copies the data in the Ghost_Data array to the SD card * @param race_time The number of frames elapsed during race * @param track The user selected track (int) * @param car The user selected car (int) * @param SD The object for the SDFileSystem class (object) */ void Copy(int race_time, int track, int car, SDFileSystem &SD); /** Returns the position of the ghost for a given race_time * @param ghost_available Is the game in ghost mode (bool) * @param race_time The current number of frames elapsed during race (int) * @return Current position of the ghost */ Point_2D Play(bool ghost_available, int race_time); private: void SD_Write(int track, int car, int race_time, SDFileSystem &SD); void SD_Write_Data(string name, int race_time, SDFileSystem &SD); void SD_Write_Time(int track, int car, int race_time, SDFileSystem &SD); void SD_Read_Data(string name, int race_time, SDFileSystem &SD); void SD_Read_Time(int track, int car, SDFileSystem &SD); int SD_Get_Time(int track, int car, SDFileSystem &SD); }; #endif