Skip to content
Snippets Groups Projects
Commit b3729235 authored by vautrin33u's avatar vautrin33u
Browse files

Affichage du score -- début de travail sur menu et règles

parent 2bc83552
No related branches found
No related tags found
No related merge requests found
File added
Ressources/menu.bmp

1.37 MiB

File added
This diff is collapsed.
...@@ -9,6 +9,9 @@ ...@@ -9,6 +9,9 @@
#include "graphisme.h" #include "graphisme.h"
void clean_textures(textures_t *textures){ void clean_textures(textures_t *textures){
if (textures->menu != NULL){
SDL_DestroyTexture(textures->menu);
}
if (textures->joueur != NULL){ if (textures->joueur != NULL){
SDL_DestroyTexture(textures->joueur); SDL_DestroyTexture(textures->joueur);
} }
...@@ -18,7 +21,6 @@ void clean_textures(textures_t *textures){ ...@@ -18,7 +21,6 @@ void clean_textures(textures_t *textures){
if (textures->comptoire != NULL){ if (textures->comptoire != NULL){
SDL_DestroyTexture(textures->comptoire); SDL_DestroyTexture(textures->comptoire);
} }
if (textures->envoi[0] != NULL){ if (textures->envoi[0] != NULL){
SDL_DestroyTexture(textures->envoi[0]); SDL_DestroyTexture(textures->envoi[0]);
} }
...@@ -37,6 +39,9 @@ void clean_textures(textures_t *textures){ ...@@ -37,6 +39,9 @@ void clean_textures(textures_t *textures){
if (textures->ingredient != NULL){ if (textures->ingredient != NULL){
SDL_DestroyTexture(textures->ingredient); SDL_DestroyTexture(textures->ingredient);
} }
if (textures->ingredient != NULL){
TTF_CloseFont(textures->police);
}
} }
void nettoyage_graphisme (SDL_Renderer *renderer, textures_t *textures, SDL_Window *fenetre){ void nettoyage_graphisme (SDL_Renderer *renderer, textures_t *textures, SDL_Window *fenetre){
...@@ -47,6 +52,7 @@ void nettoyage_graphisme (SDL_Renderer *renderer, textures_t *textures, SDL_Wind ...@@ -47,6 +52,7 @@ void nettoyage_graphisme (SDL_Renderer *renderer, textures_t *textures, SDL_Wind
void init_textures (SDL_Renderer *renderer, textures_t *textures, TTF_Font *font){ void init_textures (SDL_Renderer *renderer, textures_t *textures, TTF_Font *font){
Uint8 r = 255, g = 255, b = 255; Uint8 r = 255, g = 255, b = 255;
textures->menu = charger_image("Ressources/menu.bmp", renderer);
textures->fond = charger_image("Ressources/fond1.bmp", renderer); textures->fond = charger_image("Ressources/fond1.bmp", renderer);
textures->joueur = charger_image ("Ressources/joueur.bmp", renderer); textures->joueur = charger_image ("Ressources/joueur.bmp", renderer);
textures->comptoire = charger_image ("Ressources/compt0.bmp", renderer); textures->comptoire = charger_image ("Ressources/compt0.bmp", renderer);
...@@ -56,6 +62,7 @@ void init_textures (SDL_Renderer *renderer, textures_t *textures, TTF_Font *font ...@@ -56,6 +62,7 @@ void init_textures (SDL_Renderer *renderer, textures_t *textures, TTF_Font *font
textures->poubelle = charger_image ("Ressources/trash0.bmp", renderer); textures->poubelle = charger_image ("Ressources/trash0.bmp", renderer);
textures->lavabo[0] = charger_image ("Ressources/lavabo0.bmp", renderer); textures->lavabo[0] = charger_image ("Ressources/lavabo0.bmp", renderer);
textures->ingredient = charger_image_transparente("Ressources/ingredient.bmp", renderer, r, g, b); textures->ingredient = charger_image_transparente("Ressources/ingredient.bmp", renderer, r, g, b);
textures->police = font;
// SDL_Color color = { 255, 0, 255 }; // SDL_Color color = { 255, 0, 255 };
//... = charger_texte ("Score : ", renderer, font, color); //... = charger_texte ("Score : ", renderer, font, color);
...@@ -63,28 +70,35 @@ void init_textures (SDL_Renderer *renderer, textures_t *textures, TTF_Font *font ...@@ -63,28 +70,35 @@ void init_textures (SDL_Renderer *renderer, textures_t *textures, TTF_Font *font
void apply_graphics (SDL_Renderer *renderer, textures_t *textures, world_t *world){ void apply_graphics (SDL_Renderer *renderer, textures_t *textures, world_t *world){
//maj les texture selon la position des éléments différents //maj les texture selon la position des éléments différents
//Affichage du fond
if(textures->fond != NULL){ if(textures->fond != NULL){
SDL_RenderCopy(renderer, textures->fond, NULL, NULL); SDL_RenderCopy(renderer, textures->fond, NULL, NULL);
} }
//Affichage du joueur
if (textures->joueur !=NULL && est_visible(&world->joueur)){ if (textures->joueur !=NULL && est_visible(&world->joueur)){
SDL_RenderCopy(renderer, textures->joueur, NULL, &world->joueur.rect); SDL_RenderCopy(renderer, textures->joueur, NULL, &world->joueur.rect);
} }
//Affichage de la poubelle
if (textures->poubelle !=NULL && est_visible(&world->poubelle)){ if (textures->poubelle !=NULL && est_visible(&world->poubelle)){
SDL_RenderCopy(renderer, textures->poubelle, NULL, &world->poubelle.rect); SDL_RenderCopy(renderer, textures->poubelle, NULL, &world->poubelle.rect);
} }
//Affichage du lavabo
if (textures->lavabo[0] !=NULL && est_visible(&world->lavabo)){ if (textures->lavabo[0] !=NULL && est_visible(&world->lavabo)){
SDL_RenderCopy(renderer, textures->lavabo[0], NULL, &world->lavabo.rect); SDL_RenderCopy(renderer, textures->lavabo[0], NULL, &world->lavabo.rect);
} }
//Affichage du frigo
if (textures->frigo[0] !=NULL&& est_visible(&world->frigo)){ if (textures->frigo[0] !=NULL&& est_visible(&world->frigo)){
SDL_RenderCopy(renderer, textures->frigo[0], NULL, &world->frigo.rect); SDL_RenderCopy(renderer, textures->frigo[0], NULL, &world->frigo.rect);
} }
//Affichage du four
if (textures->four[0] !=NULL && est_visible(&world->four)){ if (textures->four[0] !=NULL && est_visible(&world->four)){
SDL_RenderCopy(renderer, textures->four[0], NULL, &world->four.rect); SDL_RenderCopy(renderer, textures->four[0], NULL, &world->four.rect);
} }
//Affichage de la zone d'envoi
if (textures->envoi[0] !=NULL && est_visible(&world->envoi)){ if (textures->envoi[0] !=NULL && est_visible(&world->envoi)){
SDL_RenderCopy(renderer, textures->envoi[0], NULL, &world->envoi.rect); SDL_RenderCopy(renderer, textures->envoi[0], NULL, &world->envoi.rect);
} }
//Affichage des comptoires
if (textures->comptoire != NULL){ if (textures->comptoire != NULL){
for (int i=0; i<NB_COMPT_1; i++){ for (int i=0; i<NB_COMPT_1; i++){
if (est_visible(&world->comptoire[i])){ if (est_visible(&world->comptoire[i])){
...@@ -92,6 +106,7 @@ void apply_graphics (SDL_Renderer *renderer, textures_t *textures, world_t *worl ...@@ -92,6 +106,7 @@ void apply_graphics (SDL_Renderer *renderer, textures_t *textures, world_t *worl
} }
} }
} }
//Affichage des ingrédients (!!! à actualiser)
SDL_Rect temp; SDL_Rect temp;
if (textures->ingredient !=NULL){ if (textures->ingredient !=NULL){
for (int i=0; i<NB_INGREDIENT; i++){ for (int i=0; i<NB_INGREDIENT; i++){
...@@ -101,6 +116,33 @@ void apply_graphics (SDL_Renderer *renderer, textures_t *textures, world_t *worl ...@@ -101,6 +116,33 @@ void apply_graphics (SDL_Renderer *renderer, textures_t *textures, world_t *worl
} }
} }
} }
//Affichage du score:
if (textures->police != NULL){
//Zone d'affichage du score -- taille du score s'adapte à son contenu
SDL_Rect zone_message = create_SDL_rect(20, 550, 75, 50);
SDL_Rect zone_score;
if (get_score(&world->etat_stocks)<100){
zone_score = create_SDL_rect(90, 555, 40, 40);
}else if (get_score(&world->etat_stocks)<10000){
zone_score = create_SDL_rect(90, 555, 60, 40);
}else{
zone_score = create_SDL_rect(90, 555, 100, 40);
}
//Couleur du message
SDL_Color color = { 255, 255, 0, 0 };
SDL_Texture* message;
SDL_Texture* points;
message = charger_texte("Score : ", renderer, textures->police, color);
char score_j[10];
sprintf(score_j, " %d", get_score(&world->etat_stocks)); //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);
//get_score(&world->etat_stocks);
}
} }
...@@ -170,9 +212,8 @@ SDL_Texture* charger_texte (const char* message, SDL_Renderer* renderer, TTF_Fon ...@@ -170,9 +212,8 @@ SDL_Texture* charger_texte (const char* message, SDL_Renderer* renderer, TTF_Fon
return texture; return texture;
} }
void render_texte(SDL_Renderer *renderer, int x, int y, int w, int h, SDL_Texture* texte){ void render_texte(SDL_Renderer *renderer, SDL_Rect zone_texte, SDL_Texture* texte){
SDL_Rect rect = {x, y, w, h}; SDL_RenderCopy(renderer, texte, NULL, &zone_texte);
SDL_RenderCopy(renderer, texte, NULL, &rect);
} }
/* /*
......
...@@ -13,6 +13,8 @@ ...@@ -13,6 +13,8 @@
#include "constantes.h" #include "constantes.h"
struct textures_s{ struct textures_s{
SDL_Texture* menu; /*!< Texture liée à l'image du fond du menu. */
SDL_Texture* fond; /*!< Texture liée à l'image du fond de l'écran. */ SDL_Texture* fond; /*!< Texture liée à l'image du fond de l'écran. */
SDL_Texture* joueur ; /* Texture du joueur*/ SDL_Texture* joueur ; /* Texture du joueur*/
SDL_Texture* comptoire ; /*< Texture des comptoires */ SDL_Texture* comptoire ; /*< Texture des comptoires */
...@@ -22,8 +24,7 @@ struct textures_s{ ...@@ -22,8 +24,7 @@ struct textures_s{
SDL_Texture* poubelle ; /*< Texture de la poubelle */ SDL_Texture* poubelle ; /*< Texture de la poubelle */
SDL_Texture* frigo[1] ; /*< Tableau de texture du frigo */ SDL_Texture* frigo[1] ; /*< Tableau de texture du frigo */
SDL_Texture* ingredient ; /*< textures des ingredients */ SDL_Texture* ingredient ; /*< textures des ingredients */
TTF_Font* police; /*Texture de la police d'écriture*/
//TTF_Font* police; /*Texture de la police d'écriture*/
}; };
/** /**
* \brief Type qui correspond aux textures du jeu * \brief Type qui correspond aux textures du jeu
...@@ -38,7 +39,7 @@ SDL_Texture* charger_image_transparente(const char* nomfichier, SDL_Renderer* re ...@@ -38,7 +39,7 @@ SDL_Texture* charger_image_transparente(const char* nomfichier, SDL_Renderer* re
SDL_Texture* charger_texte (const char* message, SDL_Renderer* renderer, TTF_Font *font, SDL_Color color); SDL_Texture* charger_texte (const char* message, SDL_Renderer* renderer, TTF_Font *font, SDL_Color color);
void render_texte(SDL_Renderer *renderer, int x, int y, int w, int h, SDL_Texture* texte); void render_texte(SDL_Renderer *renderer, SDL_Rect zone_texte, SDL_Texture* texte);
/** /**
* \brief La fonction nettoie les textures * \brief La fonction nettoie les textures
......
...@@ -48,7 +48,7 @@ void init_plat (plat_t* plat, char nom, int x, int y, int w, int h, int v, int s ...@@ -48,7 +48,7 @@ void init_plat (plat_t* plat, char nom, int x, int y, int w, int h, int v, int s
void init_stocks(stock_t* stocks, world_t *world){ void init_stocks(stock_t* stocks, world_t *world){
//Initialisation des stocks et du tableau d'état des menus //Initialisation des stocks et du tableau d'état des menus
stocks->score = 0; stocks->score = 1000;
for (int y=0; y<NB_PLAT; y++){ for (int y=0; y<NB_PLAT; y++){
for (int x=0; x<NB_INGREDIENT; x++){ for (int x=0; x<NB_INGREDIENT; x++){
stocks->plats[y][x] = 0; stocks->plats[y][x] = 0;
...@@ -65,6 +65,11 @@ void init_stocks(stock_t* stocks, world_t *world){ ...@@ -65,6 +65,11 @@ void init_stocks(stock_t* stocks, world_t *world){
} }
} }
int get_score(stock_t* stocks){
//retourne le score
return stocks->score;
}
void init_sprite(sprite_t *sprite, char nom, int x, int y, int w, int h, int v, int state){ void init_sprite(sprite_t *sprite, char nom, int x, int y, int w, int h, int v, int state){
//La fonction initialise tous les composants d'un sprite //La fonction initialise tous les composants d'un sprite
sprite->rect.x = x; sprite->rect.x = x;
...@@ -404,4 +409,3 @@ void update_data (world_t *world){ ...@@ -404,4 +409,3 @@ void update_data (world_t *world){
genere_fichier(nomSave, world->map, SCREEN_HEIGHT, SCREEN_WIDTH); genere_fichier(nomSave, world->map, SCREEN_HEIGHT, SCREEN_WIDTH);
} }
...@@ -214,6 +214,13 @@ int has_collided (sprite_t* spr1, sprite_t* spr2); ...@@ -214,6 +214,13 @@ int has_collided (sprite_t* spr1, sprite_t* spr2);
*/ */
void handle_collision (sprite_t* spr_move, sprite_t* spr_fixed); void handle_collision (sprite_t* spr_move, sprite_t* spr_fixed);
/**
* @brief donne le score actuelle de la partie
*
* @param stocks
* @return int
*/
int get_score(stock_t* stocks);
/** /**
* \brief Gère les collisions du jeu * \brief Gère les collisions du jeu
......
...@@ -25,7 +25,7 @@ textures_t textures; ...@@ -25,7 +25,7 @@ textures_t textures;
SDL_Window *windows; SDL_Window *windows;
SDL_Renderer *ecran; SDL_Renderer *ecran;
SDL_Event evenements; SDL_Event evenements;
TTF_Font *font; TTF_Font *font = TTF_OpenFont("Ressources/arial.ttf", 14);
windows = SDL_CreateWindow(TITRE, 100, 100, SCREEN_WIDTH, SCREEN_HEIGHT,SDL_WINDOW_OPENGL); windows = SDL_CreateWindow(TITRE, 100, 100, SCREEN_WIDTH, SCREEN_HEIGHT,SDL_WINDOW_OPENGL);
...@@ -41,6 +41,9 @@ init_data(&world); ...@@ -41,6 +41,9 @@ init_data(&world);
//Chargement des textures sur le renderer //Chargement des textures sur le renderer
ecran = SDL_CreateRenderer(windows, -1, SDL_RENDERER_ACCELERATED); ecran = SDL_CreateRenderer(windows, -1, SDL_RENDERER_ACCELERATED);
init_textures(ecran, &textures, font); init_textures(ecran, &textures, font);
//menu d'entrée en jeu
//boucle de jeu //boucle de jeu
while (estFini(&world)==0){ while (estFini(&world)==0){
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment