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

fliegende Vögel hinzugefügt und kleine Verbesserungen

parent 7f16dc4f
Branches
No related tags found
No related merge requests found
CFLAGS=$(shell pkg-config --cflags sdl2 SDL2_image SDL2_ttf) -std=c99 -Wall -Wextra -pedantic -g -O0
CPPFLAGS=-MMD -MF $*.d # Generate dependency files
LDLIBS=$(shell pkg-config --libs sdl2 SDL2_image SDL2_ttf) -lm
OBJ=output.o map.o rows.o auto.o charac.o main.o init.o gameLoop.o menu2.o title_screen.o file_own.o
OBJ=output.o map.o rows.o auto.o charac.o main.o init.o gameLoop.o menu2.o title_screen.o file_own.o bird.o
CC=gcc
all: main
......
#include "hDateien/auto.h"
// Vorbedinung:
// 0 < |speed| < 10, 0 < width < 500, 0 < height < 100,
// 0 < |speed| < 10,
// -5000 <= pred_pos < 5000 <- Position des Vorgängerautos
// 0 <= pred_width < 500
......@@ -35,6 +35,8 @@ struct Car* init_race_car(int speed,int pred_pos,int pred_width){
}
}
b->color = none;
return(b);
}
......@@ -65,6 +67,9 @@ struct Car* init_train(int speed,int pred_pos,int pred_width){
b->x_pos = pred_pos - b->width - distance;
}
}
b->color = none;
return(b);
}
......@@ -78,7 +83,9 @@ struct Car* init_boat(int speed,int pred_pos,int pred_width){
int min_distance;
int distance;
b->width = 200;
int p = (rand() % 2) + 2;
b->width = 100 * p;
b->height = 60;
b->type = boat;
......@@ -86,7 +93,7 @@ struct Car* init_boat(int speed,int pred_pos,int pred_width){
b->x_pos = pred_pos;
}else{
min_distance = 50 * abs(speed);
min_distance = 50 * abs(speed)+(b->width/3);
distance = (rand() % 300) + min_distance;
if (speed < 0){
......@@ -97,6 +104,8 @@ struct Car* init_boat(int speed,int pred_pos,int pred_width){
}
return(b);
b->color = none;
}
struct Car* init_coin(int speed,int pred_pos,int pred_width){
......@@ -124,6 +133,8 @@ struct Car* init_coin(int speed,int pred_pos,int pred_width){
b->x_pos = pred_pos - b->width - distance;
}
b->color = none;
return(b);
}
......@@ -157,12 +168,21 @@ struct Car* init_car(int speed,int pred_pos,int pred_width){
}
}
int p = rand() % 3;
if (p == 0){
b->color = red;
}else if(p == 1){
b->color = blue;
}else{
b->color = green;
}
return(b);
}
// Vorbedinung:
// 0 < |speed| < 10, 0 < width < 500, 0 < height < 100,
// 0 < |speed| < 10,
// 0 <= start_pos <= 900
// Nachbedingung: Initialisierte LinkedList von Autos, abhängig von den Parametern
......@@ -260,7 +280,7 @@ int move_car(SDL_Renderer* renderer,struct Row *n){
}else if (cur -> type == boat){
onBoat = true;
center_water(cur->x_pos,cur->width);
}else if(cur ->type == coin){
playerscore += 5;
......@@ -272,7 +292,7 @@ int move_car(SDL_Renderer* renderer,struct Row *n){
}
cur->x_pos += n->speed;
paste_car(renderer,cur->x_pos,n->y_pos,cur->width,cur->height,n->speed,cur->type);
paste_car(renderer,cur->x_pos,n->y_pos,cur->width,cur->height,n->speed,cur->type,cur->color);
if (cur->next == NULL){
break;
......
bird.c 0 → 100644
#include "hDateien/bird.h"
struct bird* init_bird(int x_pos,int y_pos){
struct bird *b = malloc(sizeof(*b));
if(b == NULL){
perror("kein Speicheeplatz");
}
b->speed = -3;//(((rand() % 2)*2) -1)*3
b->x_pos = x_pos;
b->y_pos = y_pos;//(rand() % 10) * ROW_SIZE
b->height = 80;
b->width = 80 ;
b->anim = 0;
return(b);
}
bool move_bird(SDL_Renderer* renderer,struct bird *b,int speed){
if (b->anim)
b->x_pos += b->speed;
b->y_pos += speed;
paste_bird(renderer,b->x_pos+10,b->y_pos+10,b->height,b->width,b->anim);
if (b->anim){
b->anim = (b->anim + 1) % 16;
if (b->anim == 0)
b->anim++;
}
if ((b->x_pos < -b->width && b->speed < 0) || (b->x_pos > 1000 && b->speed > 0) ){
return(true);
}
return(false);
}
\ No newline at end of file
......@@ -108,3 +108,14 @@ void recenter_player(void){
player->x = (i-50) + 8*ROW_SIZE; // Spieler steht ganz rechts, dann verschiebe um 20 nach links mit Offset von 8 Kästen
}
void center_water(int x_pos,int x_width){
int i = 70;
for(int j = 0;j<x_width/ROW_SIZE;j++){
if (player->x < x_pos +i+ j * ROW_SIZE){
player->x = x_pos + (i-50) + j * ROW_SIZE ;
return;
}
}
player->x = x_pos +(i-50)+ (x_width-ROW_SIZE) ;
}
\ No newline at end of file
......@@ -34,7 +34,7 @@ bool gameLoop(enum vehicle theme,SDL_Renderer* renderer) {
int last_move;
//used to implement rows and allows to remove rows out of view
struct LinkedList *map = init_map(theme);
struct LinkedList *map = init_map(theme);
//every at least 16ms this loop is called
while (!end_game) {
......@@ -86,8 +86,11 @@ bool gameLoop(enum vehicle theme,SDL_Renderer* renderer) {
end_game = true;
}
//Position des Spielers wird aktualisiert und gezeichnet
update_character(speed, renderer);
//Der aktuelle Score wird oben rechts angezeigt
paste_score (renderer);
......
......@@ -7,6 +7,7 @@
#include <stdbool.h>
#include "output.h"
#include "header.h"
#include "charac.h"
//Declarations of functions
......
#ifndef BiRD_H
#define BIRD_H
#include <stdlib.h>
#include "main.h"
#include "output.h"
#include <SDL_render.h>
#include "header.h"
#include "stdbool.h"
struct bird* init_bird(int,int);
bool move_bird(SDL_Renderer* renderer,struct bird *b,int);
#endif
\ No newline at end of file
......@@ -28,4 +28,6 @@ int update_character(int,SDL_Renderer*);
void recenter_player(void);
void center_water(int,int);
#endif
\ No newline at end of file
......@@ -13,6 +13,7 @@
#include "file_own.h"
#include "header.h"
#include "charac.h"
#include "bird.h"
......
......@@ -9,6 +9,22 @@ extern SDL_Rect *player;
extern int playerscore;
extern int playerhighscore;
enum color{
red,
blue,
green,
none
};
struct bird{
int x_pos;
int y_pos;
int speed;
int height;
int width;
int anim;
};
enum row{
grassBright,
grassDark,
......@@ -34,6 +50,7 @@ struct Car{
int x_pos;
int width;
int height;
enum color color;
struct Car *next;
};
......@@ -46,6 +63,7 @@ struct Row{
int y_pos;
int speed;
int stone;
struct bird *bird;
struct LinkedList_car *cars;
};
......
......@@ -40,5 +40,24 @@ extern SDL_Texture *img_stone;
extern SDL_Texture *img_race_street;
extern SDL_Texture *img_race_carL;
extern SDL_Texture *img_race_carR;
extern SDL_Texture *img_car_blueR;
extern SDL_Texture *img_car_blueL;
extern SDL_Texture *img_car_greenR;
extern SDL_Texture *img_car_greenL;
extern SDL_Texture *img_bird0;
extern SDL_Texture *img_bird1;
extern SDL_Texture *img_bird2;
extern SDL_Texture *img_bird3;
extern SDL_Texture *img_bird4;
extern SDL_Texture *img_bird5;
extern SDL_Texture *img_bird6;
extern SDL_Texture *img_bird7;
extern SDL_Texture *img_bird_sit0;
extern SDL_Texture *img_bird_sit1;
extern SDL_Texture *img_bird_sit2;
extern SDL_Texture *img_bird_sit3;
extern SDL_Texture *img_bird_sit4;
#endif
\ No newline at end of file
......@@ -11,7 +11,7 @@
//#include "gameLoop.h"
#include "output.h"
#include "charac.h"
#include "bird.h"
#include "header.h"
//Declaration of functions
......
......@@ -19,8 +19,8 @@
//Declaration of functions
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);
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);
#endif
......@@ -8,9 +8,10 @@
//#include "gameLoop.h"
#include "auto.h"
//#include "main.h"
#include "bird.h"
#include "header.h"
//Declaration of functions
int gen_stone();
......
images/bird0.png

1.54 KiB

images/bird1.png

1.53 KiB

images/bird2.png

1.31 KiB

images/bird3.png

1.46 KiB

images/bird4.png

1.53 KiB

images/bird5.png

1.42 KiB

0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment