Henry Triff / Mbed 2 deprecated ELEC2645_Project_el18ht

Dependencies:   mbed

Revision:
9:7b1093d3f03a
Parent:
8:4503c92acaf6
Child:
10:29126a41b1da
--- a/Mechanics/Mechanics.cpp	Mon Mar 02 18:11:04 2020 +0000
+++ b/Mechanics/Mechanics.cpp	Thu Mar 05 15:40:21 2020 +0000
@@ -4,7 +4,7 @@
 //  SPEED
 //*********
 
-float Mechanics::Get_Speed(float speed, float max_speed, float acceleration, float deceleration,  float off_track_speed, Point_2D position, Square_2D *offtrack_square, Triangle_2D *offtrack_triangle, Square_2D *out_of_bounds_square, Triangle_2D *out_of_bounds_triangle, Triangle_2D *plates, Map_Data map_info, Gamepad &Device)
+float Mechanics::Get_Speed(float speed, float max_speed, float acceleration, float deceleration,  float off_track_speed, Point_2D position, const Square_2D *offtrack_square, const Triangle_2D *offtrack_triangle, const Square_2D *out_of_bounds_square, const Triangle_2D *out_of_bounds_triangle, const Triangle_2D *plates, const Map_Data map_info, Gamepad &Device)
 {
     bool offtrack = Is_Offtrack(position, offtrack_square, offtrack_triangle, map_info);
     bool out_of_bounds = Is_Out_Of_Bounds(position, out_of_bounds_square, out_of_bounds_triangle,  map_info);
@@ -45,19 +45,19 @@
 
 //  COMBINING
 
-bool Mechanics::Is_Offtrack(Point_2D position, Square_2D offtrack_square[], Triangle_2D offtrack_triangle[], Map_Data map_info)
+bool Mechanics::Is_Offtrack(Point_2D position, const Square_2D offtrack_square[], const Triangle_2D offtrack_triangle[], const Map_Data map_info)
 {
     return (Is_Offtrack_Square(offtrack_square, map_info.number_of_off_track_squares, position) || Is_Offtrack_Triangle(offtrack_triangle, map_info.number_of_off_track_triangles, position));
 }
 
-bool Mechanics::Is_Out_Of_Bounds(Point_2D position, Square_2D out_of_bounds_square[], Triangle_2D out_of_bounds_triangle[], Map_Data map_info)
+bool Mechanics::Is_Out_Of_Bounds(Point_2D position, const Square_2D out_of_bounds_square[], const Triangle_2D out_of_bounds_triangle[], const Map_Data map_info)
 {
     return (Is_Out_Of_Bounds_Square(out_of_bounds_square, map_info.number_of_out_of_bounds_squares, position) || Is_Out_Of_Bounds_Triangle(out_of_bounds_triangle, map_info.number_of_out_of_bounds_triangles, position));
 }
 
 //  OFF TRACK
 
-bool Mechanics::Is_Offtrack_Square(Square_2D offtrack[], int size, Point_2D position)
+bool Mechanics::Is_Offtrack_Square(const Square_2D offtrack[], int size, Point_2D position)
 {
     for(int i = 0; i < size; i++) {
         if(position.x > offtrack[i].TL.x && position.x < offtrack[i].BR.x && position.y < offtrack[i].TL.y && position.y > offtrack[i].BR.y ) {
@@ -67,7 +67,7 @@
     return false;
 }
 
-bool Mechanics::Is_Offtrack_Triangle(Triangle_2D offtrack[], int size, Point_2D position)
+bool Mechanics::Is_Offtrack_Triangle(const Triangle_2D offtrack[], int size, Point_2D position)
 {
     for(int i = 0; i < size; i++) {
         if(position.x > offtrack[i].TL.x && position.x < offtrack[i].BR.x && position.y < offtrack[i].TL.y && position.y > offtrack[i].BR.y ) {
@@ -103,7 +103,7 @@
 
 //  OUT OF BOUNDS
 
-bool Mechanics::Is_Out_Of_Bounds_Square(Square_2D out_of_bounds[], int size, Point_2D position)
+bool Mechanics::Is_Out_Of_Bounds_Square(const Square_2D out_of_bounds[], int size, Point_2D position)
 {
     for(int i = 0; i < size; i++) {
         if(position.x > out_of_bounds[i].TL.x && position.x < out_of_bounds[i].BR.x && position.y < out_of_bounds[i].TL.y && position.y > out_of_bounds[i].BR.y ) {
@@ -113,7 +113,7 @@
     return false;
 }
 
-bool Mechanics::Is_Out_Of_Bounds_Triangle(Triangle_2D out_of_bounds[], int size, Point_2D position)
+bool Mechanics::Is_Out_Of_Bounds_Triangle(const Triangle_2D out_of_bounds[], int size, Point_2D position)
 {
     for(int i = 0; i < size; i++) {
         if(position.x > out_of_bounds[i].TL.x && position.x < out_of_bounds[i].BR.x && position.y < out_of_bounds[i].TL.y && position.y > out_of_bounds[i].BR.y ) {
@@ -149,7 +149,7 @@
 
 //  BOOST PLATE
 
-float Mechanics::Get_Boost_Speed(Triangle_2D plates[], int number_of_plates, Point_2D position, float speed)
+float Mechanics::Get_Boost_Speed(const Triangle_2D plates[], int number_of_plates, Point_2D position, float speed)
 {
     for(int i = 0; i < number_of_plates; i++) {
         if(position.x > plates[i].TL.x && position.x < plates[i].BR.x && position.y < plates[i].TL.y && position.y > plates[i].BR.y) {
@@ -163,7 +163,7 @@
 //  GATES AND LAPS
 //******************
 
-int Mechanics::Get_Gate(Square_2D gates[], int number_of_gates, Point_2D position, int current_gate)
+int Mechanics::Get_Gate(const Square_2D gates[], int number_of_gates, Point_2D position, int current_gate)
 {
     int next_gate;
 
@@ -180,7 +180,7 @@
     return current_gate;
 }
 
-int Mechanics::Get_Laps(int laps, Square_2D gates[], int number_of_gates, Point_2D position, int current_gate)
+int Mechanics::Get_Laps(int laps, const Square_2D gates[], int number_of_gates, Point_2D position, int current_gate)
 {
     int next_gate;
 
@@ -219,10 +219,15 @@
 {
     if(gyro_enabled == false) {
         int Stick_Position = Device.get_direction();
-        if(Stick_Position == 2 || Stick_Position == 3 || Stick_Position == 4) {
-            angle += handling;
-        } else if(Stick_Position == 6 || Stick_Position == 7 || Stick_Position == 8) {
-            angle -= handling;
+        float Stick_Magnitude = Device.get_mag();
+        printf("%f\n", Stick_Magnitude);
+        if(Stick_Magnitude > 0.95) {
+            Stick_Magnitude = 1;
+        }
+        if(Stick_Position == E || Stick_Position == NE || Stick_Position == SE) {
+            angle += handling * Stick_Magnitude;
+        } else if(Stick_Position == W || Stick_Position == NW || Stick_Position == SW) {
+            angle -= handling * Stick_Magnitude;
         }
         return angle;
     } else {
@@ -249,7 +254,7 @@
 //  GET TRANSLATION
 //*******************
 
-Point_2D Mechanics::Get_Translation(Point_2D in, float angle, float speed, Square_2D *out_of_bounds_square, Triangle_2D *out_of_bounds_triangle, Map_Data map_info, Gamepad &Device)
+Point_2D Mechanics::Get_Translation(Point_2D in, float angle, float speed, const Square_2D *out_of_bounds_square, const Triangle_2D *out_of_bounds_triangle, const Map_Data map_info, Gamepad &Device)
 {
     float x = in.x;
     float y = in.y;