diff --git a/main.c b/main.c index 8984f816b78afb19a60a852cc6ac14c04a9b8eec..64e2ec0568aa76b2274f2abb7e67826eb5d1a904 100644 --- a/main.c +++ b/main.c @@ -66,6 +66,7 @@ struct textures_s{ SDL_Texture* background; /*!< Texture liée à l'image du fond de l'écran. */ SDL_Texture* ship; /*!< Texture liée à l'image du vaisseau. */ SDL_Texture* meteorite; /*!< Texture liée à l'image du météorite. */ + SDL_Texture* finishLine; /*!< Texture liée à l'image de la ligne d'arrivée. */ /* A COMPLETER */ }; @@ -97,6 +98,7 @@ typedef struct sprite_s sprite_t; struct world_s{ sprite_t *vaisseau ; /*!< Représentation du vaisseau */ sprite_t *mur; /*!< Représentation du météorite */ + sprite_t *ligneArriver; int gameover; /*!< Champ indiquant si l'on est à la fin du jeu */ int speed_h; /*!< Vitesse de déplacement horizontal des éléments du jeu */ @@ -127,11 +129,13 @@ void print_sprite(sprite_t *sprite){ * \param w * \param h */ -void init_sprite(sprite_t *sprite, int x, int y, int w, int h){ +sprite_t *init_sprite(sprite_t *sprite, int x, int y, int w, int h){ + sprite = malloc(sizeof(sprite_t)); sprite->x = x; sprite->y = y; sprite->w = w; sprite->h = h; + return sprite; } /** @@ -147,10 +151,11 @@ void init_data(world_t * world){ world->speed_h = 0; // Initialisation du vaisseau - world->vaisseau = malloc(sizeof(sprite_t)); - world->mur = malloc(sizeof(sprite_t)); - init_sprite(world->vaisseau, SCREEN_WIDTH/2 - SHIP_SIZE/2, SCREEN_HEIGHT - SHIP_SIZE, SHIP_SIZE, SHIP_SIZE); - init_sprite(world->mur, 0, 0, 3*METEORITE_SIZE, 7*METEORITE_SIZE); + + + world->vaisseau = init_sprite(world->vaisseau, SCREEN_WIDTH/2 - SHIP_SIZE/2, SCREEN_HEIGHT - SHIP_SIZE, SHIP_SIZE, SHIP_SIZE); + world->mur = init_sprite(world->mur, 0, 0, 3*METEORITE_SIZE, 7*METEORITE_SIZE); + world->ligneArriver = init_sprite(world->ligneArriver, 0, -40, SCREEN_WIDTH, FINISH_LINE_HEIGHT); print_sprite(world->vaisseau); } @@ -189,7 +194,7 @@ int is_game_over(world_t *world){ */ void update_data(world_t *world){ - printf("%d\n", world->speed_h); + world->ligneArriver->y += INITIAL_SPEED - world->speed_h; world->mur->y += INITIAL_SPEED - world->speed_h; } @@ -255,6 +260,9 @@ void handle_events(SDL_Event *event,world_t *world){ void clean_textures(textures_t *textures){ clean_texture(textures->background); clean_texture(textures->ship); + clean_texture(textures->meteorite); + clean_texture(textures->finishLine); + /* A COMPLETER */ } @@ -270,6 +278,7 @@ void init_textures(SDL_Renderer *renderer, textures_t *textures){ textures->background = load_image( "ressources/space-background.bmp",renderer); textures->ship = load_image( "ressources/spaceship.bmp",renderer); textures->meteorite = load_image( "ressources/meteorite.bmp",renderer); + textures->finishLine = load_image( "ressources/finish_line.bmp",renderer); /* A COMPLETER */ @@ -329,6 +338,8 @@ void refresh_graphics(SDL_Renderer *renderer, world_t *world,textures_t *texture /* A COMPLETER */ apply_sprite(renderer, textures->ship, world->vaisseau); + apply_sprite(renderer, textures->finishLine, world->ligneArriver); + for (int i = 0; i < world->mur->w/METEORITE_SIZE ; i++){ for (int i2 = 0; i2 < world->mur->h/METEORITE_SIZE ; i2++){ apply_wall(renderer, textures->meteorite, world->mur->x+i*METEORITE_SIZE, world->mur->y+i2*METEORITE_SIZE); diff --git a/main.o b/main.o index 0ba0cad0673bdab91a183949bafd71d2c9b4809d..ea24b91200aa77c889204cf77230e9a71b225a18 100644 Binary files a/main.o and b/main.o differ diff --git a/spacecorridor.exe b/spacecorridor.exe index 6021f427a8a35813cc0d605a42f978deb56d4a71..f6afb07d558e13762ed9955ea1aea9a6dfc42eda 100644 Binary files a/spacecorridor.exe and b/spacecorridor.exe differ