Skip to content
Snippets Groups Projects
Commit fb601b1d authored by Janos's avatar Janos
Browse files

Vögel bewegen sich jetzt, auftreten angepasst und Code Kommentiert

parent f17d472a
No related branches found
No related tags found
No related merge requests found
#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)
......
......@@ -32,6 +32,7 @@ struct bird{
int height;
int width;
int anim;
int anim2;
};
enum row{
......
......@@ -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
......@@ -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
......
......@@ -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) {
......
......@@ -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{
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment