diff --git a/library/Display/Display.c b/library/Display/Display.c index 5a97076ff4d4121eefa8933320e1bfd886099a04..63853f0e3c9ffb750117c79771e726340a72376f 100644 --- a/library/Display/Display.c +++ b/library/Display/Display.c @@ -32,9 +32,16 @@ void init_ressource_element(SDL_Renderer *renderer, ressources_t *textures){ textures->nb_init += 3; } +void apply_background_parralax(SDL_Renderer *renderer, SDL_Texture *texture, world_t *world, int parallax){ + if(texture != NULL){ + apply_texture(texture, renderer, 0, (int)(-1800+(world->parallax/parallax)), world->angle*180/M_PI); + + } +} + void apply_background(SDL_Renderer *renderer, SDL_Texture *texture, world_t *world, int parallax){ if(texture != NULL){ - apply_texture(texture, renderer, 0, -1800+world->parallax/parallax, world->angle*180/M_PI); + apply_texture(texture, renderer, 0, 0, world->angle*180/M_PI); } } @@ -96,44 +103,44 @@ void apply_walls(SDL_Renderer * renderer, SDL_Texture *texture, world_t *world, void refresh_graphics(SDL_Renderer *renderer, world_t *world,ressources_t *textures){ //on vide le renderer clear_renderer(renderer); - - //application des textures dans le renderer - apply_background(renderer, textures->background, world, 7); - apply_background(renderer, textures->background2, world, 3); - apply_background(renderer, textures->background3, world, 9); - if (world->isMenu == 0){ + ingame(renderer,world,textures); }else if(world -> isMenu==1){ + inmenu(renderer,world,textures); } - + update_screen(renderer); } void inmenu(SDL_Renderer *renderer, world_t *world,ressources_t *textures){ - apply_background(renderer, textures->bmenu, world); + apply_background(renderer, textures->bmenu, world, 0); } void ingame(SDL_Renderer *renderer, world_t *world,ressources_t *textures){ - if (world->ismenu == 0){ - apply_background(renderer, textures->background, world);//application des textures dans le renderer - apply_sprite(renderer, textures->ship, world->vaisseau, world); - apply_sprite(renderer, textures->finishLine, world->ligneArriver, world); - apply_walls(renderer, textures->meteorite, world, textures); - apply_sprite(renderer, textures->soleil, world->soleil, world); - apply_text(renderer, 10, 10, 100, 33, world->str, textures->font, textures->color); - 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); - printf("aaa"); - } + //application des textures dans le renderer + + // Backgrounds + apply_background_parralax(renderer, textures->background, world, 7); + apply_background_parralax(renderer, textures->background2, world, 3); + apply_background_parralax(renderer, textures->background3, world, 9); + + apply_sprite(renderer, textures->ship, world->vaisseau, world); + apply_sprite(renderer, textures->finishLine, world->ligneArriver, world); + apply_walls(renderer, textures->meteorite, world, textures); + apply_sprite(renderer, textures->soleil, world->soleil, world); + apply_text(renderer, 10, 10, 100, 33, world->temps_str, textures->font, textures->color); // Temps de jeu + 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); + // HUD + 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); + + // Update de l'écran update_screen(renderer); + } void clean(SDL_Window *window, SDL_Renderer * renderer, ressources_t *textures, world_t * world){ diff --git a/library/Display/Display.h b/library/Display/Display.h index 29d858f3584c7beebfba97eddc55bae64a5829e7..06a53fc4a1d25e64b6a63925ef24885268d44ba8 100644 --- a/library/Display/Display.h +++ b/library/Display/Display.h @@ -78,7 +78,7 @@ void init_ressource_element(SDL_Renderer *renderer, ressources_t *textures); * \param renderer le renderer * \param texture la texture liée au fond */ -void apply_background(SDL_Renderer *renderer, SDL_Texture *texture, world_t *world, int parallax); +void apply_background_parralax(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 (avec rotation) diff --git a/library/World/world.c b/library/World/world.c index c1687ac580067b7b499fb6b14c533bcfb2d47f15..0dfbb83895dfe291c00aa60c8743828d2a58925f 100644 --- a/library/World/world.c +++ b/library/World/world.c @@ -4,36 +4,40 @@ void update_data(world_t *world){ if (world->isMenu==0){ world->ligneArriver->y += (int)world->speed_h; + world->soleil->y += (int)world->speed_h; + + world->vaisseauMini->dy -= world->speed_h/(MAX_LINES*METEORITE_REAL_SIZE+700)*400; + world->vaisseauMini->y = (int)world->vaisseauMini->dy; + + outBorder(world); + + world->parallax += (int)world->speed_h; + update_walls(world); - if (isOverScreen(world->vaisseau)){ - if (world->vaisseau->x < 0) world->vaisseau->x = 0; - if (world->vaisseau->x + world->vaisseau->w > SCREEN_WIDTH) world->vaisseau->x = SCREEN_WIDTH - world->vaisseau->w; - if (world->vaisseau->y < 0) world->vaisseau->y = 0; - if (world->vaisseau->y + world->vaisseau->h > SCREEN_HEIGHT) world->vaisseau->y = SCREEN_HEIGHT - world->vaisseau->h; + world->money2 = world->money; + if (!world->invicibility){ + for(int i = 0; i < world->nb_murs; i++){ + collide(world->vaisseau, world->murs[i], world); + } } - for(int i = 0; i < world->nb_murs; i++){ - collide(world->vaisseau, world->murs[i], world, 0); + collide(world->vaisseau, world->ligneArriver, world); + if (timer_update_s(world) != 0){ + world->temps_str[0] = '\0'; + world->temps_str = strcats(world->temps_str, 3, "temps: ",int_to_str((int)world->timer/1000), "s"); } - collide(world->vaisseau, world->ligneArriver, world, 1); - allEvents(world); - - world->timer = SDL_GetTicks(); + world->timer = SDL_GetTicks() - world->startTimer;; + }else if(world->isMenu == 1){ + world->startTimer = SDL_GetTicks(); } } - -int is_game_over(world_t *world){ - return world->gameover; -} - - void init_data(world_t * world){ //on n'est pas à la fin du jeu world->gameover = 0; world->speed_h = (float)INITIAL_SPEED; init_walls(world); - world->ligneArriver = init_sprite(world->ligneArriver, 0, -world->nb_lines_murs*METEORITE_SIZE-30 , SCREEN_WIDTH, FINISH_LINE_HEIGHT, 'z'); + world->ligneArriver = init_sprite(world->ligneArriver, 0, -world->nb_lines_murs*METEORITE_SIZE-30 , SCREEN_WIDTH, FINISH_LINE_HEIGHT, 'z', 0); InitMenu(world); print_sprite(world->vaisseau); // Initialisation du vaisseau @@ -48,9 +52,8 @@ void init_data(world_t * world){ world->vaisseauMini->y = SCREEN_HEIGHT - (110); world->vaisseauMini->dy = SCREEN_HEIGHT - (110); - world->startTimer = SDL_GetTicks(); world->timer = SDL_GetTicks(); - world->str = malloc(sizeof(char)*100); // Allocation de la mémoire pour le string temps + world->temps_str = malloc(sizeof(char)*100); // Allocation de la mémoire pour le string temps world->coins_str = malloc(sizeof(char)*100); // Allocation de la mémoire pour le string coins @@ -63,48 +66,19 @@ void init_data(world_t * world){ world->mouseX = 0; world->mouseY = 0; - world->isMenu = false; world->money = 0; world->parallax = 0; world->invicibility = false; } -void update_data(world_t *world){ - if (!world->isMenu){ - world->ligneArriver->y += (int)world->speed_h; - world->soleil->y += (int)world->speed_h; - - world->vaisseauMini->dy -= world->speed_h/(MAX_LINES*METEORITE_REAL_SIZE+700)*400; - world->vaisseauMini->y = (int)world->vaisseauMini->dy; - - outBorder(world); - world->parallax += (int)world->speed_h; - update_walls(world); - world->money2 = world->money; - if (!world->invicibility){ - for(int i = 0; i < world->nb_murs; i++){ - collide(world->vaisseau, world->murs[i], 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"); - } - collide(world->vaisseau, world->ligneArriver, world); // Collision avec la ligne d'arriver - allEvents(world); - world->timer = SDL_GetTicks(); - } -} void outBorder(world_t *world){ if (isOverScreen(world->vaisseau)){ - if (world->vaisseau->x < 0) world->vaisseau->x = 0; - if (world->vaisseau->x + world->vaisseau->w > SCREEN_WIDTH) world->vaisseau->x = SCREEN_WIDTH - world->vaisseau->w; - if (world->vaisseau->y < 0) world->vaisseau->y = 0; - if (world->vaisseau->y + world->vaisseau->h > SCREEN_HEIGHT) world->vaisseau->y = SCREEN_HEIGHT - world->vaisseau->h; + if (world->vaisseau->x < 0) world->vaisseau->x = 0; + if (world->vaisseau->x + world->vaisseau->w > SCREEN_WIDTH) world->vaisseau->x = SCREEN_WIDTH - world->vaisseau->w; + if (world->vaisseau->y < 0) world->vaisseau->y = 0; + if (world->vaisseau->y + world->vaisseau->h > SCREEN_HEIGHT) world->vaisseau->y = SCREEN_HEIGHT - world->vaisseau->h; } } @@ -113,8 +87,8 @@ int is_game_over(world_t *world){ } int timer_update_s(world_t *world){ - if (world->timer%1000 <= 110|| world->timer%1000 >= 985){ - return world->timer%1000; + if ((world->timer)%1000 <= 110|| (world->timer)%1000 >= 985){ + return (world->timer)%1000; } return 0; } @@ -216,7 +190,7 @@ void clean_data(world_t *world){ free(world->vaisseau); free(world->ligneArriver); free(world->murs); - free(world->str); + free(world->temps_str); free(world->vaisseauMini); free(world->soleilBarre); free(world->soleil); @@ -224,6 +198,10 @@ void clean_data(world_t *world){ free(world->coins); free(world->coins_str); free(world->air); + free(world->play); + free(world->exit); + free(world->magasin); + free(world->sound); printf("clean_data"); } \ No newline at end of file diff --git a/library/World/world.h b/library/World/world.h index 18c176ef85c655795048c82f106f83d99a6dc0dd..c32bb80a95f7feaff56de7e2326b4ef8ec3439bd 100644 --- a/library/World/world.h +++ b/library/World/world.h @@ -57,7 +57,7 @@ struct world_s{ float speed_h; /*!< Vitesse de déplacement horizontal des éléments du jeu */ unsigned int startTimer; /*!< Timer de départ */ unsigned int timer; /*!< Timer de jeu */ - char * str; // String affichant le temps sur le jeu + char * temps_str; // String affichant le temps sur le jeu char * coins_str; double angle; // Angle de rotation de la map @@ -66,7 +66,6 @@ struct world_s{ int mouseX; int mouseY; - bool isMenu; int money; int money2; diff --git a/library/menu/menu.o b/library/menu/menu.o index b6cbc3e665f91e49dc9a7db7cdebb2712ead74c7..84c315fce363b5059bff8e7a368ef00fceb3c935 100644 Binary files a/library/menu/menu.o and b/library/menu/menu.o differ diff --git a/main.c b/main.c index 7f7045d4e68a67cf9acb39f546a1d698f4821948..e64b1209eb2c848c89b2204d623ce3af24387ab3 100644 --- a/main.c +++ b/main.c @@ -107,7 +107,7 @@ void init(SDL_Window **window, SDL_Renderer ** renderer, ressources_t *textures, // Initialisation du ttf init_ttf(); init_ressource(*renderer,textures); - + } @@ -133,13 +133,13 @@ int main( int argc, char* args[] ) frameTime = SDL_GetTicks() - ticks; //gestion des évènements handle_events(&event,&world); - + //mise à jour des données liée à la physique du monde update_data(&world); //rafraichissement de l'écran refresh_graphics(renderer,&world,&textures); - + if (frameTime < 16) { SDL_Delay(16 - frameTime); // 16 ms = 60 fps } diff --git a/sdl2-ttf-light.o b/sdl2-ttf-light.o index e6dbdb53a08901764f1103130b7cfe977b7bcc21..f8e682ac4d9855b2e3eea678d9470fab1084a9f1 100644 Binary files a/sdl2-ttf-light.o and b/sdl2-ttf-light.o differ