Henry Triff
/
ELEC2645_Project_el18ht
Diff: Graphics/Graphics.cpp
- Revision:
- 10:29126a41b1da
- Parent:
- 9:7b1093d3f03a
- Child:
- 17:4c5f25d5c4d5
--- a/Graphics/Graphics.cpp Thu Mar 05 15:40:21 2020 +0000 +++ b/Graphics/Graphics.cpp Wed Mar 25 15:36:01 2020 +0000 @@ -4,6 +4,57 @@ // Sprites //*********** +int logo[48][84] = { + {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0}, + {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0}, + {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,0,0,0,0,0,0,0,0,0,0,1,1,0,0}, + {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,1,1,0,0}, + {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,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0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, + {0,0,0,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0} +}; + int flag[8][8] = { {4,1,1,1,1,1,1,1}, {4,1,1,0,1,0,1,1}, @@ -200,17 +251,22 @@ //************************** // MAIN GRAPHICS FUNCTION //************************** +// This is the main function for the graphics. It is a LARGE function but it reduces the clutter in the main function. +// It is a LARGE function but it reduces the clutter in the main function. +// This is run once every frame void Graphics::Draw_Map(Point_2D translation, int angle, float squish, Line_2D *Track_Lines, Line_2D *Track_Dotted_Lines, Line_2D *Track_Walls, Point_2D *Track_Flags, Triangle_2D *Track_Boost_Plates, Map_Data map_info, int car_type, Point_2D ghost_position, N5110 &LCD) { + //Variable declaration enum cars {Basic, Offroad, Drifter, Sportscar, Racecar, Stupid}; Line_2D Track_Lines_Transformed[map_info.number_of_track_lines]; Line_2D Track_Dotted_Lines_Transformed[map_info.number_of_dotted_lines]; Point_2D Transformed_Flags[map_info.number_of_flags]; Line_2D Transformed_Walls[map_info.number_of_walls]; Point_2D Transformed_Ghost; - - for(int i = 0; i < map_info.number_of_track_lines; i++) { + + //Transforms the points of the track lines + for(int i = 0; i < map_info.number_of_track_lines; i++) { //Iterates through the given track array Track_Lines_Transformed[i] = Track_Lines[i]; //Translation Track_Lines_Transformed[i].from = Translate_Point(Track_Lines_Transformed[i].from, Round(translation.x), Round(translation.y)); @@ -222,8 +278,9 @@ Track_Lines_Transformed[i].from = Squish_Point(Track_Lines_Transformed[i].from, squish); Track_Lines_Transformed[i].to = Squish_Point(Track_Lines_Transformed[i].to, squish); } - - for(int i = 0; i < map_info.number_of_dotted_lines; i++) { + + //Transforms the points of the dotted lines on the track + for(int i = 0; i < map_info.number_of_dotted_lines; i++) { //Iterates through the given dotted lines array Track_Dotted_Lines_Transformed[i] = Track_Dotted_Lines[i]; //Translation Track_Dotted_Lines_Transformed[i].from = Translate_Point(Track_Dotted_Lines_Transformed[i].from, Round(translation.x), Round(translation.y)); @@ -235,8 +292,9 @@ Track_Dotted_Lines_Transformed[i].from = Squish_Point(Track_Dotted_Lines_Transformed[i].from, squish); Track_Dotted_Lines_Transformed[i].to = Squish_Point(Track_Dotted_Lines_Transformed[i].to, squish); } - - for(int i = 0; i < map_info.number_of_flags; i++) { + + //Transforms the points of the start flags + for(int i = 0; i < map_info.number_of_flags; i++) { //Iterates through the given flags array Transformed_Flags[i] = Track_Flags[i]; //Translation Transformed_Flags[i] = Translate_Point(Transformed_Flags[i], Round(translation.x), Round(translation.y)); @@ -245,8 +303,9 @@ //Squish Transformed_Flags[i] = Squish_Point(Transformed_Flags[i], squish); } - - for(int i = 0; i < map_info.number_of_walls; i++) { + + //Transforms the points of the walls + for(int i = 0; i < map_info.number_of_walls; i++) { //Iterates throught the given walls array Transformed_Walls[i] = Track_Walls[i]; //Translation Transformed_Walls[i].from = Translate_Point(Transformed_Walls[i].from, Round(translation.x), Round(translation.y)); @@ -258,7 +317,8 @@ Transformed_Walls[i].from = Squish_Point(Transformed_Walls[i].from, squish); Transformed_Walls[i].to = Squish_Point(Transformed_Walls[i].to, squish); } - + + //Transforms the points of the ghost position Transformed_Ghost = ghost_position; //Translation Transformed_Ghost = Translate_Point(Transformed_Ghost, Round(translation.x), Round(translation.y)); @@ -267,31 +327,37 @@ //Squish Transformed_Ghost = Squish_Point(Transformed_Ghost, squish); Transformed_Ghost.x = Transformed_Ghost.x + 4; - - for(int i = 0; i < map_info.number_of_track_lines; i++) { + + //Draws the track lines + for(int i = 0; i < map_info.number_of_track_lines; i++) { //Iterates through each line Graphics_Draw_Line(Track_Lines_Transformed[i].from, Track_Lines_Transformed[i].to, true, LCD); } - - for(int i = 0; i < map_info.number_of_dotted_lines; i++) { + + //Draws the dotted lines + for(int i = 0; i < map_info.number_of_dotted_lines; i++) { //Iterates through each line Graphics_Draw_Line(Track_Dotted_Lines_Transformed[i].from, Track_Dotted_Lines_Transformed[i].to,false, LCD); } - - for(int i = 0; i < map_info.number_of_boost_plates; i++) { + + //Draws the boost plates + for(int i = 0; i < map_info.number_of_boost_plates; i++) { //Iterates through each plate Graphics_Draw_Boost_Plate(Track_Boost_Plates[i], translation, angle, squish, LCD); } - - for(int i = 0; i < map_info.number_of_flags; i++) { + + //Draws the flags + for(int i = 0; i < map_info.number_of_flags; i++) { //Iterates through each flag Graphics_Draw_Sprite(Transformed_Flags[i], 8, 8, (int *)flag, LCD); } - - Graphics_Draw_Sprite(Transformed_Ghost, 8, 8, (int *)ghost, LCD); - + + //Draws the ghost + Graphics_Draw_Sprite(Transformed_Ghost, 8, 8, (int *)ghost, LCD); + + //Draws the walls for(int i = 0; i < map_info.number_of_walls; i++) { Graphics_Draw_Wall(Transformed_Walls[i].from, Transformed_Walls[i].to,4, LCD); } - + + //Draws the players car Point_2D car_position = {4,0}; - if(car_type == Stupid) { Graphics_Draw_Sprite(car_position,8,8,(int *)stupid_car, LCD); } else if(car_type == Racecar) { @@ -307,11 +373,23 @@ } } +//************** +// START LOGO +//************** + +void Graphics::Draw_Logo(N5110 &LCD) //Draw the game logo +{ + LCD.clear(); + LCD.drawSprite(0,0,48,84,(int *)logo); + LCD.refresh(); + wait(1); +} + //******************* // SCREEN SETTINGS //******************* -void Graphics::Change_Contrast(N5110 &LCD, Gamepad &Device) +void Graphics::Change_Contrast(N5110 &LCD, Gamepad &Device) //Sets the contrast with a greater level of precision { LCD.setContrast((0.35 + 0.2 * Device.read_pot1())); } @@ -320,7 +398,7 @@ // START SCREEN //**************** -void Graphics::Start_Sequence(int state, N5110 &LCD) +void Graphics::Start_Sequence(int state, N5110 &LCD) //Display the countdown numbers before the race starts { Point_2D count_down_position = {8,8}; if(state == 3) { @@ -335,7 +413,7 @@ } -void Graphics::Finish(N5110 &LCD) +void Graphics::Finish(N5110 &LCD) //When the race is over draw the cup symbol { Point_2D finish_position = {8,8}; Graphics_Draw_Sprite(finish_position, 16, 16, (int *) cup, LCD); @@ -345,7 +423,7 @@ // DRAW LAP COUNTER //******************** -void Graphics::Draw_Laps(int laps, N5110 &LCD) +void Graphics::Draw_Laps(int laps, N5110 &LCD) //Prints the lab counter in the bottom left corner { if(laps == 1) { LCD.printString("1",0,5); @@ -360,54 +438,54 @@ } } -void Graphics::Draw_Time(bool finished, Time time, N5110 &LCD) +void Graphics::Draw_Time(bool finished, Time time, N5110 &LCD) //Displays the lap time { - if(finished == false) { + if(finished == false) { //If the race is over, Print the time in the middle of the screen char min[1]; - sprintf(min, "%i", time.mins); - LCD.printString(min,47,5); + sprintf(min, "%i", time.mins); //Converts min integer to char + LCD.printString(min,47,5); //Prints the min char on the screen LCD.printString(":",52,5); - if(time.secs < 10) { - LCD.printString("0",57,5); + if(time.secs < 10) { //If the number of seconds is less than 10 + LCD.printString("0",57,5); //Draw a 0 char sec[1]; - sprintf(sec, "%i", time.secs); - LCD.printString(sec,63,5); + sprintf(sec, "%i", time.secs); //Converts sec integer to char + LCD.printString(sec,63,5); //Prints the sec char on the screen } else { char sec[2]; - sprintf(sec, "%i", time.secs); - LCD.printString(sec,57,5); + sprintf(sec, "%i", time.secs); //Converts sec integer to char + LCD.printString(sec,57,5); //Prints the sec char on the screen } LCD.printString(".",68,5); char mili[2]; - sprintf(mili, "%i", time.milis); - LCD.printString(mili,73,5); - } else { + sprintf(mili, "%i", time.milis); //Convers mili integer to char + LCD.printString(mili,73,5); //Prints the mili char on the screen + } else { //If the race is still ongoing char min[1]; - sprintf(min, "%i", time.mins); - LCD.printString(min,23,0); + sprintf(min, "%i", time.mins); //Convers min integer to char + LCD.printString(min,23,0); //Prints the min char on the screen LCD.printString(":",28,0); - if(time.secs < 10) { - LCD.printString("0",33,0); + if(time.secs < 10) { //If the number of seconds is less than 10 + LCD.printString("0",33,0); //Draw a 0 char sec[1]; - sprintf(sec, "%i", time.secs); - LCD.printString(sec,39,0); + sprintf(sec, "%i", time.secs); //Convers sec integer to char + LCD.printString(sec,39,0); //Prints the sec char on the screen } else { char sec[2]; - sprintf(sec, "%i", time.secs); - LCD.printString(sec,33,0); + sprintf(sec, "%i", time.secs); //Convers sec integer to char + LCD.printString(sec,33,0); //Prints the sec char on the screen } LCD.printString(".",44,0); char mili[2]; - sprintf(mili, "%i", time.milis); - LCD.printString(mili,49,0); + sprintf(mili, "%i", time.milis); //Convers mili integer to char + LCD.printString(mili,49,0); //Prints the mili char on the screen } } @@ -416,25 +494,26 @@ //************** //ROTATE -Point_2D Graphics::Rotate_Point(Point_2D point, float angle) +Point_2D Graphics::Rotate_Point(Point_2D point, float angle) //Rotates all points around the origin { - angle = (angle * PI)/180; - float x_rotated = point.x * cos(angle) - point.y * sin(angle); - float y_rotated = point.y * cos(angle) + point.x * sin(angle); + angle = (angle * PI)/180; //The angle given in degrees is changed into radian form + float x_rotated = point.x * cos(angle) - point.y * sin(angle); //X-points are rotated about the origin + float y_rotated = point.y * cos(angle) + point.x * sin(angle); //Y-points are rotated about the origin return {x_rotated, y_rotated}; } //TRANSLATE -Point_2D Graphics::Translate_Point(Point_2D point, int translate_x, int translate_y) +Point_2D Graphics::Translate_Point(Point_2D point, int translate_x, int translate_y) //Translates all point by a given translationg { - float x_translated = point.x - translate_x; - float y_translated = point.y - translate_y; + float x_translated = point.x - translate_x; //Translates the x-points + float y_translated = point.y - translate_y; //Translates the y-points return {x_translated, y_translated}; } //SQUISH -Point_2D Graphics::Squish_Point(Point_2D point, float squish) +//To get the 3D perspective, the y-coordinate is reduced by a factor +Point_2D Graphics::Squish_Point(Point_2D point, float squish) //Squishes all y-coordinates by a factor { - float x_squish = point.x; - float y_squish = point.y * squish; + float x_squish = point.x; //The x-coordinate remains the same + float y_squish = point.y * squish; //The y-coordinate is reduced return {x_squish, y_squish}; } @@ -442,33 +521,33 @@ // MATH //******** -int Graphics::Round(float number) +int Graphics::Round(float number) //Simple function that rounds floating point numbers { - int number_int = (number * 10); - int remainder = number_int % 10; - if(remainder < 5) { - return ((number_int - remainder) / 10); + int number_int = (number * 10); //The number is multiplied by 10 + int remainder = number_int % 10; //The remainder when dividing by 10 is calculated + if(remainder < 5) { //If the number is less than 5 + return ((number_int - remainder) / 10); //Round down } else { - return ((number_int + (10 - remainder)) / 10); + return ((number_int + (10 - remainder)) / 10); //Round up } } -float Graphics::Gradient(Point_2D from, Point_2D to) +float Graphics::Gradient(Point_2D from, Point_2D to) //Calculates the gradient of the line between two points { - float change_in_y = to.y - from.y; - float change_in_x = to.x - from.x; - float gradient = change_in_y / change_in_x; - if(gradient < 0.001 && gradient > -0.001) { - return 0; + float change_in_y = to.y - from.y; //Calculates the change in the y-values of the two points + float change_in_x = to.x - from.x; //Calculates the change in the x-values of the two points + float gradient = change_in_y / change_in_x; //Calculates the gradient by doing dy/dx + if(gradient < 0.001 && gradient > -0.001) { //If the gradient is aproximately 0 + return 0; //Return zero } else { - return gradient; + return gradient; //Else return the gradient } } -bool Graphics::Gradient_Check_Infinate(Point_2D from, Point_2D to) +bool Graphics::Gradient_Check_Infinate(Point_2D from, Point_2D to) //Checks to see if the gradient is vertical { - float change_in_x = to.x - from.x; - if(change_in_x < 0.001 && change_in_x > -0.001) { + float change_in_x = to.x - from.x; //Calculates the change in the x-value + if(change_in_x < 0.001 && change_in_x > -0.001) { //If the change in x value is very small return true; } else { return false; @@ -483,6 +562,7 @@ { if( Gradient_Check_Infinate(from, to) == false ) { //Checking to see if the line is vertical + //Initialising variables Point_2D plot_x_from = {0,0}; Point_2D plot_x_to = {0,0}; Point_2D plot_y_from = {0,0}; @@ -493,7 +573,7 @@ float x_intercept = (from.x - from.y / gradient); // Calculating the x intercept x - y/m = d if(gradient <= 1 && gradient >= -1) { - //Reordering from and to so that the for loops below can use ++ + //Reordering 'from' and 'to' so that the for loops below can use ++ if(to.x < from.x) { plot_x_from = to; plot_x_to = from; @@ -501,11 +581,11 @@ plot_x_from = from; plot_x_to = to; } - if(solid == true) { + if(solid == true) { //If the line is solid or dotted for(int x = Round(plot_x_from.x); x <= Round(plot_x_to.x); x++) { //Iterating through the x points int y = -(Round((gradient * x) + y_intercept)); //Calculating the value of y for each x point Point_2D plot_x = {x+42, y+36}; //Assigning them to a Plot_2D variable and transforming so the centre of the screen is 0,0 - if(plot_x.x <= 84 && plot_x.x >= 0 && plot_x.y <=48 && plot_x.y >= 0) { + if(plot_x.x <= 84 && plot_x.x >= 0 && plot_x.y <=48 && plot_x.y >= 0) { //Checking to see if the point is on the screen LCD.setPixel(plot_x.x, plot_x.y, true); //Plotting the points } } @@ -513,12 +593,13 @@ for(int x = Round(plot_x_from.x); x <= Round(plot_x_to.x); x+=2) { //Iterating through the x points int y = -(Round((gradient * x) + y_intercept)); //Calculating the value of y for each x point Point_2D plot_x = {x+42, y+36}; //Assigning them to a Plot_2D variable and transforming so the centre of the screen is 0,0 - if(plot_x.x <= 84 && plot_x.x >= 0 && plot_x.y <=48 && plot_x.y >= 0) { + if(plot_x.x <= 84 && plot_x.x >= 0 && plot_x.y <=48 && plot_x.y >= 0) { //Checking to see if the point is on the screen LCD.setPixel(plot_x.x, plot_x.y, true); //Plotting the points } } } } else { + //Reordering 'from' and 'to' so that the for loops below can use ++ if(to.y < from.y) { plot_y_from = to; plot_y_to = from; @@ -526,11 +607,11 @@ plot_y_from = from; plot_y_to = to; } - if(solid == true) { + if(solid == true) { //If the line is solid or dotted for(int y = Round(plot_y_from.y); y <= Round(plot_y_to.y); y++) { //Iterating through the Y points int x = Round((y / gradient) + x_intercept); //Calculating the value of x for every y point Point_2D plot_y = {x+42, (-y)+36}; //Assigning them to a Plot_2D variable and transforming so the centre of the screen is 0,0 - if(plot_y.x <= 84 && plot_y.x >= 0 && plot_y.y <=48 && plot_y.y >= 0) { + if(plot_y.x <= 84 && plot_y.x >= 0 && plot_y.y <=48 && plot_y.y >= 0) { //Checking to see if the point is on the screen LCD.setPixel(plot_y.x, plot_y.y, true); //Plotting the points } } @@ -538,7 +619,7 @@ for(int y = Round(plot_y_from.y); y <= Round(plot_y_to.y); y+=2) { //Iterating through the Y points int x = Round((y / gradient) + x_intercept); //Calculating the value of x for every y point Point_2D plot_y = {x+42, (-y)+36}; //Assigning them to a Plot_2D variable and transforming so the centre of the screen is 0,0 - if(plot_y.x <= 84 && plot_y.x >= 0 && plot_y.y <=48 && plot_y.y >= 0) { + if(plot_y.x <= 84 && plot_y.x >= 0 && plot_y.y <=48 && plot_y.y >= 0) { //Checking to see if the point is on the screen LCD.setPixel(plot_y.x, plot_y.y, true); //Plotting the points } } @@ -557,7 +638,7 @@ plot_y_to = to; } float x_intercept = from.x; //Calculating the x_intercept - if(solid == true) { + if(solid == true) { //If the line is solid or dotted for(int y = plot_y_from.y; y <= plot_y_to.y; y++) { Point_2D plot_y = {x_intercept+42, (-y)+36}; //Assigning them to a Plot_2D variable and transforming so the centre of the screen is 0,0 LCD.setPixel(plot_y.x, plot_y.y, true); //Plotting the points @@ -575,15 +656,15 @@ // DRAW SPRITE //*************** -void Graphics::Graphics_Draw_Sprite(Point_2D point, int x_size, int y_size, int *sprite, N5110 &LCD) +void Graphics::Graphics_Draw_Sprite(Point_2D point, int x_size, int y_size, int *sprite, N5110 &LCD) //Similar to N5110 drawSprite function but mine uses the origin as poin 0,0 and allows for transparent pixels { Point_2D zeroed_point = {Round(point.x) + 42 - x_size, Round(-point.y) + 36 - y_size}; - if(zeroed_point.x <= 84 && zeroed_point.x >= 0 && zeroed_point.y <= 48 && zeroed_point.y >= 0) { - for(int y = 0; y < y_size; y++) { - for(int x = 0; x < x_size; x++) { - if(*((sprite + y*y_size)+x) == 1) { + if(zeroed_point.x <= 84 && zeroed_point.x >= 0 && zeroed_point.y <= 48 && zeroed_point.y >= 0) { //If the point is on the screen + for(int y = 0; y < y_size; y++) { //Iterates through y-points + for(int x = 0; x < x_size; x++) { //Iterates through x-points + if(*((sprite + y*y_size)+x) == 1) { //If the sprite has a 1 at that point then set that pixel to black LCD.setPixel((zeroed_point.x + x), (zeroed_point.y + y), true); - } else if(*((sprite + y*y_size)+x) == 0) { + } else if(*((sprite + y*y_size)+x) == 0) { //If the sprite has a 0 at that point then set that pixel to white LCD.setPixel((zeroed_point.x + x), (zeroed_point.y + y), false); } } @@ -598,6 +679,7 @@ void Graphics::Graphics_Draw_Wall(Point_2D from, Point_2D to, int height, N5110 &LCD) //Draw a line between two points on only the portion of the screen { if(Gradient_Check_Infinate(from, to) == 0) { //Checking to see if the line is vertical + //Declaring points Point_2D plot_x_from = {0,0}; Point_2D plot_x_to = {0,0}; Point_2D plot_y_from = {0,0}; @@ -608,7 +690,7 @@ float x_intercept = (from.x - from.y / gradient); // Calculating the x intercept x - y/m = d if(gradient <= 1 && gradient >= -1) { - //Reordering from and to so that the for loops below can use ++ + //Reordering 'from' and 'to' so that the for loops below can use ++ if(to.x < from.x) { plot_x_from = to; plot_x_to = from; @@ -619,13 +701,14 @@ for(int x = Round(plot_x_from.x); x <= Round(plot_x_to.x); x++) { //Iterating through the x points int y = -(Round((gradient * x) + y_intercept)); //Calculating the value of y for each x point Point_2D plot_x = {x+42, y+36}; //Assigning them to a Plot_2D variable and transforming so the centre of the screen is 0,0 - if(plot_x.x <= 84 && plot_x.x >= 0 && plot_x.y <=48 && plot_x.y >= 0) { - for(int y_add = 0; y_add < height; y_add++) { - LCD.setPixel(plot_x.x, plot_x.y - y_add, true); + if(plot_x.x <= 84 && plot_x.x >= 0 && plot_x.y <=48 && plot_x.y >= 0) { //Checking to see if the point is on the screen + for(int y_add = 0; y_add < height; y_add++) { //To differentiate it from a line, 'heigh' number of pixels above the line are also drawn. This gives the impression of height + LCD.setPixel(plot_x.x, plot_x.y - y_add, true); //Plotting the point } } } } else { + //Reordering 'from' and 'to' so that the for loops can use ++ if(to.y < from.y) { plot_y_from = to; plot_y_to = from; @@ -636,15 +719,16 @@ for(int y = Round(plot_y_from.y); y <= Round(plot_y_to.y); y++) { //Iterating through the Y points int x = Round((y / gradient) + x_intercept); //Calculating the value of x for every y point Point_2D plot_y = {x+42, (-y)+36}; //Assigning them to a Plot_2D variable and transforming so the centre of the screen is 0,0 - if(plot_y.x <= 84 && plot_y.x >= 0 && plot_y.y <=48 && plot_y.y >= 0) { - for(int y_add = 0; y_add < height; y_add++) { - LCD.setPixel(plot_y.x, plot_y.y - y_add, true); + if(plot_y.x <= 84 && plot_y.x >= 0 && plot_y.y <=48 && plot_y.y >= 0) { //Checking to see if the point is on the screen + for(int y_add = 0; y_add < height; y_add++) { //To differentiate it from a line, 'heigh' number of pixels above the line are also drawn. This gives the impression of height + LCD.setPixel(plot_y.x, plot_y.y - y_add, true); //Plotting the point } } } } } else { + //Declaring and initialising points Point_2D plot_y_from = {0,0}; Point_2D plot_y_to = {0,0}; //Reordering from and to so that the for loops below can use ++ @@ -658,8 +742,8 @@ float x_intercept = from.x; //Calculating the x_intercept for(int y = plot_y_from.y; y <= plot_y_to.y; y++) { Point_2D plot_y = {x_intercept+42, (-y)+36}; //Assigning them to a Plot_2D variable and transforming so the centre of the screen is 0,0 - for(int y_add = 0; y_add < height; y_add++) { - LCD.setPixel(plot_y.x, plot_y.y - y_add, true); + for(int y_add = 0; y_add < height; y_add++) { //To differentiate it from a line, 'heigh' number of pixels above the line are also drawn. This gives the impression of height + LCD.setPixel(plot_y.x, plot_y.y - y_add, true); //Plotting the point } } @@ -670,23 +754,29 @@ // DRAW BOOST PLATE //******************** -void Graphics::Graphics_Draw_Boost_Plate(Triangle_2D boost_plate, Point_2D translation, int angle, float squish, N5110 &LCD) +void Graphics::Graphics_Draw_Boost_Plate(Triangle_2D boost_plate, Point_2D translation, int angle, float squish, N5110 &LCD) //Draws a boost plate on the track { + //Using the given coordinates, calculates the points of all corners of the boost plate Point_2D boost_plate_TL = boost_plate.TL; Point_2D boost_plate_TR = {boost_plate.BR.x, boost_plate.TL.y}; Point_2D boost_plate_BL = {boost_plate.TL.x, boost_plate.BR.y}; Point_2D boost_plate_BR = boost_plate.BR; - Point_2D boost_plate_mid; + Point_2D boost_plate_mid; //The coordinate of the point of the arrow of the boost plate + //The type defines the direction the plate is facing, e.g. Noth, South, East, West if(boost_plate.Type == 1) { + //Calculates the coordinate of the point of the arrow drawn on the boost plate boost_plate_mid.x = boost_plate_BR.x; boost_plate_mid.y = (((boost_plate_TL.y - boost_plate_BR.y) / 2) + boost_plate_BR.y); } else if(boost_plate.Type == 2) { + //Calculates the coordinate of the point of the arrow drawn on the boost plate boost_plate_mid.x = (((boost_plate_BR.x - boost_plate_TL.x) / 2) + boost_plate_TL.x); boost_plate_mid.y = boost_plate_BR.y; } else if(boost_plate.Type == 3) { + //Calculates the coordinate of the point of the arrow drawn on the boost plate boost_plate_mid.x = boost_plate_TL.x; boost_plate_mid.y = (((boost_plate_TL.y - boost_plate_BR.y) / 2) + boost_plate_BR.y); } else if(boost_plate.Type == 4) { + //Calculates the coordinate of the point of the arrow drawn on the boost plate boost_plate_mid.x = (((boost_plate_BR.x - boost_plate_TL.x) / 2) + boost_plate_TL.x); boost_plate_mid.y = boost_plate_TL.y; } @@ -711,12 +801,14 @@ boost_plate_BL = Squish_Point(boost_plate_BL, squish); boost_plate_BR = Squish_Point(boost_plate_BR, squish); boost_plate_mid = Squish_Point(boost_plate_mid, squish); - + + //Draws the square edge of the boost plate Graphics_Draw_Line(boost_plate_TL, boost_plate_TR, true, LCD); Graphics_Draw_Line(boost_plate_TR, boost_plate_BR, true, LCD); Graphics_Draw_Line(boost_plate_BR, boost_plate_BL, true, LCD); Graphics_Draw_Line(boost_plate_BL, boost_plate_TL, true, LCD); - + + //For each type of boost plate draw the arrow if(boost_plate.Type == 1) { Graphics_Draw_Line(boost_plate_TL, boost_plate_mid, true, LCD); Graphics_Draw_Line(boost_plate_BL, boost_plate_mid, true, LCD);