Skip to content
Snippets Groups Projects
Commit 4be663c9 authored by SmallIshMink's avatar SmallIshMink
Browse files

Ramassage des pieces, ajout a un compteur, affichage du compteurs (tout fonctionnel)

parent 74233f49
No related branches found
No related tags found
No related merge requests found
......@@ -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);
......
......@@ -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
No preview for this file type
......@@ -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);
/**
......
......@@ -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
......@@ -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
No preview for this file type
No preview for this file type
No preview for this file type
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment