Dependencies:   mbed

Revision:
6:5f76dd718dc3
Parent:
5:2d9f3c36bcb9
Child:
7:2ce6e90f6d47
--- a/main.cpp	Tue Feb 11 17:28:56 2020 +0000
+++ b/main.cpp	Wed Feb 19 21:40:21 2020 +0000
@@ -14,15 +14,25 @@
 #include "mbed.h"
 #include "Gamepad.h"
 #include "N5110.h"
+#include "FXOS8700CQ.h"
 #include "Graphics.h"
 #include "Controls.h"
+#include "Mechanics.h"
+#include "Menu.h"
+#include "LEDs.h"
+#include "Ghost.h"
+#include <string>
 
 //OBJECTS
 Gamepad Device;
 N5110 LCD;
+FXOS8700CQ Gyro(I2C_SDA,I2C_SCL);
 Graphics Graphics;
 Controls Controls;
 Mechanics Mechanics;
+Menu Menu;
+LEDs LEDs;
+Ghost Ghost;
 
 #ifndef STRUCTS
 #define STRUCTS
@@ -57,12 +67,28 @@
     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
 
 //MAP - 1
-Map_Data Map_1 = {36,1,2,16,14,19,8,5,12};
+Map_Data Map_1 = {36,1,2,20,14,19,9,5,12,0};
 
 //Lines
 const Line_2D Map_1_Track_Lines[36] = {
@@ -117,7 +143,7 @@
 };
 
 //Walls
-Line_2D Map_1_Walls[16] = {
+Line_2D Map_1_Walls[20] = {
     //Inside
     {{-40,80},{-40,0}},
     {{-40,0},{-100,-60}},
@@ -135,7 +161,11 @@
     {{40,160},{40,-220}},
     {{40,-220},{-420,-220}},
     {{-420,-220},{-420,160}},
-    {{-420,160},{40,160}},
+    {{-420,160},{-200,160}},
+    {{-200,160},{-200,60}},
+    {{-200,60},{-160,60}},
+    {{-160,60},{-160,160}},
+    {{-160,160},{40,160}},
 };
 
 //Off track? objects
@@ -181,7 +211,7 @@
     {{-400,-120},{-320,-200},1}
 };
 
-Square_2D Map_1_Out_Of_Bounds_Square[8] = {
+Square_2D Map_1_Out_Of_Bounds_Square[9] = {
     //Inside
     {{-80,80},{-40,0}},
     {{-340,60},{-280,-60}},
@@ -191,7 +221,8 @@
     {{40,160},{60,-220}},
     {{-420,-220},{40,-240}},
     {{-440,160},{-420,-220}},
-    {{-420,180},{40,160}}
+    {{-420,180},{40,160}},
+    {{-200,160},{-160,60}}
 };
 
 Triangle_2D Map_1_Out_Of_Bounds_Triangle[5] = {
@@ -218,6 +249,9 @@
     {{-100,-40},{40,-60}}
 };
 
+Triangle_2D Map_1_Boost_Plates[0] = {
+};
+
 //GLOBAL VARIABLES
 
 //Transform
@@ -235,31 +269,96 @@
 bool out_of_bounds = false;
 int lap_gate = 0;
 int laps = 1;
+int number_of_laps = 3;
 bool direction = true;
+int race_time = 0;
+bool ghost_available = false;
 
 //Game parameters
 int game_fps = 50;
+bool back_light = true;
+bool leds = true;
+bool rumble = true;
+bool gyro_enabled = false;
 
 int main()
 {
     LCD.init();
     Device.init();
+    Gyro.init();
+    Graphics.Change_Contrast(LCD,Device);
+
+    //MENU
+
+    /*int main_option_selected;
+    int settings_option_selected;
+
+    while(main_option_selected != 1) {
+        main_option_selected = Menu.Main_Menu(LCD, Device);
+
+        if(main_option_selected == 2) {
+            while(settings_option_selected != 0) {
+                //settings_option_selected = Menu.Settings_Menu(LCD, Device);
+                if(settings_option_selected == 1) {
+
+                }
+                if(settings_option_selected == 2) {
+
+                }
+                if(settings_option_selected == 3) {
+
+                }
+
+            }
+        }
+        if(main_option_selected == 3) {
+            Menu.Credits_Menu(LCD, Device);
+        }
+
+    }*/
+
     while(1) {
 
-        //MECHANICS
-        off_track = Mechanics.Is_Offtrack(translation, Map_1_Off_Track_Square, Map_1_Off_Track_Triangle, Map_1);
-        out_of_bounds = Mechanics.Is_Out_Of_Bounds(translation, Map_1_Out_Of_Bounds_Square, Map_1_Out_Of_Bounds_Triangle, Map_1);
-        laps = Mechanics.Get_Laps(laps, Map_1_Gates, Map_1.number_of_gates, translation, lap_gate);
-        lap_gate = Mechanics.Get_Gate(Map_1_Gates, Map_1.number_of_gates, translation, lap_gate);
+        //COUNTDOWN
+
+        LCD.clear();
+        Graphics.Draw_Map(
+            translation,
+            angle,
+            squish,
+            (Line_2D *) Map_1_Track_Lines,
+            (Line_2D *)Map_1_Track_Dotted_Lines,
+            (Line_2D *)Map_1_Walls,
+            (Point_2D *)Map_1_Flags,
+            (Triangle_2D *)Map_1_Boost_Plates,
+            Map_1,
+            Ghost.Play(ghost_available, race_time),
+            LCD
+        );
+        Graphics.Start_Sequence(3, LCD);
+        LCD.refresh();
+        wait(1);
 
-        //CONTROLS
-        angle = Controls.Get_Angle(angle, handling, Device);
-        translation = Controls.Get_Translation(translation, angle, speed, out_of_bounds, Device);
-        speed = Controls.Get_Speed(speed, max_speed, off_track, out_of_bounds, Device);
+        LCD.clear();
+        Graphics.Draw_Map(
+            translation,
+            angle,
+            squish,
+            (Line_2D *) Map_1_Track_Lines,
+            (Line_2D *)Map_1_Track_Dotted_Lines,
+            (Line_2D *)Map_1_Walls,
+            (Point_2D *)Map_1_Flags,
+            (Triangle_2D *)Map_1_Boost_Plates,
+            Map_1,
+            Ghost.Play(ghost_available, race_time),
+            LCD
+        );
+        Graphics.Start_Sequence(2, LCD);
+        LEDs.Start_Sequence(back_light, 2, Device);
+        LCD.refresh();
+        wait(1);
 
-        //GRAPHICS
         LCD.clear();
-        Graphics.Change_Contrast(LCD,Device);
         Graphics.Draw_Map(
             translation,
             angle,
@@ -268,14 +367,114 @@
             (Line_2D *)Map_1_Track_Dotted_Lines,
             (Line_2D *)Map_1_Walls,
             (Point_2D *)Map_1_Flags,
+            (Triangle_2D *)Map_1_Boost_Plates,
             Map_1,
+            Ghost.Play(ghost_available, race_time),
+            LCD
+        );
+        Graphics.Start_Sequence(1, LCD);
+        LEDs.Start_Sequence(back_light, 1, Device);
+        LCD.refresh();
+        wait(1);
+        LCD.clear();
+        Graphics.Draw_Map(
+            translation,
+            angle,
+            squish,
+            (Line_2D *) Map_1_Track_Lines,
+            (Line_2D *)Map_1_Track_Dotted_Lines,
+            (Line_2D *)Map_1_Walls,
+            (Point_2D *)Map_1_Flags,
+            (Triangle_2D *)Map_1_Boost_Plates,
+            Map_1,
+            Ghost.Play(ghost_available, race_time),
             LCD
         );
-        Graphics.Draw_Laps(laps, LCD);
+        Graphics.Start_Sequence(0, LCD);
+        LEDs.Start_Sequence(back_light, 0, Device);
         LCD.refresh();
-        wait((1 / float(game_fps)));
+        wait(1);
+        LEDs.Clear(Device);
+
+        while(laps <= number_of_laps) {
+            //MECHANICS
+            off_track = Mechanics.Is_Offtrack(translation, Map_1_Off_Track_Square, Map_1_Off_Track_Triangle, Map_1);
+            out_of_bounds = Mechanics.Is_Out_Of_Bounds(translation, Map_1_Out_Of_Bounds_Square, Map_1_Out_Of_Bounds_Triangle, Map_1);
+            laps = Mechanics.Get_Laps(laps, Map_1_Gates, Map_1.number_of_gates, translation, lap_gate);
+            lap_gate = Mechanics.Get_Gate(Map_1_Gates, Map_1.number_of_gates, translation, lap_gate);
+
+            //CONTROLS
+            angle = Controls.Get_Angle(angle, handling, gyro_enabled, Gyro, Device);
+            translation = Controls.Get_Translation(translation, angle, speed, out_of_bounds, Device);
+            speed = Controls.Get_Speed(speed, max_speed, off_track, out_of_bounds, Device);
+            speed = Mechanics.Get_Boost_Speed(Map_1_Boost_Plates, Map_1.number_of_boost_plates, translation, speed);
+
+            //LEDS
+            LEDs.Speed(leds, speed, max_speed, Device);
+
+            //GHOST
+            Ghost.Record(translation, race_time);
+
+            //GRAPHICS
+            LCD.clear();
+            Graphics.Change_Contrast(LCD,Device);
+            Graphics.Draw_Map(
+                translation,
+                angle,
+                squish,
+                (Line_2D *) Map_1_Track_Lines,
+                (Line_2D *)Map_1_Track_Dotted_Lines,
+                (Line_2D *)Map_1_Walls,
+                (Point_2D *)Map_1_Flags,
+                (Triangle_2D *)Map_1_Boost_Plates,
+                Map_1,
+                Ghost.Play(ghost_available, race_time),
+                LCD
+            );
+            Graphics.Draw_Laps(laps, LCD);
+            Graphics.Draw_Time(false, Mechanics.Convert_To_Time(game_fps, race_time), LCD);
+            LCD.refresh();
+            wait((1 / float(game_fps)));
+            race_time++;
+
+        }
+        LEDs.Clear(Device);
+        LCD.clear();
+        Graphics.Draw_Map(
+            translation,
+            angle,
+            squish,
+            (Line_2D *) Map_1_Track_Lines,
+            (Line_2D *)Map_1_Track_Dotted_Lines,
+            (Line_2D *)Map_1_Walls,
+            (Point_2D *)Map_1_Flags,
+            (Triangle_2D *)Map_1_Boost_Plates,
+            Map_1,
+            Ghost.Play(ghost_available, race_time),
+            LCD
+        );
+        Graphics.Finish(LCD);
+        Graphics.Draw_Time(true, Mechanics.Convert_To_Time(game_fps, race_time), LCD);
+        LCD.refresh();
+        ghost_available = true;
+        Ghost.Copy(race_time);
+
+        //RESET
+        angle = 0;
+        Point_2D test = {0,0};
+        translation = test;
+        squish = 0.15;
+        speed = 0;
+        max_speed = 4;
+        handling = 2;
+        off_track = false;
+        out_of_bounds = false;
+        lap_gate = 0;
+        laps = 1;
+        direction = true;
+        race_time = 0;
+
+        wait(3);
     }
-
-
 }