“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
Child:
4:def20a1665d1
everything in N5110

Who changed what in which revision?

UserRevisionLine numberNew contents of line
alex_20 3:cbe2dcca5058 1 #include "Utils.h"
alex_20 3:cbe2dcca5058 2 #include <vector>
alex_20 3:cbe2dcca5058 3
alex_20 3:cbe2dcca5058 4 // constructure
alex_20 3:cbe2dcca5058 5 Utils::Utils() {}
alex_20 3:cbe2dcca5058 6
alex_20 3:cbe2dcca5058 7
alex_20 3:cbe2dcca5058 8 float Utils::curveEquation(float const n1,
alex_20 3:cbe2dcca5058 9 float const n2,
alex_20 3:cbe2dcca5058 10 float perc)
alex_20 3:cbe2dcca5058 11 {
alex_20 3:cbe2dcca5058 12 float diff = n2 - n1;
alex_20 3:cbe2dcca5058 13 return n1 + ( diff * perc );
alex_20 3:cbe2dcca5058 14 }
alex_20 3:cbe2dcca5058 15
alex_20 3:cbe2dcca5058 16
alex_20 3:cbe2dcca5058 17 //funtion to get the points using Bezier curve
alex_20 3:cbe2dcca5058 18 std::vector<Vector2Df> Utils::getCurve(float const x0,
alex_20 3:cbe2dcca5058 19 float const y0,
alex_20 3:cbe2dcca5058 20 float const x1,
alex_20 3:cbe2dcca5058 21 float const y1,
alex_20 3:cbe2dcca5058 22 float const x2,
alex_20 3:cbe2dcca5058 23 float const y2)
alex_20 3:cbe2dcca5058 24 {
alex_20 3:cbe2dcca5058 25 std::vector<Vector2Df> curve_points;//_x,curve_points_y;
alex_20 3:cbe2dcca5058 26 for( float i = 0 ; i < 1 ; i += 0.01 )
alex_20 3:cbe2dcca5058 27 {
alex_20 3:cbe2dcca5058 28 float xa, ya, xb, yb; //x, y;
alex_20 3:cbe2dcca5058 29 xa = aidCurve(x0 , x1 , i);
alex_20 3:cbe2dcca5058 30 ya = aidCurve(y0 , y1 , i);
alex_20 3:cbe2dcca5058 31 xb = aidCurve(x1 , x2 , i);
alex_20 3:cbe2dcca5058 32 yb = aidCurve(y1 , y2 , i);
alex_20 3:cbe2dcca5058 33
alex_20 3:cbe2dcca5058 34 // x - coord y - coord
alex_20 3:cbe2dcca5058 35 Vector2Df curvePoint = {aidCurve(xa , xb , i),aidCurve(ya , yb , i)};
alex_20 3:cbe2dcca5058 36
alex_20 3:cbe2dcca5058 37 curve_points.push_back(curvePoint);
alex_20 3:cbe2dcca5058 38 }
alex_20 3:cbe2dcca5058 39
alex_20 3:cbe2dcca5058 40 return curve_points;
alex_20 3:cbe2dcca5058 41 }