“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:
alex_20
Date:
Fri Mar 19 20:04:39 2021 +0000
Revision:
3:cbe2dcca5058
Parent:
2:18fd28044860
Child:
4:def20a1665d1
everything in N5110

Who changed what in which revision?

UserRevisionLine numberNew contents of line
alex_20 1:2ae7a8b01771 1 #include "Road.h"
alex_20 3:cbe2dcca5058 2 #include <vector>
alex_20 1:2ae7a8b01771 3
alex_20 1:2ae7a8b01771 4 // constructure
alex_20 2:18fd28044860 5 Road::Road() {}
alex_20 2:18fd28044860 6
alex_20 2:18fd28044860 7 void Road::init() {
alex_20 2:18fd28044860 8 //initialize parameters
alex_20 2:18fd28044860 9 int direction = 0;
alex_20 2:18fd28044860 10 int inclination = 0;
alex_20 2:18fd28044860 11
alex_20 2:18fd28044860 12 _direction = direction;
alex_20 2:18fd28044860 13 _inclination = inclination;
alex_20 2:18fd28044860 14 }
alex_20 2:18fd28044860 15
alex_20 2:18fd28044860 16 void Road::set_inclination(int inclination) {
alex_20 2:18fd28044860 17 _inclination = inclination;
alex_20 1:2ae7a8b01771 18 }
alex_20 1:2ae7a8b01771 19
alex_20 3:cbe2dcca5058 20 void Road::draw(N5110 &lcd, int direction) {
alex_20 3:cbe2dcca5058 21
alex_20 3:cbe2dcca5058 22 if (direction == 0) {
alex_20 3:cbe2dcca5058 23 lcd.drawLine( 0,12,84,12, FILL_BLACK);
alex_20 3:cbe2dcca5058 24 lcd.drawLine(28,12,12,48, FILL_BLACK);
alex_20 3:cbe2dcca5058 25 lcd.drawLine(56,12,72,48, FILL_BLACK);
alex_20 1:2ae7a8b01771 26 }
alex_20 2:18fd28044860 27
alex_20 3:cbe2dcca5058 28 else {
alex_20 3:cbe2dcca5058 29 lcd.drawLine (0,12,84,12, FILL_BLACK);
alex_20 3:cbe2dcca5058 30 std::vector<Vector2Df> curve_points_1 = lcd.getCurve(12,48,20 + 5 * direction, 30 - abs(direction),28,12);
alex_20 3:cbe2dcca5058 31 std::vector<Vector2Df> curve_points_2 = lcd.getCurve(72,48,64 + 5 * direction, 30 - abs(direction),56,12);
alex_20 3:cbe2dcca5058 32
alex_20 3:cbe2dcca5058 33 lcd.drawCurve(curve_points_1, 0, 1, TYPE_SOLID);
alex_20 3:cbe2dcca5058 34 lcd.drawCurve(curve_points_2, 0, 1, TYPE_SOLID);
alex_20 3:cbe2dcca5058 35 }
alex_20 3:cbe2dcca5058 36 }
alex_20 3:cbe2dcca5058 37
alex_20 3:cbe2dcca5058 38
alex_20 3:cbe2dcca5058 39 void Road::draw_warn(N5110 &lcd, int warn_position) {
alex_20 3:cbe2dcca5058 40 const int warn_sign[12][12] = {
alex_20 3:cbe2dcca5058 41 { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 },
alex_20 3:cbe2dcca5058 42 { 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 },
alex_20 3:cbe2dcca5058 43 { 1, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 1 },
alex_20 3:cbe2dcca5058 44 { 1, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 1 },
alex_20 3:cbe2dcca5058 45 { 1, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 1 },
alex_20 3:cbe2dcca5058 46 { 1, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 1 },
alex_20 3:cbe2dcca5058 47 { 1, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 1 },
alex_20 3:cbe2dcca5058 48 { 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 },
alex_20 3:cbe2dcca5058 49 { 1, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 1 },
alex_20 3:cbe2dcca5058 50 { 1, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 1 },
alex_20 3:cbe2dcca5058 51 { 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 },
alex_20 3:cbe2dcca5058 52 { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 },
alex_20 2:18fd28044860 53 };
alex_20 2:18fd28044860 54
alex_20 2:18fd28044860 55 // if ball comes from the left side
alex_20 2:18fd28044860 56 if (warn_position == 0) {
alex_20 3:cbe2dcca5058 57 lcd.drawSprite(0,18,12,12,(int *)warn_sign);
alex_20 1:2ae7a8b01771 58 }
alex_20 2:18fd28044860 59
alex_20 2:18fd28044860 60 // if ball comes from the top
alex_20 2:18fd28044860 61 if (warn_position == 1) {
alex_20 3:cbe2dcca5058 62 lcd.drawSprite(36,0,12,12,(int *)warn_sign);
alex_20 2:18fd28044860 63 }
alex_20 2:18fd28044860 64
alex_20 2:18fd28044860 65 // if ball comes from the right side
alex_20 2:18fd28044860 66 if (warn_position == 2) {
alex_20 3:cbe2dcca5058 67 lcd.drawSprite(72,18,12,12,(int *)warn_sign);
alex_20 2:18fd28044860 68 }
alex_20 2:18fd28044860 69 }
alex_20 2:18fd28044860 70