diff --git a/.vscode/settings.json b/.vscode/settings.json index cc134d0ef702c058524988399a29a66bbe4794c1..f21fe1c75010dd90b3c68b9e10f397eb11a63f1c 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,5 +1,6 @@ { "files.associations": { - "cstdlib": "c" + "cstdlib": "c", + "system_error": "c" } } \ No newline at end of file diff --git a/Ressources/choix.bmp b/Ressources/choix.bmp new file mode 100644 index 0000000000000000000000000000000000000000..e5d8d7a584a62683a064ae58a648d91b16b4cc17 Binary files /dev/null and b/Ressources/choix.bmp differ diff --git a/Ressources/choix.kra b/Ressources/choix.kra new file mode 100644 index 0000000000000000000000000000000000000000..44d21d54ad9bd56233a600de6d5b7200f021ffc2 Binary files /dev/null and b/Ressources/choix.kra differ diff --git a/constantes.h b/constantes.h index 567152a4b32c99ab6a50023e0d1c77dcf87e0aa9..f4705f612525f2c6e66e91a82157baf9337e453c 100644 --- a/constantes.h +++ b/constantes.h @@ -49,11 +49,6 @@ enum cuisson {INCONCERNE, FRIGO, SALE, PROPRE, CUIT, CRU, JETE}; */ #define NOM_FRIGO 'F' -/** - * @brief Nombre d'ingrédient disponible en cuisine - */ -#define INGREDIENT_DISPO 5 - /** * @brief Nom des fourneaux * diff --git a/graphisme.c b/graphisme.c index c3f40d29c0a67fd8a1fadbb49c6550e9737813a6..553dcfd6e38b2a380c1a055f5211f0a68b50d140 100644 --- a/graphisme.c +++ b/graphisme.c @@ -39,7 +39,31 @@ void clean_textures(textures_t *textures){ if (textures->ingredient != NULL){ SDL_DestroyTexture(textures->ingredient); } - if (textures->ingredient != NULL){ + if (textures->horloge != NULL){ + SDL_DestroyTexture(textures->horloge); + } + if (textures->message != NULL){ + SDL_DestroyTexture(textures->message); + } + if (textures->points != NULL){ + SDL_DestroyTexture(textures->points); + } + if (textures->choix != NULL){ + SDL_DestroyTexture(textures->choix); + } + if (textures->titre != NULL){ + SDL_DestroyTexture(textures->titre); + } + if (textures->option1 != NULL){ + SDL_DestroyTexture(textures->option1); + } + if (textures->option2 != NULL){ + SDL_DestroyTexture(textures->option2); + } + if (textures->option3 != NULL){ + SDL_DestroyTexture(textures->option3); + } + if (textures->police != NULL){ TTF_CloseFont(textures->police); } } @@ -53,6 +77,7 @@ void nettoyage_graphisme (SDL_Renderer *renderer, textures_t *textures, SDL_Wind void init_textures (SDL_Renderer *renderer, textures_t *textures, TTF_Font *font){ Uint8 r = 255, g = 255, b = 255; textures->menu = charger_image("Ressources/menu.bmp", renderer); + textures->choix = charger_image_transparente("Ressources/choix.bmp", renderer, r, g, b); textures->fond = charger_image("Ressources/fond1.bmp", renderer); textures->joueur = charger_image ("Ressources/joueur.bmp", renderer); textures->comptoire = charger_image ("Ressources/compt0.bmp", renderer); @@ -63,14 +88,18 @@ void init_textures (SDL_Renderer *renderer, textures_t *textures, TTF_Font *font textures->lavabo = charger_image ("Ressources/lavabo0.bmp", renderer); textures->ingredient = charger_image_transparente("Ressources/ingredient.bmp", renderer, r, g, b); textures->police = font; - - // SDL_Color color = { 255, 0, 255 }; - //... = charger_texte ("Score : ", renderer, font, color); + textures->points = NULL; + textures->horloge = NULL; + textures->message = NULL; + textures->titre = NULL; + textures->option1 = NULL; + textures->option2 = NULL; + textures->option3 = NULL; } void apply_graphics (SDL_Renderer *renderer, textures_t *textures, world_t *world){ //maj les texture selon la position des éléments différents - //Affichage du fond + //Affichage du fond if(textures->fond != NULL){ SDL_RenderCopy(renderer, textures->fond, NULL, NULL); } @@ -81,6 +110,7 @@ void apply_graphics (SDL_Renderer *renderer, textures_t *textures, world_t *worl apply_mobilier (renderer, textures, world); apply_ingredients (renderer, textures, world->etat_stocks.commande_actuelle, world->etat_stocks.nb); apply_texte (renderer, world, textures); + } void apply_mobilier (SDL_Renderer* renderer, textures_t* textures, world_t* world){ @@ -192,21 +222,19 @@ void apply_texte (SDL_Renderer* renderer, world_t* world, textures_t* textures){ SDL_Rect zone_message = create_SDL_rect(20, 550, 75, 50); SDL_Rect zone_score; SDL_Rect zone_horloge = create_SDL_rect(SCREEN_WIDTH/2, 5, 75, 50); - SDL_Texture* message; - SDL_Texture* points; - SDL_Texture* horloge; + //Couleur du texte SDL_Color color = { 255, 255, 0, 0 }; char score_j[10]; char buffer[7]; //Traduction du temps restant en string: - sprintf(buffer, "%d", temps_restant(world)); + sprintf(buffer, "%d", temps_restant(world->temps_debut_jeu)); if (buffer[0] == '1'){ buffer[3] = '\0'; }else{ buffer[2] = '\0'; } - + //printf("timer: %s \n", buffer); //Concernant le score if (get_score(world)<100){ zone_score = create_SDL_rect(90, 555, 40, 40); @@ -217,16 +245,55 @@ void apply_texte (SDL_Renderer* renderer, world_t* world, textures_t* textures){ } //affichage en deux partie de score et de la valeur du score, et du timer - horloge = charger_texte(buffer, renderer, textures->police, color); - message = charger_texte("Score : ", renderer, textures->police, color); + textures->horloge = charger_texte(buffer, renderer, textures->police, color); + textures->message = charger_texte("Score : ", renderer, textures->police, color); sprintf(score_j, " %d", world->score); //Nécessaire pour afficher le score -- limite le nombre de points max! - points = charger_texte(score_j, renderer, textures->police, color); - render_texte(renderer, zone_message, message); - render_texte(renderer, zone_score, points); - render_texte(renderer, zone_horloge, horloge); + textures->points = charger_texte(score_j, renderer, textures->police, color); + render_texte(renderer, zone_message, textures->message); + render_texte(renderer, zone_score, textures->points); + render_texte(renderer, zone_horloge, textures->horloge); } } +void apply_graphics_menu (SDL_Renderer *renderer, textures_t *textures, menu_t* menu){ + //Affichage du menu + if (textures->menu !=NULL){ + //Affichage du fond du menu + SDL_RenderCopy(renderer, textures->menu, NULL, NULL); + } + + if (textures->choix !=NULL){ + //Affichage de la glyphe + SDL_RenderCopy(renderer, textures->choix, NULL, &menu->glyphe); + } + + //Texte du menu + if (textures->police !=NULL){ + //Couleur du texte + SDL_Color color = { 255, 255, 0, 0 }; + + //Textes à afficher + char title[15] = TITRE; + char begin[20] = "Nouvelle partie"; + char continuer[20] = "Continuer la partie"; + char quit[10] = "Quitter"; + + //Génération des textures + textures->titre = charger_texte(title, renderer, textures->police, color); + textures->option1 = charger_texte(begin, renderer, textures->police, color); + textures->option2 = charger_texte(continuer, renderer, textures->police, color); + textures->option3 = charger_texte(quit, renderer, textures->police, color); + + //afficher les textes + render_texte(renderer, menu->titre_jeu, textures->titre); + render_texte(renderer, menu->nouvelle_partie, textures->option1); + render_texte(renderer, menu->charger, textures->option2); + render_texte(renderer, menu->quitter, textures->option3); + + } +} + + SDL_Rect create_SDL_rect_from_texture (SDL_Texture * texture, int x, int y, int h, int w){ //Permet de créer un SDL_rect retournant la texture de la taille de la texture (SOURCE) int largeur; @@ -287,11 +354,3 @@ SDL_Texture* charger_texte (const char* message, SDL_Renderer* renderer, TTF_Fon void render_texte(SDL_Renderer *renderer, SDL_Rect zone_texte, SDL_Texture* texte){ SDL_RenderCopy(renderer, texte, NULL, &zone_texte); } - -/* -TTF_Font *TTF_OpenFont(const char *file, int size) ; //charge la police et applique la taille du texte -// Écrire le texte sur une surface SDL -SDL_Surface *TTF_RenderText_Solid(TTF_Font *font, const char *text, SDL_Color fg) ; -// Fermer la police -void TTF_CloseFont(TTF_Font *font) ; -*/ \ No newline at end of file diff --git a/graphisme.h b/graphisme.h index 2f28fe0af29481bd4fc9f976fd5911433e7fd907..aac73657c0518a61a8684bec5966adb2c24eb162 100644 --- a/graphisme.h +++ b/graphisme.h @@ -14,16 +14,25 @@ struct textures_s{ SDL_Texture* menu; /*!< Texture liée à l'image du fond du menu. */ + SDL_Texture* choix; /*!< Texture liée au choix du joueur dans le menu.*/ SDL_Texture* fond; /*!< Texture liée à l'image du fond de l'écran. */ - SDL_Texture* joueur ; /* Texture du joueur*/ - SDL_Texture* comptoire ; /*< Texture des comptoires */ - SDL_Texture* envoi ; /*< Tableau de texture de la zone d'envoi */ - SDL_Texture* four ; /*< Tableau de texture du four */ - SDL_Texture* lavabo ; /*< Tableau de texture du frigo */ - SDL_Texture* poubelle ; /*< Texture de la poubelle */ - SDL_Texture* frigo ; /*< Tableau de texture du frigo */ - SDL_Texture* ingredient ; /*< textures des ingredients */ + SDL_Texture* joueur ; /*!< Texture du joueur*/ + SDL_Texture* comptoire ; /*!< Texture des comptoires */ + SDL_Texture* envoi ; /*!<Tableau de texture de la zone d'envoi */ + SDL_Texture* four ; /*!<Tableau de texture du four */ + SDL_Texture* lavabo ; /*!<Tableau de texture du frigo */ + SDL_Texture* poubelle ; /*!<Texture de la poubelle */ + SDL_Texture* frigo ; /*!<Tableau de texture du frigo */ + SDL_Texture* ingredient ; /*!<textures des ingredients */ TTF_Font* police; /*Texture de la police d'écriture*/ + SDL_Texture* message; /*!<textures du message score */ + SDL_Texture* points; /*!<textures du texte du score */ + SDL_Texture* horloge; /*!<textures du texte de l'horloge */ + SDL_Texture* titre; /*!<Texture du texte du titre */ + SDL_Texture* option1; /*!<Texture du texte de l'option 1 */ + SDL_Texture* option2; /*!<Texture du texte de l'option 2 */ + SDL_Texture* option3; /*!<Texture du texte de l'option 3 */ + }; /** * \brief Type qui correspond aux textures du jeu @@ -109,6 +118,15 @@ void apply_texte (SDL_Renderer* renderer, world_t* world, textures_t* textures); */ void apply_ingredients (SDL_Renderer* renderer, textures_t* textures, sprite_t* ingredients, int taille_commande); +/** + * @brief Applique les éléments du menu sur l'écran + * + * @param renderer + * @param textures textures du jeu + * @param menu données du jeu + */ +void apply_graphics_menu (SDL_Renderer *renderer, textures_t *textures, menu_t* menu); + /** * @brief Créer un objet SDL_rect * @@ -148,5 +166,4 @@ SDL_Rect create_SDL_rect_from_sprite (sprite_t * sprite); * @param textures textures disponibles */ void update_graphics (SDL_Renderer *renderer, world_t *world, textures_t *textures); - #endif \ No newline at end of file diff --git a/logique.c b/logique.c index 1b2628a058066e4a2b41f96a535de5a538e988a8..fa509bc15286b8810db04e2b13fc48fcf1c40a71 100644 --- a/logique.c +++ b/logique.c @@ -266,9 +266,9 @@ void calcul_score (world_t* world, sprite_t* ingredient){ } } -void temps_depassee (world_t* world){ +void temps_depassee (world_t* world, Uint32 temps_debut_jeu){ //Retourne un indicateur si la partie peut continuer ou non - if (SDL_GetTicks() > TEMPS_DE_PARTIE){ + if (temps_restant(temps_debut_jeu) ==0){ world->gameover = 1; }else{ if (estFini(world)==1){ @@ -280,12 +280,12 @@ void temps_depassee (world_t* world){ } } -int temps_restant (){ +int temps_restant (Uint32 temps_debut_jeu){ //Retourne le temps restant avant la fin de partie Uint32 time = SDL_GetTicks(); int temps_restant; if (time < INT_MAX){ - temps_restant = (int) (TEMPS_DE_PARTIE - time); + temps_restant = (int) ((TEMPS_DE_PARTIE + temps_debut_jeu) - (time )); if (temps_restant <=0) temps_restant = 0; } return temps_restant; diff --git a/logique.h b/logique.h index ed06f1f4067df0db971b638ef4c8838f9f2555ae..29edd362e4185173a1202093bdcfcfd267c5c429 100644 --- a/logique.h +++ b/logique.h @@ -134,15 +134,16 @@ void calcul_score (world_t* world, sprite_t* ingredient); * @brief Indique si il est temps de terminer la partie * * @param world Données du monde + * @param temps_debut_jeu Moment à partir duquel le jeu commence réellement */ -void temps_depassee (world_t* world); +void temps_depassee (world_t* world, Uint32 temps_debut_jeu); /** * @brief Temps restant avant la fin de partie * - * @param world + * @param temps_debut_jeu Moment à partir duquel le jeu commence réellement * @return int temps restant */ -int temps_restant (); +int temps_restant (Uint32 temps_debut_jeu); #endif \ No newline at end of file diff --git a/main.c b/main.c index a4eaeee149b235de601d458f66e03665dad79c35..f401dbde9fe6f54ee96f712198d56edc357fd657 100644 --- a/main.c +++ b/main.c @@ -26,7 +26,7 @@ textures_t textures; SDL_Window *windows; SDL_Renderer *ecran; SDL_Event evenements; -TTF_Font *font = TTF_OpenFont("Ressources/arial.ttf", 14); +TTF_Font *font = TTF_OpenFont("Ressources/arial.ttf", 50); windows = SDL_CreateWindow(TITRE, 100, 100, SCREEN_WIDTH, SCREEN_HEIGHT,SDL_WINDOW_OPENGL); @@ -45,23 +45,25 @@ init_textures(ecran, &textures, font); //menu init_menu(&menu); -menu_event(&evenements, &menu); - +//boucle menu +while (sortir_menu(&menu) ==0){ + SDL_RenderClear(ecran); + apply_graphics_menu(ecran, &textures, &menu); + menu_event(&evenements, &menu, &world); + SDL_RenderPresent(ecran); +} //boucle de jeu while (estFini(&world)==0){ - SDL_RenderClear(ecran); // permet de vider le Renderer (ecran) de toutes les textures - //Gestion des évenements (entrées joueurs) suivi de la mise à jour des données (collisions etc) et actualisation graphique + temps_depassee(&world, world.temps_debut_jeu); gestion_events(&evenements, &world); update_data(&world); update_graphics(ecran, &world, &textures); - temps_depassee(&world); - SDL_RenderPresent(ecran); // Récupère les infos actualisés de render et les affiches - /*if (world.gameover == 1){ - SDL_Delay(10000); - }*/ + if (world.gameover == 1){ + SDL_Delay(1000); + } } SDL_Delay(150); diff --git a/menu.c b/menu.c index 4235629b10b783351befb7ff3f6e10488d069253..bd831f6397d0fd3fd299bfb2ffbff3ff0cab3a3f 100644 --- a/menu.c +++ b/menu.c @@ -11,47 +11,111 @@ void init_menu (menu_t *menu){ //initialise le menu - menu->gameover = 0; + SDL_Rect option1= {50, 300, 200, 50}; + SDL_Rect option2= {50, 360, 250, 50}; + SDL_Rect option3= {50, 420, 100, 50}; + SDL_Rect pos_titre= {SCREEN_WIDTH/2 -100, 20, 200, 100}; + SDL_Rect pos_glyphe = {20, 310, PLAT_SIZE, PLAT_SIZE}; menu->quitter_menu = 0; menu->choix = 0; + menu->nouvelle_partie = option1; + menu->charger = option2; + menu->quitter = option3; + menu->titre_jeu = pos_titre; + menu->glyphe = pos_glyphe; } void menu_event(SDL_Event *event, menu_t *menu, world_t *world){ //Gère les évenements liés au menu - while (menu->quitter_menu ==0){ - SDL_WaitEvent(event); - switch(event->type){ - case SDL_QUIT: - menu->gameover = 1; - menu->quitter_menu = 1; - break; + SDL_WaitEvent(event); + switch(event->type){ + case SDL_QUIT: + world->gameover = 1; + quitterMenu(menu); + break; + + case SDL_KEYDOWN: + switch(event->key.keysym.sym){ + case SDLK_ESCAPE: + //Si on appuie sur escape on quitte le jeu + world->gameover = 1; + quitterMenu(menu); + break; + + case SDLK_UP: + //Déplacement dans les menus + menu->choix--; + if (menu->choix <0) menu->choix = 0; + modif_position_glyphe(menu); + break; + + case SDLK_DOWN: + //Déplacement dans les menus + menu->choix++; + if (menu->choix >=3) menu->choix = 2; + modif_position_glyphe(menu); + break; - case SDL_KEYDOWN: - switch(event->key.keysym.sym){ - case SDLK_ESCAPE: - //Si on appuie sur escape on quitte le jeu - menu->gameover = 1; - menu->quitter_menu = 1; - break; - - case SDLK_UP: - //Déplacement dans les menus - menu->choix--; - if (menu->choix <0) menu->choix = 0; - break; - - case SDLK_DOWN: - //Déplacement dans les menus - menu->choix++; - if (menu->choix >4) menu->choix = 4; - break; - - case SDLK_SPACE: - //Valide le choix et on quitte le menu - menu->quitter_menu = 1; - break; - - } + case SDLK_SPACE: + //Valide le choix et on quitte le menu + switch (get_choix(menu)){ + case 0: + quitterMenu(menu); + world->temps_debut_jeu = SDL_GetTicks(); + break; + case 1: + break; + default: + world->gameover = 1; + quitterMenu(menu); + break; + } + break; + + case SDLK_RETURN: + //Valide le choix et on quitte le menu + switch (get_choix(menu)){ + case 0: + quitterMenu(menu); + world->temps_debut_jeu = SDL_GetTicks(); + break; + case 1: + break; + default: + world->gameover = 1; + quitterMenu(menu); + break; + } + break; } } + } + +int get_choix (menu_t* menu){ + return menu->choix; +} + +int sortir_menu (menu_t* menu){ + return menu->quitter_menu; +} + +void quitterMenu(menu_t* menu){ + menu->quitter_menu = 1; +} + +void modif_position_glyphe (menu_t* menu){ + switch(get_choix(menu)){ + case 0: + menu->glyphe.y = 315; + break; + + case 1: + menu->glyphe.y = 375; + break; + + default: + menu->glyphe.y = 435; + break; + } +} \ No newline at end of file diff --git a/menu.h b/menu.h index 18e7fde1be92c2670c50b0900216560749fc3895..dfab4a3a49af276df37fb37102d167fb9895d2d0 100644 --- a/menu.h +++ b/menu.h @@ -13,10 +13,13 @@ #include "stocks.h" struct menu_s{ - int gameover; /*!< Champ indiquant si l'on est à la fin du jeu */ int quitter_menu; /*!< Champ indiquant si l'on sort du menu */ int choix; /*!< Champ indiquant le choix du joueur */ - sprite_t texte; /*!< Sprite du joueur */ + SDL_Rect titre_jeu; /*!< Position et dimension du titre */ + SDL_Rect nouvelle_partie; /*!< Position et dimension de l'option 'nouvelle partie' */ + SDL_Rect charger; /*!< Position et dimension de l'option de chargement d'une partie pré-existante */ + SDL_Rect quitter; /*!< Position et dimension de l'option n°3 (exit) */ + SDL_Rect glyphe; /*!< Position et dimension de l'indicateur du choix actuel du joueur */ }; /** * \brief Type qui correspond aux données du monde @@ -38,5 +41,34 @@ void init_menu (menu_t *menu); */ void menu_event(SDL_Event *event, menu_t *menu, world_t *world); +/** + * @brief l'option du menu choisie + * + * @param menu + * @return int valeur de l'option choisie + */ +int get_choix (menu_t* menu); + +/** + * @brief état de sortie du menu + * + * @param menu + * @return int 0 si on continue, 1 si on quitte le menu + */ +int sortir_menu (menu_t* menu); + +/** + * @brief Enclenche la sortie de la boucle du menu + * + * @param menu + */ +void quitterMenu(menu_t* menu); + +/** + * @brief Déplace l'indicateur du choix du joueur + * + * @param menu + */ +void modif_position_glyphe (menu_t* menu); #endif \ No newline at end of file diff --git a/stocks.h b/stocks.h index c3eda18d88eafb910f36492f9434b0cfd58fe619..849332276cbaeb15e3ff7999ef9c1477969acd8e 100644 --- a/stocks.h +++ b/stocks.h @@ -38,6 +38,7 @@ struct world_s{ stock_t etat_stocks; /*!< Structure gérant les stocks et le score*/ int compteur_plats; /*!< Nombre de plats étant sorti de l'écran */ int attente; /*!< Compte le nombre de tours avant la fin de la partie*/ + Uint32 temps_debut_jeu; /*!< Moment à partir duquel le jeu commence réellement*/ char** map; /*!< tableau de caractère correspondant à l'état de la map actuel */ }; /**