“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:
1:2ae7a8b01771
Parent:
0:be41a15e7a86
Child:
2:18fd28044860
--- a/main.cpp	Fri Dec 11 12:25:25 2020 +0000
+++ b/main.cpp	Wed Mar 17 17:32:56 2021 +0000
@@ -4,37 +4,68 @@
  */
 
 #include "mbed.h"
-#include "platform/mbed_thread.h"
 #include "Joystick.h"
 #include "N5110.h"
 
+// objects
+// BusOut leds(LED4,LED3,LED2,LED1);
 
-//VCC,SCE,RST,D/C,MOSI,SCLK,LED
-N5110 lcd(p14,p8,p9,p10,p11,p13,p21);
+//       VCC,SCE,RST,D/C,MOSI,SCLK,LED
+ N5110 lcd(p14,p8,p9,p10,p11,p13,p21);
+ 
+ DigitalIn button_A(p29);
+ DigitalIn button_C(p27);
 
 //                y     x  
-Joystick joystick(p20,p19);
+// Joystick joystick(p20,p19);
+
+//           B   G   R
+//BusOut leds(p22,p23,p24);
+//          LSB     MSB
+
+// functions
+void init_buttons();
 
 int main()
 {
     // initialise the LCD and joystick
     lcd.init();
     lcd.setContrast(0.5);
-    joystick.init();
-    
-    while (1) {
-        // read the joystick to get the x- and y- values
-        Vector2D coord = joystick.get_mapped_coord(); 
-        printf("Coord = %f | %f\n",coord.x,coord.y);    
+   
+    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);
         
-        lcd.clear();  // clear buffer at the start of the loop
-        char buffer[14]={0};  // each character is 6 pixels wide, screen is 84 pixels (84/6 = 14)
-        sprintf(buffer,"x = %.3f",coord.x); // print formatted data to buffer
-        lcd.printString(buffer,0,2);     // display on screen
-        sprintf(buffer,"y = %.3f",coord.y); // print formatted data to buffer
-        lcd.printString(buffer,0,3);     // display on screen
-        lcd.refresh();  // need to fresh the screen to get the message to appear
+ /*       for (int y = 12; y <= 48; y++) {
+            lcd.drawSprite(48,y,6,3,(int *) road_line);
+            if (y == 48) 
+            {
+                y = 12;    
+            }
+        } */
         
-        thread_sleep_for(200);
+        if ( button_A.read() == 1) 
+        {
+            lcd.printString("A!",0,0);  
+        }
+        
+        if ( button_C.read() == 1) 
+        {
+            lcd.printString("C!",0,0);    
+        }
+        
+        lcd.refresh(); 
+        thread_sleep_for(50);
     }
 }
+
+void init_buttons()
+{
+    // PCB has external pull-down resistors so turn the internal ones off
+    // (default for DigitalIn)
+    button_A.mode(PullNone);
+    button_C.mode(PullNone);
+}
\ No newline at end of file