diff --git a/auto.c b/auto.c index 62e3a7fe6c58a909cfe8fb941e8ee5a3effba913..b16879dbcd52ef85f626f19ecde48e749ba4b149 100644 --- a/auto.c +++ b/auto.c @@ -15,6 +15,7 @@ struct Car* init_car(int speed,int width,int height,int pred_pos,int pred_width, perror("kein Speicherplatz"); } + int min_distance; int distance; int p = rand() % 10; @@ -31,13 +32,19 @@ struct Car* init_car(int speed,int width,int height,int pred_pos,int pred_width, }else{ distance = 25; } + if (speed < 0){ + b->x_pos = pred_pos + pred_width + distance; + }else{ + b->x_pos = pred_pos - b->width - distance; + } + }else{ b->width = width; b->height = height; - if (t == coin || t == coin_gathered) + if (t == coin || t == coin_gathered){ b->type = car; - else{ + }else{ b->type = t; } if (pred_width == 0){ // kein Vorgänger @@ -54,15 +61,14 @@ struct Car* init_car(int speed,int width,int height,int pred_pos,int pred_width, min_distance = 50 * abs(speed) + 50; distance = (rand() % 500) + min_distance; } - } - } - if (speed < 0){ - b->x_pos = pred_pos + pred_width + distance; - }else{ - b->x_pos = pred_pos - b->width - distance; + if (speed < 0){ + b->x_pos = pred_pos + pred_width + distance; + }else{ + b->x_pos = pred_pos - b->width - distance; + } + } } - return(b); }