“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
Diff: lib/N5110.cpp
- Revision:
- 7:559edc36f261
- Parent:
- 6:40ef2030334c
- Child:
- 8:1fc5e14b0db6
--- a/lib/N5110.cpp Thu Apr 22 10:52:37 2021 +0000 +++ b/lib/N5110.cpp Thu Apr 22 16:33:42 2021 +0000 @@ -402,7 +402,7 @@ } y++; - if (radiusError<0) { + if (radiusError < 0) { radiusError += 2 * y + 1; } else { x--; @@ -412,7 +412,87 @@ } -// ***************************************************************************** +// function to draw ellipse +void N5110:: drawEllipse(unsigned int const xc, + unsigned int const yc, + unsigned int const rx, + unsigned int const ry) +{ + float dx, dy, d1, d2, x, y; + x = 0; + y = ry; + int radiusError = 1-x; + + // Initial decision parameter of region 1 + d1 = (ry * ry) - (rx * rx * ry) + (0.25 * rx * rx); + dx = 2 * ry * ry * x; + dy = 2 * rx * rx * y; + + // For region 1 + while (dx < dy) + { + setPixel (xc + x, yc + y,true); + setPixel (xc - x, yc + y,true); + setPixel (xc + x, yc - y,true); + setPixel (xc - x, yc - y,true); + + if (radiusError < 0) { + radiusError += 2 * x + 1; + } else { + x++; + radiusError += 2 * (x - y) + 1; + } + + // Checking and updating value of + // decision parameter based on algorithm + if (d1 < 0) + { + dx = dx + (2 * ry * ry); + d1 = d1 + dx + (ry * ry); + } + else + { + y--; + dx = dx + (2 * ry * ry); + dy = dy - (2 * rx * rx); + d1 = d1 + dx - dy + (ry * ry); + } + } + + // Region 2 + // Decision parameter of region 2 + d2 = ((ry * ry) * ((x + 0.5) * (x + 0.5))) + + ((rx * rx) * ((y - 1) * (y - 1))) - + (rx * rx * ry * ry); + + // Plotting points of region 2 + while (y >= 0) + { + setPixel (xc + x, yc + y,true); + setPixel (xc - x, yc + y,true); + setPixel (xc + x, yc - y,true); + setPixel (xc - x, yc - y,true); + + y--; + + // Checking and updating parameter + // value based on algorithm + if (d2 > 0) + { + dy = dy - (2 * rx * rx); + d2 = d2 + (rx * rx) - dy; + } + else + { + x++; + dx = dx + (2 * ry * ry); + dy = dy - (2 * rx * rx); + d2 = d2 + dx - dy + (rx * rx); + } + } +} + + // take points on a curve, decide whether to draw them or not void N5110::drawCurve(std::vector<Vector2Df> curve_points, float offset, int dash_len, int type) {