From 71b4bfa7768c7256de1ecd7098cfd34af3dd4f32 Mon Sep 17 00:00:00 2001 From: Michael <michaef01@zedat.fu-berlin.de> Date: Thu, 21 Mar 2024 14:15:56 +0100 Subject: [PATCH] added commentary to output.c --- output.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/output.c b/output.c index edbcec0..754b652 100644 --- a/output.c +++ b/output.c @@ -1,5 +1,7 @@ #include "output.h" +//V: renderer exists, enum row_type is correct and not renamed, correct y coordinates are transferred +//N: img corresponding to row_type is set to coordinates: x: 0 to 900 y: y to y+100 and displayed via renderer int paste_row(SDL_Renderer* renderer, int y, enum row row_type){ SDL_Rect destination = { @@ -60,7 +62,10 @@ int paste_row(SDL_Renderer* renderer, int y, enum row row_type){ return 0; } +//V renderer exists, correct x, y coordinates and width and height and speed and type of car is passed on +//N: car is set to correct variables and displayed in renderer with correct image and direction int paste_car(SDL_Renderer* renderer, int x, int y, int width, int height,int speed,enum vehicle type) { + //Prevents cars from being displayed at the wrong position int offset = 20; if (type == coin){ @@ -73,6 +78,8 @@ int paste_car(SDL_Renderer* renderer, int x, int y, int width, int height,int sp .w = width, .h = height}; + //correct "car" type is displayed + //could be implemented like above with switch case if (type == boat){ if (SDL_RenderCopy(renderer, img_plank, NULL, &rect) != 0) { SDL_Log("Bild konnte nicht kopiert werden! SDL_Error Error: %s\n",SDL_GetError()); @@ -123,7 +130,9 @@ int paste_car(SDL_Renderer* renderer, int x, int y, int width, int height,int sp return(0); } - +//used to calculate width of score display +//V: score exists +//N: returns int corresponding to digits of score int func_digits(int score){ if (score == 0) return(1); @@ -135,6 +144,8 @@ int func_digits(int score){ return(i); } +//V: renderer exists +//N: current playerhighscore is displayed in white in the upper right corner int paste_score (SDL_Renderer* renderer) { int digits = func_digits(playerhighscore); @@ -157,7 +168,8 @@ int paste_score (SDL_Renderer* renderer) { return -1; } - char output [5]; + char output [10]; + //max displayable score has 10 digits sprintf(output, "%d", playerhighscore); SDL_Surface* surfaceMessage = TTF_RenderText_Blended_Wrapped (font, output, (SDL_Color) {225, 225, 225, 255}, 4*200); -- GitLab