“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:
2:18fd28044860
Child:
4:def20a1665d1
--- a/lib/Road.cpp	Thu Mar 18 13:21:12 2021 +0000
+++ b/lib/Road.cpp	Fri Mar 19 20:04:39 2021 +0000
@@ -1,6 +1,5 @@
 #include "Road.h"
-#include "GameEngine.h"
-#include <cmath> 
+#include <vector>
 
 // constructure
 Road::Road() {}
@@ -14,66 +13,58 @@
     _inclination = inclination;
 }
 
-void Road::draw(N5110 &lcd, int i) { 
-
-    if (_direction == 0) {
-        lcd.drawLine(0,12,84,12, FILL_BLACK);
-        lcd.drawLine(28,12,12,48, FILL_BLACK);
-        lcd.drawLine(56,12,72,48, FILL_BLACK);    
-    }
-    
-    else if (_direction == 1) {
-            lcd.drawLine(0,12,84,12, FILL_BLACK);
-            lcd.drawCurve(12,48,20 + 7 * i, 30 - abs(i),28,12);
-            lcd.drawCurve(72,48,64 + 5 * i, 30 - abs(i),56,12);
-    }
-            
-    else {
-            lcd.drawLine(0,12,84,12, FILL_BLACK);
-            lcd.drawCurve(12,48,20 - 2 * i,30 - i,28,12);
-            lcd.drawCurve(72,48,68 - 6 * i,30 - i,56,12); 
-    }
-}
-
 void Road::set_inclination(int inclination) {
     _inclination = inclination; 
     }
 
-void Road::set_direction(int direction) {
-    _direction = direction;
+void Road::draw(N5110 &lcd, int direction) { 
+
+    if (direction == 0) {
+        lcd.drawLine( 0,12,84,12, FILL_BLACK);
+        lcd.drawLine(28,12,12,48, FILL_BLACK);
+        lcd.drawLine(56,12,72,48, FILL_BLACK);
     }
-  
     
-void _draw_warn(N5110 &lcd, int warn_position) {
-    const int warn_sign[13][16] = {
-        { 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0 },
-        { 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0 },
-        { 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0 },
-        { 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0 },
-        { 0, 0, 0, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 0, 0, 0 },
-        { 0, 0, 0, 1, 0, 0, 0, 1, 1, 0, 0, 0, 1, 0, 0, 0 },
-        { 0, 0, 0, 1, 0, 0, 0, 1, 1, 0, 0, 0, 1, 0, 0, 0 },
-        { 0, 0, 1, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 1, 0, 0 },
-        { 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0 },
-        { 0, 1, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 1, 0 },
-        { 0, 1, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 1, 0 },
-        { 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 },
-        { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 },
+    else {
+        lcd.drawLine (0,12,84,12, FILL_BLACK);
+        std::vector<Vector2Df> curve_points_1 = lcd.getCurve(12,48,20 + 5 * direction, 30 - abs(direction),28,12);
+        std::vector<Vector2Df> curve_points_2 = lcd.getCurve(72,48,64 + 5 * direction, 30 - abs(direction),56,12);
+        
+        lcd.drawCurve(curve_points_1, 0, 1, TYPE_SOLID);
+        lcd.drawCurve(curve_points_2, 0, 1, TYPE_SOLID);
+    }
+}
+
+    
+void Road::draw_warn(N5110 &lcd, int warn_position) {
+    const int warn_sign[12][12] = {
+        { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 },
+        { 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 },
+        { 1, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 1 },
+        { 1, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 1 },
+        { 1, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 1 },
+        { 1, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 1 },
+        { 1, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 1 },
+        { 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 },
+        { 1, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 1 },
+        { 1, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 1 },
+        { 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 },
+        { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 },
     };
     
     // if ball comes from the left side
     if (warn_position == 0) {
-        lcd.drawSprite(10,18,13,16,(int *)warn_sign); 
+        lcd.drawSprite(0,18,12,12,(int *)warn_sign); 
     }
     
     // if ball comes from the top
     if (warn_position == 1) {
-        lcd.drawSprite(40,0,13,16,(int *)warn_sign); 
+        lcd.drawSprite(36,0,12,12,(int *)warn_sign); 
     }
     
     // if ball comes from the right side
     if (warn_position == 2) {
-        lcd.drawSprite(68,18,13,16,(int *)warn_sign); 
+        lcd.drawSprite(72,18,12,12,(int *)warn_sign); 
     }
 }