“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

Committer:
eencae
Date:
Fri Dec 11 12:25:25 2020 +0000
Revision:
0:be41a15e7a86
Child:
1:2ae7a8b01771
Initial Commit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
eencae 0:be41a15e7a86 1 /* mbed Microcontroller Library
eencae 0:be41a15e7a86 2 * Copyright (c) 2019 ARM Limited
eencae 0:be41a15e7a86 3 * SPDX-License-Identifier: Apache-2.0
eencae 0:be41a15e7a86 4 */
eencae 0:be41a15e7a86 5
eencae 0:be41a15e7a86 6 #include "mbed.h"
eencae 0:be41a15e7a86 7 #include "platform/mbed_thread.h"
eencae 0:be41a15e7a86 8 #include "Joystick.h"
eencae 0:be41a15e7a86 9 #include "N5110.h"
eencae 0:be41a15e7a86 10
eencae 0:be41a15e7a86 11
eencae 0:be41a15e7a86 12 //VCC,SCE,RST,D/C,MOSI,SCLK,LED
eencae 0:be41a15e7a86 13 N5110 lcd(p14,p8,p9,p10,p11,p13,p21);
eencae 0:be41a15e7a86 14
eencae 0:be41a15e7a86 15 // y x
eencae 0:be41a15e7a86 16 Joystick joystick(p20,p19);
eencae 0:be41a15e7a86 17
eencae 0:be41a15e7a86 18 int main()
eencae 0:be41a15e7a86 19 {
eencae 0:be41a15e7a86 20 // initialise the LCD and joystick
eencae 0:be41a15e7a86 21 lcd.init();
eencae 0:be41a15e7a86 22 lcd.setContrast(0.5);
eencae 0:be41a15e7a86 23 joystick.init();
eencae 0:be41a15e7a86 24
eencae 0:be41a15e7a86 25 while (1) {
eencae 0:be41a15e7a86 26 // read the joystick to get the x- and y- values
eencae 0:be41a15e7a86 27 Vector2D coord = joystick.get_mapped_coord();
eencae 0:be41a15e7a86 28 printf("Coord = %f | %f\n",coord.x,coord.y);
eencae 0:be41a15e7a86 29
eencae 0:be41a15e7a86 30 lcd.clear(); // clear buffer at the start of the loop
eencae 0:be41a15e7a86 31 char buffer[14]={0}; // each character is 6 pixels wide, screen is 84 pixels (84/6 = 14)
eencae 0:be41a15e7a86 32 sprintf(buffer,"x = %.3f",coord.x); // print formatted data to buffer
eencae 0:be41a15e7a86 33 lcd.printString(buffer,0,2); // display on screen
eencae 0:be41a15e7a86 34 sprintf(buffer,"y = %.3f",coord.y); // print formatted data to buffer
eencae 0:be41a15e7a86 35 lcd.printString(buffer,0,3); // display on screen
eencae 0:be41a15e7a86 36 lcd.refresh(); // need to fresh the screen to get the message to appear
eencae 0:be41a15e7a86 37
eencae 0:be41a15e7a86 38 thread_sleep_for(200);
eencae 0:be41a15e7a86 39 }
eencae 0:be41a15e7a86 40 }