From 39dc1a35dd22e9a48a55182aaef8cc4d2f0bf6e5 Mon Sep 17 00:00:00 2001 From: Janos <janol55@zedat.fu-berlin.de> Date: Wed, 20 Mar 2024 22:52:06 +0100 Subject: [PATCH] kleinere Fehlerbehebungen --- auto.c | 8 ++++---- gameLoop.h | 1 + map.c | 9 +++++++-- map.h | 1 + output.c | 16 ++++++++-------- output.h | 2 +- 6 files changed, 22 insertions(+), 15 deletions(-) diff --git a/auto.c b/auto.c index 08d880b..e076cb2 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 8ff7abd..5ba4871 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 728828f..9eb9310 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 223f0ec..6881498 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 9960510..edbcec0 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 f921df6..1a3640f 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*); -- GitLab