“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:
2:18fd28044860
Parent:
1:2ae7a8b01771
Child:
3:cbe2dcca5058
--- a/main.cpp	Wed Mar 17 17:32:56 2021 +0000
+++ b/main.cpp	Thu Mar 18 13:21:12 2021 +0000
@@ -6,55 +6,48 @@
 #include "mbed.h"
 #include "Joystick.h"
 #include "N5110.h"
+#include "Road.h"
+#include <cmath> 
 
 // objects
 // BusOut leds(LED4,LED3,LED2,LED1);
 
-//       VCC,SCE,RST,D/C,MOSI,SCLK,LED
- N5110 lcd(p14,p8,p9,p10,p11,p13,p21);
- 
+ N5110 lcd(p14,p8,p9,p10,p11,p13,p21); 
  DigitalIn button_A(p29);
  DigitalIn button_C(p27);
 
 //                y     x  
 // Joystick joystick(p20,p19);
 
-//           B   G   R
+//             B   G   R
 //BusOut leds(p22,p23,p24);
 //          LSB     MSB
 
+Road road;
+
 // functions
 void init_buttons();
 
 int main()
 {
-    // initialise the LCD and joystick
+    // initialisation
     lcd.init();
+    road.init();
     lcd.setContrast(0.5);
    
     while(1) {
         lcd.clear();
-        lcd.drawLine(0,12,84,12, FILL_BLACK);
-        lcd.drawLine(28,12,12,48, FILL_BLACK);
-        lcd.drawLine(56,12,72,48, FILL_BLACK);
-        lcd.drawCurve(30,48,50,20,60,48);
+        
+        road.draw(lcd, 0);
         
- /*       for (int y = 12; y <= 48; y++) {
-            lcd.drawSprite(48,y,6,3,(int *) road_line);
-            if (y == 48) 
-            {
-                y = 12;    
-            }
-        } */
+        road.set_direction(1);
         
-        if ( button_A.read() == 1) 
-        {
-            lcd.printString("A!",0,0);  
+        if (button_A.read() == 1) {
+            road.draw(lcd, 1);    
         }
         
-        if ( button_C.read() == 1) 
-        {
-            lcd.printString("C!",0,0);    
+        if (button_A.read() == 1) {
+            road.draw(lcd, 2);    
         }
         
         lcd.refresh();