diff --git a/auto.c b/auto.c index 08d880bebc78796863767b6930551d7800cab73b..e076cb2800ce17a628618cd40fd3809379aef023 100644 --- a/auto.c +++ b/auto.c @@ -6,7 +6,7 @@ // -5000 <= pred_pos < 5000 <- Position des Vorgängerautos // 0 <= pred_width < 500 -// Nachbedingung: Ein struct Auto mit den Parametern wurde initialisiert +// Nachbedingung: Ein Auto wurde aus den Parametern initialisiert struct Car* init_car(int speed,int width,int height,int pred_pos,int pred_width,enum vehicle t){ struct Car *b = malloc(sizeof(*b)); @@ -146,7 +146,7 @@ int move_car(SDL_Renderer* renderer,struct Row *n){ } while (true){ - if (n->y_pos <=player->y && player->y <=n->y_pos + ROW_SIZE && kollision(cur->x_pos,cur->width)){ + if (n->y_pos <= player->y && player->y <= n->y_pos + ROW_SIZE && kollision(cur->x_pos,cur->width)){ if (cur->type == car || cur->type == train){ return(1); @@ -159,13 +159,13 @@ int move_car(SDL_Renderer* renderer,struct Row *n){ playerscore += 5; playerhighscore += 5; - paste_score (renderer); + paste_score(renderer); cur->type = coin_gathered; } } cur->x_pos += n->speed; - paste_car(renderer,cur->x_pos,n->y_pos,cur->width,cur->height,n->speed,cur); + paste_car(renderer,cur->x_pos,n->y_pos,cur->width,cur->height,n->speed,cur->type); if (cur->next == NULL){ break; diff --git a/gameLoop.h b/gameLoop.h index 8ff7abd40a0a0031a319edc1979524b44ed3022b..5ba487158bd1b52b07f0376af8879330ce6fb37a 100644 --- a/gameLoop.h +++ b/gameLoop.h @@ -6,6 +6,7 @@ #include <stdbool.h> #include <SDL_rect.h> #include <SDL_render.h> +#include <stdio.h> //#include "auto.h" #include "map.h" //#include "main.h" diff --git a/map.c b/map.c index 728828fa42b115feb1669989d21bc0b7936a2498..9eb9310dc79f68e949ec6de1f8bc25b2b9cd2129 100644 --- a/map.c +++ b/map.c @@ -21,7 +21,12 @@ struct LinkedList* init_map(enum vehicle theme){ struct LinkedList *list = malloc(sizeof(*list)); - + + if (list == NULL){ + perror("kein Speicherplatz"); + + } + struct Row *n = grass(true,false,SCREEN_HEIGHT - ROW_SIZE); //helles Gras mit y = 900 list->head = n; @@ -46,7 +51,7 @@ struct LinkedList* init_map(enum vehicle theme){ m = track( n->y_pos - ROW_SIZE); }else if (theme == coin_gathered){ - m = grass((i+1)%2,(i*ROW_SIZE + player->y/ROW_SIZE) % 100 == 98,n->y_pos - ROW_SIZE); + m = grass((i+1)%2,false,n->y_pos - ROW_SIZE); } n->next = m; diff --git a/map.h b/map.h index 223f0ec5a3698e6bc9348f5877489fd4d2a28bed..6881498dfd15c60096cf56cbc4c0d9fadd8fdab2 100644 --- a/map.h +++ b/map.h @@ -3,6 +3,7 @@ #include <stdbool.h> #include <stdlib.h> +#include <stdio.h> #include <SDL.h> #include <SDL_render.h> #include "auto.h" diff --git a/output.c b/output.c index 9960510ca9d3e8d70c2f4ad5a019f3e4de940426..edbcec074fa3b276a8ae80d81221c0f0836c9db8 100644 --- a/output.c +++ b/output.c @@ -60,26 +60,26 @@ int paste_row(SDL_Renderer* renderer, int y, enum row row_type){ return 0; } -int paste_car(SDL_Renderer* renderer, int x, int y, int width, int height,int speed,struct Car* cur) { +int paste_car(SDL_Renderer* renderer, int x, int y, int width, int height,int speed,enum vehicle type) { int offset = 20; - if (cur->type == coin){ + if (type == coin){ offset = 25; } SDL_Rect rect = { .x = x, - .y = y + offset, // Autos,Züge und Boote werden um 20 Pixel nach unten gesetzt, Münzen 30 + .y = y + offset, // Autos,Züge und Boote werden um 20 Pixel nach unten gesetzt, Münzen um 25 .w = width, .h = height}; - if (cur->type == boat){ + 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()); return(1); } return(0); - }else if(cur->type == car){ + }else if(type == car){ if (speed > 0) { if (SDL_RenderCopy(renderer, img_car_trans, NULL, &rect) != 0) { SDL_Log("Bild konnte nicht kopiert werden! SDL_Error Error: %s\n",SDL_GetError()); @@ -93,7 +93,7 @@ int paste_car(SDL_Renderer* renderer, int x, int y, int width, int height,int sp } return(0); } - }else if(cur->type == train){ + }else if(type == train){ if (speed > 0){ if (SDL_RenderCopy(renderer, img_trainR, NULL, &rect) != 0) { SDL_Log("Bild konnte nicht kopiert werden! SDL_Error Error: %s\n",SDL_GetError()); @@ -106,13 +106,13 @@ int paste_car(SDL_Renderer* renderer, int x, int y, int width, int height,int sp } } return(0); - }else if(cur->type == coin){ + }else if(type == coin){ if (SDL_RenderCopy(renderer, img_coin, NULL, &rect) != 0) { SDL_Log("Bild konnte nicht kopiert werden! SDL_Error Error: %s\n",SDL_GetError()); return(1); } return(0); - }else if (cur->type == coin_gathered){ + }else if (type == coin_gathered){ return(0); } if (SDL_RenderFillRect(renderer, &rect) != 0) { diff --git a/output.h b/output.h index f921df680005a1a84eef8a54d2b8b2b7e13f9212..1a3640f27523a613076b4b9aafcbbcfe4393a722 100644 --- a/output.h +++ b/output.h @@ -19,7 +19,7 @@ //Declaration of functions int paste_row(SDL_Renderer*, int , enum row); -int paste_car(SDL_Renderer*, int, int, int, int,int,struct Car*); +int paste_car(SDL_Renderer*, int, int, int, int,int,enum vehicle); int paste_score (SDL_Renderer*);