Skip to content
Snippets Groups Projects
Commit 71b4bfa7 authored by Michael's avatar Michael
Browse files

added commentary to output.c

parent 7c698a5d
Branches
Tags
No related merge requests found
#include "output.h" #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){ int paste_row(SDL_Renderer* renderer, int y, enum row row_type){
SDL_Rect destination = { SDL_Rect destination = {
...@@ -60,7 +62,10 @@ int paste_row(SDL_Renderer* renderer, int y, enum row row_type){ ...@@ -60,7 +62,10 @@ int paste_row(SDL_Renderer* renderer, int y, enum row row_type){
return 0; 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) { 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; int offset = 20;
if (type == coin){ if (type == coin){
...@@ -73,6 +78,8 @@ int paste_car(SDL_Renderer* renderer, int x, int y, int width, int height,int sp ...@@ -73,6 +78,8 @@ int paste_car(SDL_Renderer* renderer, int x, int y, int width, int height,int sp
.w = width, .w = width,
.h = height}; .h = height};
//correct "car" type is displayed
//could be implemented like above with switch case
if (type == boat){ if (type == boat){
if (SDL_RenderCopy(renderer, img_plank, NULL, &rect) != 0) { if (SDL_RenderCopy(renderer, img_plank, NULL, &rect) != 0) {
SDL_Log("Bild konnte nicht kopiert werden! SDL_Error Error: %s\n",SDL_GetError()); 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 ...@@ -123,7 +130,9 @@ int paste_car(SDL_Renderer* renderer, int x, int y, int width, int height,int sp
return(0); 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){ int func_digits(int score){
if (score == 0) if (score == 0)
return(1); return(1);
...@@ -135,6 +144,8 @@ int func_digits(int score){ ...@@ -135,6 +144,8 @@ int func_digits(int score){
return(i); return(i);
} }
//V: renderer exists
//N: current playerhighscore is displayed in white in the upper right corner
int paste_score (SDL_Renderer* renderer) { int paste_score (SDL_Renderer* renderer) {
int digits = func_digits(playerhighscore); int digits = func_digits(playerhighscore);
...@@ -157,7 +168,8 @@ int paste_score (SDL_Renderer* renderer) { ...@@ -157,7 +168,8 @@ int paste_score (SDL_Renderer* renderer) {
return -1; return -1;
} }
char output [5]; char output [10];
//max displayable score has 10 digits
sprintf(output, "%d", playerhighscore); sprintf(output, "%d", playerhighscore);
SDL_Surface* surfaceMessage = SDL_Surface* surfaceMessage =
TTF_RenderText_Blended_Wrapped (font, output, (SDL_Color) {225, 225, 225, 255}, 4*200); TTF_RenderText_Blended_Wrapped (font, output, (SDL_Color) {225, 225, 225, 255}, 4*200);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment