diff --git a/library/Display/Display.c b/library/Display/Display.c index 1506aa9673e0d3faa766a9ae79837f2577036c2a..8fbbe594f970236072aa4bd139fec3d875e37b2f 100644 --- a/library/Display/Display.c +++ b/library/Display/Display.c @@ -49,6 +49,19 @@ void apply_sprite(SDL_Renderer * renderer, SDL_Texture *texture, sprite_t *sprit } } +void apply_sprite_fixed(SDL_Renderer * renderer, SDL_Texture *texture, sprite_t *sprite, world_t *world){ + if(texture != NULL){ + SDL_Rect rect; + rect.x = sprite->x; + rect.y = sprite->y; + + rect.w = sprite->w; + rect.h = sprite->h; + + SDL_RenderCopyEx(renderer, texture, NULL, &rect, world->angle*180/M_PI, NULL, SDL_FLIP_NONE); + } +} + void apply_wall(SDL_Renderer * renderer, SDL_Texture *texture, int x, int y,world_t *world){ if(texture != NULL){ SDL_Rect rect; @@ -92,14 +105,12 @@ void refresh_graphics(SDL_Renderer *renderer, world_t *world,ressources_t *textu apply_sprite(renderer, textures->finishLine, world->ligneArriver, world); apply_walls(renderer, textures->meteorite, world, textures); apply_sprite(renderer, textures->soleil, world->soleil, world); - if (timer_update_s(world) != 0){ - world->str[0] = '\0'; - world->str = strcats(world->str, 3, "temps: ",int_to_str((int)world->timer/1000), "s"); - } apply_text(renderer, 10, 10, 100, 33, world->str, textures->font, textures->color); - apply_sprite(renderer, textures->BarreProgression, world->BarreProgression, world); - apply_sprite(renderer, textures->vaisseauMini, world->vaisseauMini, world); - apply_sprite(renderer, textures->soleilBarre, world->soleilBarre, world); + apply_text(renderer, SCREEN_WIDTH-(60+10*number_of_numbers(world->money)), 10, 15*number_of_numbers(world->money), 30, world->coins_str, textures->font, textures->color); + apply_sprite_fixed(renderer, textures->BarreProgression, world->BarreProgression, world); + apply_sprite_fixed(renderer, textures->vaisseauMini, world->vaisseauMini, world); + apply_sprite_fixed(renderer, textures->soleilBarre, world->soleilBarre, world); + apply_sprite_fixed(renderer, textures->coins, world->coins, world); }else{ apply_text(renderer, 10, 10, 100, 33, "Menu", textures->font, textures->color); @@ -109,13 +120,6 @@ void refresh_graphics(SDL_Renderer *renderer, world_t *world,ressources_t *textu update_screen(renderer); } -int timer_update_s(world_t *world){ - if (world->timer%1000 <= 110|| world->timer%1000 >= 985){ - return world->timer%1000; - } - return 0; -} - void clean(SDL_Window *window, SDL_Renderer * renderer, ressources_t *textures, world_t * world){ clean_data(world); clean_textures(textures); diff --git a/library/Display/Display.h b/library/Display/Display.h index 7b2eeaf2d239f944981170c33c41d92d533d0ab7..0f82b368f7013aa848fb5c3102c71a0d83d7a489 100644 --- a/library/Display/Display.h +++ b/library/Display/Display.h @@ -79,7 +79,7 @@ void init_ressource_element(SDL_Renderer *renderer, ressources_t *textures); void apply_background(SDL_Renderer *renderer, SDL_Texture *texture, world_t *world, int parallax); /** - * \brief La fonction qui applique la texture \a texture sur le renderer \a renderer en fonction des données du sprite \a sprite + * \brief La fonction qui applique la texture \a texture sur le renderer \a renderer en fonction des données du sprite \a sprite (avec rotation) * * \param texture * \param renderer @@ -87,6 +87,15 @@ void apply_background(SDL_Renderer *renderer, SDL_Texture *texture, world_t *wor */ void apply_sprite(SDL_Renderer * renderer, SDL_Texture *texture, sprite_t *sprite, world_t *world); +/** + * @brief La fonction qui applique la texture \a texture sur le renderer \a renderer en fonction des données du sprite \a sprite (sans rotation) + * + * @param renderer + * @param texture + * @param sprite + * @param world + */ +void apply_sprite_fixed(SDL_Renderer * renderer, SDL_Texture *texture, sprite_t *sprite, world_t *world); /** * \brief La fonction qui applique la texture \a texture sur le renderer \a renderer en fonction des coordonnées \a x et \a y * @@ -130,11 +139,4 @@ void clean_textures(ressources_t *textures); */ void clean(SDL_Window *window, SDL_Renderer * renderer, ressources_t *textures, world_t * world); -/** - * \brief La fonction qui affiche le temps restant sur l'écran - * - * \param world - * \return int - */ -int timer_update_s(world_t *world); #endif \ No newline at end of file diff --git a/library/Display/Display.o b/library/Display/Display.o index b35f05eb6ba848349a94357fdb103c74407b09ba..0ed2735f9fe08a8f649598e2919051cb21dd5de3 100644 Binary files a/library/Display/Display.o and b/library/Display/Display.o differ diff --git a/library/World/world.h b/library/World/world.h index 80bc15556bdb4b2784765a0ca55030052f81091c..a38d3dc93042ff6dc626aa770684574a03d40940 100644 --- a/library/World/world.h +++ b/library/World/world.h @@ -42,6 +42,7 @@ struct world_s{ sprite_t *soleilBarre; sprite_t *soleil; sprite_t *air; + sprite_t *coins; int nb_murs; // Nombre de météorites int nb_lines_murs; // Nombre de lignes de météorites sprite_t *ligneArriver; @@ -50,10 +51,13 @@ struct world_s{ unsigned int startTimer; /*!< Timer de départ */ unsigned int timer; /*!< Timer de jeu */ char * str; // String affichant le temps sur le jeu + char * coins_str; + double angle; // Angle de rotation de la map int isFlipping; // Indique si l'on est en train de faire une rotation de l'écran et dans quelle sens (0 : non droite, 1 : vers la droite, -1 : vers la gauche, -2 : non gauche) bool isMenu; int money; + int money2; int parallax; bool invicibility; @@ -73,6 +77,20 @@ void update_data(world_t *world); int is_game_over(world_t *world); +/** + * @brief Detecte si le vaisseau va en dehors de l'écran + * + * @param world + */ +void outBorder(world_t *world); + +/** + * @brief Actualise le timer de jeu + * + * @param world + * @return int + */ +int timer_update_s(world_t *world); /** * \brief La fonction initialise les données du monde du jeu @@ -103,7 +121,7 @@ void flipScreen(world_t *world); * \param world Le monde * \param make_disappear Indique si l'on doit faire disparaître les sprites en cas de collision */ -void collide(sprite_t *sp1, sprite_t *sp2, world_t *world, int make_disappear); +void collide(sprite_t *sp1, sprite_t *sp2, world_t *world); /** diff --git a/library/utility/utility.c b/library/utility/utility.c index 74927a35b85c22d9bfdd1d9a1e3e092bd14b8260..492d747cf9b3e2d9e91b255de3007dcaf3ebf525 100644 --- a/library/utility/utility.c +++ b/library/utility/utility.c @@ -41,4 +41,13 @@ char **lirefile(char *filename, int *num_lines) { fclose(file); return lines; +} + +int number_of_numbers(int n){ + int count = 0; + while (n != 0){ + n /= 10; + count++; + } + return count; } \ No newline at end of file diff --git a/library/utility/utility.h b/library/utility/utility.h index 987adc67990829df6eda2344449aca1ce9356f3b..5d6567d9a9dedac457be3144ff8a079c51ab90f6 100644 --- a/library/utility/utility.h +++ b/library/utility/utility.h @@ -42,4 +42,5 @@ char * int_to_str(int n); char ** lirefile(char *filename, int *num_lines); +int number_of_numbers(int n); #endif \ No newline at end of file diff --git a/library/utility/utility.o b/library/utility/utility.o index 3ab3761c00d488f6924c02b7f94aa7aabcb2b55c..7133de4d09f644f9a7255773bb41e3367c335008 100644 Binary files a/library/utility/utility.o and b/library/utility/utility.o differ diff --git a/main.o b/main.o index 4a30a338e59dce2bf6d60e9958547885cb47d969..7cad5b701a1aa19e4758ce700959258e4203466f 100644 Binary files a/main.o and b/main.o differ diff --git a/spacecorridor.exe b/spacecorridor.exe index f0b6a6f8b6e396b4678948fe6c273ef38b75e782..6afffc9f3d6199f933ef132ba119c25e18470092 100644 Binary files a/spacecorridor.exe and b/spacecorridor.exe differ