From fb601b1d288e2a4b67de1e07579512d5f692d6c5 Mon Sep 17 00:00:00 2001 From: Janos <janol55@zedat.fu-berlin.de> Date: Sun, 14 Apr 2024 14:40:44 +0200 Subject: [PATCH] =?UTF-8?q?V=C3=B6gel=20bewegen=20sich=20jetzt,=20auftrete?= =?UTF-8?q?n=20angepasst=20und=20Code=20Kommentiert?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bird.c | 9 ++++++--- hDateien/header.h | 1 + hDateien/output.h | 2 +- init.c | 10 +++++----- output.c | 46 ++++++++++++++++++++++++++++++++++++++++++---- rows.c | 2 +- 6 files changed, 56 insertions(+), 14 deletions(-) diff --git a/bird.c b/bird.c index 860a089..097f331 100644 --- a/bird.c +++ b/bird.c @@ -1,6 +1,6 @@ #include "hDateien/bird.h" - +// Nachbedingung: Es wurde ein Vogel initialisiert struct bird* init_bird(int x_pos,int y_pos){ struct bird *b = malloc(sizeof(*b)); if(b == NULL){ @@ -14,15 +14,18 @@ struct bird* init_bird(int x_pos,int y_pos){ b->height = 80; b->width = 80 ; b->anim = 0; + b->anim2 = 0; return(b); } bool move_bird(SDL_Renderer* renderer,struct bird *b,int speed){ - if (b->anim) + if (b->anim){ b->x_pos += b->speed; + } + b->anim2 = (b->anim2 + 1) % 300; b->y_pos += speed; - paste_bird(renderer,b->x_pos+10,b->y_pos+10,b->height,b->width,b->anim); + paste_bird(renderer,b->x_pos+10,b->y_pos+10,b->height,b->width,b->anim,b->anim2); if (b->anim){ b->anim = (b->anim + 1) % 16; if (b->anim == 0) diff --git a/hDateien/header.h b/hDateien/header.h index 5253c5f..cd6cbf9 100644 --- a/hDateien/header.h +++ b/hDateien/header.h @@ -32,6 +32,7 @@ struct bird{ int height; int width; int anim; + int anim2; }; enum row{ diff --git a/hDateien/output.h b/hDateien/output.h index b3fe993..4283c90 100644 --- a/hDateien/output.h +++ b/hDateien/output.h @@ -21,6 +21,6 @@ int paste_stone(SDL_Renderer*,int,int); int paste_row(SDL_Renderer*, int , enum row); int paste_car(SDL_Renderer*, int, int, int, int,int,enum vehicle,enum color); int paste_score (SDL_Renderer*); -int paste_bird(SDL_Renderer*,int,int,int,int,int); +int paste_bird(SDL_Renderer*,int,int,int,int,int,int); #endif diff --git a/init.c b/init.c index 0c4b183..9fed897 100644 --- a/init.c +++ b/init.c @@ -20,7 +20,7 @@ SDL_Texture *img_trainL; //https://www.pinterest.com/hassanhojabri/sprite/ SDL_Texture *img_trainR; //https://www.pinterest.com/hassanhojabri/sprite/ SDL_Texture *img_plank; //https://www.craiyon.com/image/_XEsXKthRYqpK8Vn6ZixAg SDL_Texture *img_duck; -SDL_Texture *img_player_down; +SDL_Texture *img_player_down; SDL_Texture *img_player_left; SDL_Texture *img_player_right; SDL_Texture *img_3D_Duck; @@ -112,7 +112,7 @@ int init_images(SDL_Renderer* renderer) { img_trainL = IMG_LoadTexture(renderer,"images/trainL.png"); // Quelle: https://www.pinterest.de/pin/645492559082244309/ img_trainR = IMG_LoadTexture(renderer,"images/trainR.png"); // Quelle: https://www.pinterest.de/pin/645492559082244309/ img_plank = IMG_LoadTexture(renderer,"images/plank.png"); // Quelle: https://www.craiyon.com/image/_XEsXKthRYqpK8Vn6ZixAg - img_duck = IMG_LoadTexture(renderer,"images/player.png"); // Quelle: https://www.sandromaglione.com/articles/pixel-art-top-down-game-sprite-design-and-animation + img_duck = IMG_LoadTexture(renderer,"images/player.png"); // Quelle: https://www.sandromaglione.com/articles/pixel-art-top-down-game-sprite-design-and-animation img_3D_Duck = IMG_LoadTexture(renderer,"images/3D_Duck.png"); img_stone = IMG_LoadTexture(renderer,"images/stone.png"); // Quelle: https://www.vecteezy.com/vector-art/22285554-stones-in-pixel-art-style img_race_street = IMG_LoadTexture(renderer,"images/race_street.jpg"); @@ -135,9 +135,9 @@ int init_images(SDL_Renderer* renderer) { img_bird_sit2 = IMG_LoadTexture(renderer,"images/bird_sit2.png"); img_bird_sit3 = IMG_LoadTexture(renderer,"images/bird_sit3.png"); img_bird_sit4 = IMG_LoadTexture(renderer,"images/bird_sit4.png"); - img_player_down = IMG_LoadTexture(renderer,"images/player_down.png"); - img_player_left = IMG_LoadTexture(renderer,"images/player_left.png"); - img_player_right = IMG_LoadTexture(renderer,"images/player_right.png"); + img_player_down = IMG_LoadTexture(renderer,"images/player_down.png"); // Quelle: https://www.sandromaglione.com/articles/pixel-art-top-down-game-sprite-design-and-animation + img_player_left = IMG_LoadTexture(renderer,"images/player_left.png"); // Quelle: https://www.sandromaglione.com/articles/pixel-art-top-down-game-sprite-design-and-animation + img_player_right = IMG_LoadTexture(renderer,"images/player_right.png"); // Quelle: https://www.sandromaglione.com/articles/pixel-art-top-down-game-sprite-design-and-animation //Initiierung der Bilder diff --git a/output.c b/output.c index 74e50d9..01a4910 100644 --- a/output.c +++ b/output.c @@ -253,7 +253,7 @@ int paste_score (SDL_Renderer* renderer) { } -int paste_bird(SDL_Renderer* renderer,int x_pos,int y_pos,int height,int width,int anim){ +int paste_bird(SDL_Renderer* renderer,int x_pos,int y_pos,int height,int width,int anim,int anim2){ SDL_Rect rect = { .x = x_pos, @@ -261,10 +261,48 @@ int paste_bird(SDL_Renderer* renderer,int x_pos,int y_pos,int height,int width,i .w = height, .h = width}; if (anim == 0){ - if (SDL_RenderCopy(renderer, img_bird_sit0, NULL, &rect) != 0) { - SDL_Log("Bild konnte nicht kopiert werden! SDL_Error Error: %s\n",SDL_GetError()); - return(1); + if (anim2 <30){ + if (SDL_RenderCopy(renderer, img_bird_sit0, NULL, &rect) != 0) { + SDL_Log("Bild konnte nicht kopiert werden! SDL_Error Error: %s\n",SDL_GetError()); + return(1); + } + }else if(anim2 <60){ + if (SDL_RenderCopy(renderer, img_bird_sit1, NULL, &rect) != 0) { + SDL_Log("Bild konnte nicht kopiert werden! SDL_Error Error: %s\n",SDL_GetError()); + return(1); + } + }else if(anim2 <90){ + if (SDL_RenderCopy(renderer, img_bird_sit0, NULL, &rect) != 0) { + SDL_Log("Bild konnte nicht kopiert werden! SDL_Error Error: %s\n",SDL_GetError()); + return(1); + } + }else if(anim2 <120){ + if (SDL_RenderCopy(renderer, img_bird_sit1, NULL, &rect) != 0) { + SDL_Log("Bild konnte nicht kopiert werden! SDL_Error Error: %s\n",SDL_GetError()); + return(1); + } + }else if(anim2 <150){ + if (SDL_RenderCopy(renderer, img_bird_sit0, NULL, &rect) != 0) { + SDL_Log("Bild konnte nicht kopiert werden! SDL_Error Error: %s\n",SDL_GetError()); + return(1); } + }else if(anim2 <180){ + if (SDL_RenderCopy(renderer, img_bird_sit1, NULL, &rect) != 0) { + SDL_Log("Bild konnte nicht kopiert werden! SDL_Error Error: %s\n",SDL_GetError()); + return(1); + } + }else if(anim2 <240){ + if (SDL_RenderCopy(renderer, img_bird_sit3, NULL, &rect) != 0) { + SDL_Log("Bild konnte nicht kopiert werden! SDL_Error Error: %s\n",SDL_GetError()); + return(1); + } + }else if(anim2 <300){ + if (SDL_RenderCopy(renderer, img_bird_sit4, NULL, &rect) != 0) { + SDL_Log("Bild konnte nicht kopiert werden! SDL_Error Error: %s\n",SDL_GetError()); + return(1); + } + } + }else if (anim <= 1){ if (SDL_RenderCopy(renderer, img_bird0, NULL, &rect) != 0) { diff --git a/rows.c b/rows.c index 78dac6d..a76856a 100644 --- a/rows.c +++ b/rows.c @@ -54,7 +54,7 @@ struct Row* grass(bool dark,bool gold,int y_pos){ } int p = rand() % 10; - if (p < 5){ + if (p < 7){ n->stone = gen_stone(); n->bird = NULL; }else{ -- GitLab