“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
main.cpp@1:2ae7a8b01771, 2021-03-17 (annotated)
- Committer:
- alex_20
- Date:
- Wed Mar 17 17:32:56 2021 +0000
- Revision:
- 1:2ae7a8b01771
- Parent:
- 0:be41a15e7a86
- Child:
- 2:18fd28044860
Iteration 1. Curve done
Who changed what in which revision?
User | Revision | Line number | New 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 "Joystick.h" |
eencae | 0:be41a15e7a86 | 8 | #include "N5110.h" |
eencae | 0:be41a15e7a86 | 9 | |
alex_20 | 1:2ae7a8b01771 | 10 | // objects |
alex_20 | 1:2ae7a8b01771 | 11 | // BusOut leds(LED4,LED3,LED2,LED1); |
eencae | 0:be41a15e7a86 | 12 | |
alex_20 | 1:2ae7a8b01771 | 13 | // VCC,SCE,RST,D/C,MOSI,SCLK,LED |
alex_20 | 1:2ae7a8b01771 | 14 | N5110 lcd(p14,p8,p9,p10,p11,p13,p21); |
alex_20 | 1:2ae7a8b01771 | 15 | |
alex_20 | 1:2ae7a8b01771 | 16 | DigitalIn button_A(p29); |
alex_20 | 1:2ae7a8b01771 | 17 | DigitalIn button_C(p27); |
eencae | 0:be41a15e7a86 | 18 | |
eencae | 0:be41a15e7a86 | 19 | // y x |
alex_20 | 1:2ae7a8b01771 | 20 | // Joystick joystick(p20,p19); |
alex_20 | 1:2ae7a8b01771 | 21 | |
alex_20 | 1:2ae7a8b01771 | 22 | // B G R |
alex_20 | 1:2ae7a8b01771 | 23 | //BusOut leds(p22,p23,p24); |
alex_20 | 1:2ae7a8b01771 | 24 | // LSB MSB |
alex_20 | 1:2ae7a8b01771 | 25 | |
alex_20 | 1:2ae7a8b01771 | 26 | // functions |
alex_20 | 1:2ae7a8b01771 | 27 | void init_buttons(); |
eencae | 0:be41a15e7a86 | 28 | |
eencae | 0:be41a15e7a86 | 29 | int main() |
eencae | 0:be41a15e7a86 | 30 | { |
eencae | 0:be41a15e7a86 | 31 | // initialise the LCD and joystick |
eencae | 0:be41a15e7a86 | 32 | lcd.init(); |
eencae | 0:be41a15e7a86 | 33 | lcd.setContrast(0.5); |
alex_20 | 1:2ae7a8b01771 | 34 | |
alex_20 | 1:2ae7a8b01771 | 35 | while(1) { |
alex_20 | 1:2ae7a8b01771 | 36 | lcd.clear(); |
alex_20 | 1:2ae7a8b01771 | 37 | lcd.drawLine(0,12,84,12, FILL_BLACK); |
alex_20 | 1:2ae7a8b01771 | 38 | lcd.drawLine(28,12,12,48, FILL_BLACK); |
alex_20 | 1:2ae7a8b01771 | 39 | lcd.drawLine(56,12,72,48, FILL_BLACK); |
alex_20 | 1:2ae7a8b01771 | 40 | lcd.drawCurve(30,48,50,20,60,48); |
eencae | 0:be41a15e7a86 | 41 | |
alex_20 | 1:2ae7a8b01771 | 42 | /* for (int y = 12; y <= 48; y++) { |
alex_20 | 1:2ae7a8b01771 | 43 | lcd.drawSprite(48,y,6,3,(int *) road_line); |
alex_20 | 1:2ae7a8b01771 | 44 | if (y == 48) |
alex_20 | 1:2ae7a8b01771 | 45 | { |
alex_20 | 1:2ae7a8b01771 | 46 | y = 12; |
alex_20 | 1:2ae7a8b01771 | 47 | } |
alex_20 | 1:2ae7a8b01771 | 48 | } */ |
eencae | 0:be41a15e7a86 | 49 | |
alex_20 | 1:2ae7a8b01771 | 50 | if ( button_A.read() == 1) |
alex_20 | 1:2ae7a8b01771 | 51 | { |
alex_20 | 1:2ae7a8b01771 | 52 | lcd.printString("A!",0,0); |
alex_20 | 1:2ae7a8b01771 | 53 | } |
alex_20 | 1:2ae7a8b01771 | 54 | |
alex_20 | 1:2ae7a8b01771 | 55 | if ( button_C.read() == 1) |
alex_20 | 1:2ae7a8b01771 | 56 | { |
alex_20 | 1:2ae7a8b01771 | 57 | lcd.printString("C!",0,0); |
alex_20 | 1:2ae7a8b01771 | 58 | } |
alex_20 | 1:2ae7a8b01771 | 59 | |
alex_20 | 1:2ae7a8b01771 | 60 | lcd.refresh(); |
alex_20 | 1:2ae7a8b01771 | 61 | thread_sleep_for(50); |
eencae | 0:be41a15e7a86 | 62 | } |
eencae | 0:be41a15e7a86 | 63 | } |
alex_20 | 1:2ae7a8b01771 | 64 | |
alex_20 | 1:2ae7a8b01771 | 65 | void init_buttons() |
alex_20 | 1:2ae7a8b01771 | 66 | { |
alex_20 | 1:2ae7a8b01771 | 67 | // PCB has external pull-down resistors so turn the internal ones off |
alex_20 | 1:2ae7a8b01771 | 68 | // (default for DigitalIn) |
alex_20 | 1:2ae7a8b01771 | 69 | button_A.mode(PullNone); |
alex_20 | 1:2ae7a8b01771 | 70 | button_C.mode(PullNone); |
alex_20 | 1:2ae7a8b01771 | 71 | } |