From ea839c0ce9ae8bce798e620bdc9a7b87e2e8022d Mon Sep 17 00:00:00 2001 From: SmallIshMink <mattheo.m10@gmail.com> Date: Sat, 13 May 2023 14:03:38 +0200 Subject: [PATCH] =?UTF-8?q?Mise=20a=20jour=20de=20l'heure=20en=20fonction?= =?UTF-8?q?=20du=20d=C3=A9but=20r=C3=A9el=20du=20jeu?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/Display/Display.c | 59 ++++++++++++++----------- library/Display/Display.h | 2 +- library/World/world.c | 90 ++++++++++++++------------------------ library/World/world.h | 3 +- library/menu/menu.o | Bin 897 -> 913 bytes main.c | 6 +-- sdl2-ttf-light.o | Bin 2077 -> 2093 bytes 7 files changed, 72 insertions(+), 88 deletions(-) diff --git a/library/Display/Display.c b/library/Display/Display.c index 5a97076..63853f0 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 29d858f..06a53fc 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 c1687ac..0dfbb83 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 18c176e..c32bb80 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 GIT binary patch delta 80 zcmZo<pUBRc(#FOB0%{XEl^GvQ)Sb`xYT{XWMuUlOPpSl^mRag3IF)ARlqe)sD)<IR i1{*096y;~7CYNX`7#isr=^1Q3#hAm$s6E-7*$V*9*cdqg delta 64 zcmbQp-pJ0G(#FOB0%8+6l^HKg)Sb_GYvNgXMumxQPl~wvg=#7o8tED78Gw|4@#b5M MIgE@#liiuU01>_qcmMzZ diff --git a/main.c b/main.c index 7f7045d..e64b120 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 GIT binary patch delta 117 zcmbO$uvUOGrH!2d1pZ9qRAyW;QTI5b$HcGlj0T%U8D$w61t%LbMezuhs3^PuDVo49 zFnK1^Q<b39GD{r=r_#)v5{0Bn1>fMvU?YWsqWrAX<PuE<LnA#SJ%i1Yn5!6>7#KG5 Sv1TzcYEN_&-Q364&j<iiTOZW` delta 101 zcmZ20Fjs&xrH!2d1l~;KRA!tpQTI5b#l)}jj0&4Y8D$w6H76T0Me%5ss3^PuDVo5q wF?lA_QxSK+P)!9xBRwNM1CTHnZ(hV)#mJ<WyjhMli;+=iqNC{Md2IcR0Q1!s{Qv*} -- GitLab