Dependencies:   mbed

Revision:
7:2ce6e90f6d47
Parent:
6:5f76dd718dc3
Child:
8:4503c92acaf6
--- a/main.cpp	Wed Feb 19 21:40:21 2020 +0000
+++ b/main.cpp	Sat Feb 22 23:13:25 2020 +0000
@@ -16,7 +16,6 @@
 #include "N5110.h"
 #include "FXOS8700CQ.h"
 #include "Graphics.h"
-#include "Controls.h"
 #include "Mechanics.h"
 #include "Menu.h"
 #include "LEDs.h"
@@ -28,7 +27,6 @@
 N5110 LCD;
 FXOS8700CQ Gyro(I2C_SDA,I2C_SCL);
 Graphics Graphics;
-Controls Controls;
 Mechanics Mechanics;
 Menu Menu;
 LEDs LEDs;
@@ -85,6 +83,11 @@
     float mz;
 };
 
+struct Menu_Data {
+    int Menu_return;
+    bool Back;
+};
+
 #endif
 
 //MAP - 1
@@ -254,23 +257,27 @@
 
 //GLOBAL VARIABLES
 
+enum cars {Basic, Offroad, Drifter, Sportscar, Racecar, Stupid};
+
 //Transform
 int angle = 0;
 Point_2D translation = {0,0};
 float squish = 0.15;
 
 //Vehicle parameters
-float speed = 0;
-float max_speed = 4;
-int handling = 2;
+float speed;
+float max_speed;
+int handling;
+float off_track_speed;
+float acceleration;
+float deceleration;
+
+int car_model = Stupid;
 
 //Mechanics
-bool off_track = false;
-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;
 
@@ -290,7 +297,8 @@
 
     //MENU
 
-    /*int main_option_selected;
+    /*
+    int main_option_selected;
     int settings_option_selected;
 
     while(main_option_selected != 1) {
@@ -314,100 +322,107 @@
         if(main_option_selected == 3) {
             Menu.Credits_Menu(LCD, Device);
         }
+    }
+    */
+    Menu_Data select_main_menu = {0,true};
+    Menu_Data select_settings_menu = {0,false};
+    Menu_Data select_game_mode = {0,true};
+    Menu_Data select_map = {0,true};
+    Menu_Data select_laps = {0,true};
+    Menu_Data select_car = {0,true};
 
-    }*/
+    do {
+
+        select_main_menu = Menu.Main_Menu(LCD, Device);
+
+        if(select_main_menu.Back == false && select_main_menu.Menu_return == 2) {
+            Menu.Settings_Menu(LCD, Device);
+            select_main_menu.Back = true;
+        }
+        
+        if(select_main_menu.Back == false && select_main_menu.Menu_return == 3) {
+            Menu.Credits_Menu(LCD, Device);
+            select_main_menu.Back = true;
+        }
+
+        if(select_main_menu.Back == false && select_main_menu.Menu_return == 1) {
+            select_game_mode = Menu.Select_Game_Mode(LCD, Device);
+        }
+        if(select_main_menu.Back == false && select_main_menu.Menu_return == 1 && select_game_mode.Back == false) {
+            select_map = Menu.Select_Map(LCD, Device);
+        }
+        if(select_main_menu.Back == false && select_main_menu.Menu_return == 1 && select_game_mode.Back == false && select_map.Back == false) {
+            select_laps = Menu.Select_Laps(LCD, Device);
+        }
+        if(select_main_menu.Back == false && select_main_menu.Menu_return == 1 && select_game_mode.Back == false && select_map.Back == false && select_laps.Back == false) {
+            select_car = Menu.Select_Car(LCD, Device);
+        }
+    } while(select_car.Back == true);
+
+    car_model = select_car.Menu_return;
+    number_of_laps = select_laps.Menu_return;
+    
+    back_light = Menu.Get_Back_Light_Setting();
+    leds = Menu.Get_LED_Setting();
+    rumble = Menu.Get_Rrumble_Setting();
+    gyro_enabled = Menu.Get_Gyro_Setting();
+
+    //CAR PARAMETERS SETUP
+    max_speed = Mechanics.Get_Max_Speed(car_model);
+    acceleration = Mechanics.Get_Acceleration(car_model);
+    deceleration = Mechanics.Get_Deceleration(car_model);
+    off_track_speed = Mechanics.Get_Off_Road_Speed(car_model);
+    handling = Mechanics.Get_Handling(car_model);
+
+
 
     while(1) {
 
         //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);
-
-        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);
-
-        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(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.Start_Sequence(0, LCD);
-        LEDs.Start_Sequence(back_light, 0, Device);
-        LCD.refresh();
-        wait(1);
+        for(int count = 3; count >= 0; count--) {
+            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,
+                car_model,
+                Ghost.Play(ghost_available, race_time),
+                LCD
+            );
+            Graphics.Start_Sequence(count, LCD);
+            LEDs.Start_Sequence(leds, count, Device);
+            LCD.refresh();
+            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);
+            angle = Mechanics.Get_Angle(angle, handling, gyro_enabled, Gyro, Device);
+            speed = Mechanics.Get_Speed(
+                        speed,
+                        max_speed,
+                        acceleration,
+                        deceleration,
+                        off_track_speed,
+                        translation,
+                        Map_1_Off_Track_Square,
+                        Map_1_Off_Track_Triangle,
+                        Map_1_Out_Of_Bounds_Square,
+                        Map_1_Out_Of_Bounds_Triangle,
+                        Map_1_Boost_Plates,
+                        Map_1,
+                        Device
+                    );
+            translation = Mechanics.Get_Translation(translation, angle, speed, Map_1_Out_Of_Bounds_Square, Map_1_Out_Of_Bounds_Triangle, Map_1, Device);
 
             //LEDS
             LEDs.Speed(leds, speed, max_speed, Device);
@@ -428,6 +443,7 @@
                 (Point_2D *)Map_1_Flags,
                 (Triangle_2D *)Map_1_Boost_Plates,
                 Map_1,
+                car_model,
                 Ghost.Play(ghost_available, race_time),
                 LCD
             );
@@ -438,6 +454,8 @@
             race_time++;
 
         }
+
+
         LEDs.Clear(Device);
         LCD.clear();
         Graphics.Draw_Map(
@@ -450,6 +468,7 @@
             (Point_2D *)Map_1_Flags,
             (Triangle_2D *)Map_1_Boost_Plates,
             Map_1,
+            car_model,
             Ghost.Play(ghost_available, race_time),
             LCD
         );
@@ -467,11 +486,8 @@
         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);