“Race Collision” is a one player game in which a truck has to avoid “particles” that appear on the road. By the use of the joystick, the player can guide themselves through the menu system to start the game. The truck is the main element of the game and it can be moved from side to side with the joystick. The road curves randomly from time to time and the player has to be careful to keep the truck within the road boundaries. Particles appear on the screen at random positions and 4 collisions lead to the end of the game.

Dependencies:   ELEC2645_JoystickLCD_LPC1768_2021

Revision:
3:cbe2dcca5058
Parent:
1:2ae7a8b01771
Child:
4:def20a1665d1
diff -r 18fd28044860 -r cbe2dcca5058 lib/N5110.cpp
--- a/lib/N5110.cpp	Thu Mar 18 13:21:12 2021 +0000
+++ b/lib/N5110.cpp	Fri Mar 19 20:04:39 2021 +0000
@@ -1,5 +1,7 @@
 #include "mbed.h"
 #include "N5110.h"
+#include <vector>
+
 
 // overloaded constructor includes power pin - LCD Vcc connected to GPIO pin
 // this constructor works fine with LPC1768 - enough current sourced from GPIO
@@ -411,38 +413,56 @@
 
 }
 
-int N5110::pointsCurve(unsigned int const n1, 
-                       unsigned int const  n2, 
-                       float perc)
+//******************************************************************************
+float N5110::aidCurve(float const n1, 
+                      float const n2, 
+                      float perc)
 { 
-    int diff = n2 - n1;
+    float diff = n2 - n1;
     return n1 + ( diff * perc );
 }
 
-//funtion to draw curve with Benzier curve
-void N5110::drawCurve(unsigned int const x0,
-                      unsigned int const y0,
-                      unsigned int const x1,
-                      unsigned int const y1,
-                      unsigned int const x2,
-                      unsigned int const y2)
+
+
+//******************************************************************************
+//funtion to draw curve with Bezier curve
+std::vector<Vector2Df> N5110::getCurve(float const x0,
+                                 float const y0,
+                                 float const x1,
+                                 float const y1,
+                                 float const x2,
+                                 float const y2)
 {  
+    std::vector<Vector2Df> curve_points;//_x,curve_points_y;
     for( float i = 0 ; i < 1 ; i += 0.01 )
     {
-        int xa, ya, xb, yb, x, y;
-        xa = pointsCurve(x0 , x1 , i);
-        ya = pointsCurve(y0 , y1 , i);
-        xb = pointsCurve(x1 , x2 , i);
-        yb = pointsCurve(y1 , y2 , i);
+        float xa, ya, xb, yb; //x, y;
+        xa = aidCurve(x0 , x1 , i);
+        ya = aidCurve(y0 , y1 , i);
+        xb = aidCurve(x1 , x2 , i);
+        yb = aidCurve(y1 , y2 , i);
+        
+        //                                x - coord             y - coord
+        Vector2Df curvePoint = {aidCurve(xa , xb , i),aidCurve(ya , yb , i)};
     
-        x = pointsCurve(xa , xb , i);
-        y = pointsCurve(ya , yb , i);
-    
-        setPixel(x,  y, true);
-    }    
+        curve_points.push_back(curvePoint);
+    }
+    return curve_points;    
 }
 
 
+// *****************************************************************************
+// take points on a curve, decide whether to draw them or not
+void N5110::drawCurve(std::vector<Vector2Df> curve_points, int offset, int step, int type)
+{
+    if(type == TYPE_SOLID){
+        for(int i = 0; i < curve_points.size()-1; i += step){
+            drawLine(static_cast<int>(curve_points[i].x),static_cast<int>(curve_points[i].y), 
+            static_cast<int>(curve_points[i+step].x),static_cast<int>(curve_points[i+step].y), FILL_BLACK);
+        }
+    }
+}
+
 void N5110::drawLine(unsigned int const x0,
                      unsigned int const y0,
                      unsigned int const x1,