diff --git a/bird.c b/bird.c index 860a089d61d0cf373fa84d8f35b24a648b31ba7a..097f331add01b2828bded2a73a1b711c43155715 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 5253c5fffe967972be5b0549ec3c8affbae7a625..cd6cbf91de45d132b20e14482fabfd9d3ba5cbbb 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 b3fe993cfbb17eb4fac5d9a88ad1f1e2daf07db1..4283c901b3c8bb2969996ab17db4842d19d7166c 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 0c4b18343935ac47af155cb937c3bd2c7646fa45..9fed89724fb608a6af4f085d2d55b780daddcd2e 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 74e50d92e2e163eda2a6a4948fade04588c28ed5..01a49104d182b83cac8db228e054ecd40cc5e57a 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 78dac6d764c6219087c094c143b01f52fbce56f5..a76856a3080916d7e4013e8bebd00301b1c05202 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{