Game

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers Ghost.h Source File

Ghost.h

00001 //#define DEBUG_GHOST_READ
00002 //#define DEBUG_GHOST_WRITE
00003 
00004 #ifndef GHOST_H
00005 #define GHOST_H
00006 
00007 #include "mbed.h"
00008 #include "Gamepad.h"
00009 #include "N5110.h"
00010 #include "FXOS8700CQ.h"
00011 #include "SDFileSystem.h"
00012 #include "Graphics.h"
00013 #include "Mechanics.h"
00014 #include "Menu.h"
00015 #include "LEDs.h"
00016 #include "Ghost.h"
00017 #include <string>
00018 
00019 #ifndef STRUCTS
00020 #define STRUCTS
00021 
00022 //STRUCTS
00023 struct Point_2D {
00024     float x;
00025     float y;
00026 };
00027 struct Line_2D {
00028     Point_2D from;
00029     Point_2D to;
00030 };
00031 
00032 struct Square_2D {
00033     Point_2D TL;
00034     Point_2D BR;
00035 };
00036 struct Triangle_2D {
00037     Point_2D TL;
00038     Point_2D BR;
00039     int Type;
00040 };
00041 
00042 struct Sprite_2D {
00043     float x;
00044     float y;
00045     int type;
00046 };
00047 
00048 struct Map_Data {
00049     int number_of_track_lines;
00050     int number_of_dotted_lines;
00051     int number_of_sprites;
00052     int number_of_walls;
00053     int number_of_off_track_squares;
00054     int number_of_off_track_triangles;
00055     int number_of_out_of_bounds_squares;
00056     int number_of_out_of_bounds_triangles;
00057     int number_of_gates;
00058     int number_of_boost_plates;
00059 };
00060 
00061 struct Time {
00062     int mins;
00063     int secs;
00064     int milis;
00065 };
00066 
00067 struct Gyro_Data {
00068     float ax;
00069     float ay;
00070     float az;
00071     float mx;
00072     float my;
00073     float mz;
00074 };
00075 
00076 #endif
00077 
00078 static Point_2D Ghost_Data[6000];
00079 static int Ghost_Held_Data_Time = 0;
00080 static Point_2D Ghost_Held_Data[6000];
00081 
00082 #ifndef ENUMS
00083 #define ENUMS
00084 enum track {Small, Medium, Large}; //Track Names
00085 enum cars {Basic, Offroad, Drifter, Sportscar, Racecar, Stupid}; //Car Names (Stupid is now the alien space ship)
00086 enum sprites {Flag, Helicopter, People_Standing_1, People_Standing_2, People_Cheering};
00087 #endif
00088 
00089 /** Ghost Class
00090 * @brief Records the current position of the player so that it can be played back later during ghost mode.
00091 * @brief The best race (so far) is copied to the SD card when the race is over.
00092 * @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.
00093 * @author Henry W Triff
00094 * @date Mar, 2020
00095 */
00096 
00097 class Ghost
00098 {
00099 public:
00100 
00101     /** Constructor */
00102     Ghost();
00103     
00104     /** Destructor */
00105     ~Ghost();
00106     
00107     /** Formats the SD card with the correct text files and fills them with temporary data.
00108     * @param SD The object for the SDFileSystem class (object).
00109     */
00110     void SD_init(SDFileSystem &SD, N5110 &LCD);
00111     
00112     /** Copies the ghost data int the txt file associated with the track-car combination to RAM
00113     * @param track The user selected track (int)
00114     * @param car The user selected car (int)
00115     * @param SD The object for the SDFileSystem class (object)
00116     */
00117     void SD_Read(int track, int car, SDFileSystem &SD);
00118     
00119     /** Adds the current position of the car to a Ghost_Data array
00120     * @param position The current coordinate position of the players car (Point_2D)
00121     * @param race_time The current number of frames elapsed during race
00122     */
00123     void Record(Point_2D position, int race_time);
00124     
00125     /** 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
00126     * @param race_time The number of frames elapsed during race
00127     * @param track The user selected track (int)
00128     * @param car The user selected car (int)
00129     * @param SD The object for the SDFileSystem class (object)
00130     */
00131     void Copy(int race_time, int track, int car, SDFileSystem &SD);
00132     
00133     /** Returns the position of the ghost for a given race_time
00134     * @param ghost_available Is the game in ghost mode (bool)
00135     * @param race_time The current number of frames elapsed during race (int)
00136     * @return Current position of the ghost
00137     */
00138     Point_2D Play(bool ghost_available, int race_time);
00139 
00140 private:
00141     
00142     void SD_Write(int track, int car, int race_time, SDFileSystem &SD);
00143     void SD_Write_Data(string name, int race_time, SDFileSystem &SD);
00144     void SD_Write_Time(int track, int car, int race_time, SDFileSystem &SD);
00145     void SD_Read_Data(string name, int race_time, SDFileSystem &SD);
00146     void SD_Read_Time(int track, int car, SDFileSystem &SD);
00147     int SD_Get_Time(int track, int car, SDFileSystem &SD);
00148 
00149 };
00150 
00151 #endif