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

Gestion de merge, on espere que ça marche...

parents 9f04bee5 ec8624db
No related branches found
No related tags found
No related merge requests found
Showing with 743 additions and 91 deletions
{
"configurations": [
{
"name": "Linux",
"includePath": [
"${workspaceFolder}/**",
"/usr/include/SDL2"
],
"defines": [],
"compilerPath": "/usr/bin/gcc",
"cStandard": "gnu17",
"cppStandard": "gnu++14",
"intelliSenseMode": "gcc-x64"
}
],
"version": 4
}
\ No newline at end of file
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "(gdb) Lancer",
"type": "cppdbg",
"request": "launch",
"program": "entrer le nom du programme, par exemple ${workspaceFolder}/a.out",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"setupCommands": [
{
"description": "Activer l'impression en mode Pretty pour gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
}
]
}
\ No newline at end of file
{
"files.associations": {
"cstdlib": "c"
}
}
\ No newline at end of file
...@@ -5,8 +5,8 @@ LDFLAGS = `sdl2-config --cflags --libs` -lSDL2_ttf ...@@ -5,8 +5,8 @@ LDFLAGS = `sdl2-config --cflags --libs` -lSDL2_ttf
INCLUDES = -I./SDL2_ttf INCLUDES = -I./SDL2_ttf
EXEC1 = main EXEC1 = main
EXEC2 = tests EXEC2 = tests
SRC = logique.c gestion_fichiers.c graphisme.c fonctions_SDL.c main.c SRC = logique.c gestion_fichiers.c graphisme.c main.c
SRC2 = logique.c gestion_fichiers.c graphisme.c fonctions_SDL.c tests.c SRC2 = logique.c gestion_fichiers.c graphisme.c tests.c
OBJ = $(SRC:.c=.o) OBJ = $(SRC:.c=.o)
OBJ2 = $(SRC2:.c=.o) OBJ2 = $(SRC2:.c=.o)
......
Ressources/compt0.bmp

29.3 KiB

Ressources/envoi0.bmp

14.7 KiB

Ressources/fond1.bmp

3.43 MiB | W: | H:

Ressources/fond1.bmp

1.37 MiB | W: | H:

Ressources/fond1.bmp
Ressources/fond1.bmp
Ressources/fond1.bmp
Ressources/fond1.bmp
  • 2-up
  • Swipe
  • Onion skin
Ressources/four0.bmp

44.2 KiB

Ressources/frigo0.bmp

44.2 KiB

No preview for this file type
Ressources/lavabo0.bmp

44.2 KiB

Source diff could not be displayed: it is too large. Options to address this: view the blob.
File added
Ressources/trash0.bmp

29.3 KiB

/**
* \file fonctions_SDL.c
* \brief Fichier de gestion de l'affichage, du texte
* \author Guillaume Vautrin
* \version 1.0
*/
#include "fonctions_SDL.h"
SDL_Texture* charger_image (const char* nomfichier, SDL_Renderer* renderer){
//Charge une image et retourne la surface de texture associée
SDL_Surface * image = SDL_LoadBMP(nomfichier);
SDL_Texture *texture = SDL_CreateTextureFromSurface(renderer, image);
SDL_FreeSurface(image);
return texture;
}
SDL_Texture* charger_image_transparente(const char* nomfichier, SDL_Renderer* renderer, Uint8 r, Uint8 g, Uint8 b){
SDL_Surface * image = SDL_LoadBMP(nomfichier);
SDL_SetColorKey(image, SDL_TRUE, SDL_MapRGB(image->format, r, g, b));
SDL_Texture* texture = SDL_CreateTextureFromSurface(renderer, image);
SDL_FreeSurface(image);
return texture;
}
//int SDL_SetColorKey(SDL_Surface* surface, int flag, Uint32 key) ; // défini la couleur transparente dans une surface
//Uint32 SDL_MapRGB(const SDL_PixelFormat* format, Uint8 r, Uint8 g, Uint8 b); //map les couleurs d'une bitmap
SDL_Texture* charger_texte (const char* message, SDL_Renderer* renderer, TTF_Font *font, SDL_Color color){
SDL_Surface* texte = TTF_RenderText_Blended(font, message, color);
SDL_Texture* texture = SDL_CreateTextureFromSurface(renderer, texte);
SDL_FreeSurface(texte);
return texture;
}
void render_texte(SDL_Renderer *renderer, int x, int y, int w, int h, SDL_Texture* texte){
SDL_Rect rect = {x, y, w, h};
SDL_RenderCopy(renderer, texte, NULL, &rect);
}
/*
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
/**
* \file fonctions_SDL.h
* \brief header des fonctions SDL
* \author Guillaume Vautrin
* \version 1.0
*/
#ifndef FONCTIONS_SDL_H
#define FONCTIONS_SDL_H
#include <SDL2/SDL.h>
#include <SDL2/SDL_ttf.h>
SDL_Texture* charger_image (const char* nomfichier, SDL_Renderer* renderer);
SDL_Texture* charger_image_transparente(const char* nomfichier, SDL_Renderer* renderer, Uint8 r, Uint8 g, Uint8 b) ;
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);
#endif
\ No newline at end of file
File added
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
char** allouer_tab_2D (int lig, int col){ char** allouer_tab_2D (int lig, int col){
//Allocation d'un tableau de caractère à 2 dimensions
char ** tab = malloc(lig * sizeof(char *)); char ** tab = malloc(lig * sizeof(char *));
for(int i=0; i<lig; i++){ for(int i=0; i<lig; i++){
tab[i] = malloc(col * sizeof(char)); tab[i] = malloc(col * sizeof(char));
...@@ -18,6 +19,7 @@ char** allouer_tab_2D (int lig, int col){ ...@@ -18,6 +19,7 @@ char** allouer_tab_2D (int lig, int col){
} }
void desallouer_tab_2D (char** tab, int lig){ void desallouer_tab_2D (char** tab, int lig){
//désallocation d'un tab de car 2D
for (int i=0; i<lig; i++){ for (int i=0; i<lig; i++){
free(tab[i]); free(tab[i]);
} }
...@@ -25,6 +27,7 @@ void desallouer_tab_2D (char** tab, int lig){ ...@@ -25,6 +27,7 @@ void desallouer_tab_2D (char** tab, int lig){
} }
void afficher_tab_2D (char** tab, int lig, int col){ void afficher_tab_2D (char** tab, int lig, int col){
//Affiche le tableau 2D
for (int i=0; i<lig; i++){ for (int i=0; i<lig; i++){
for (int j=0; j<col; j++){ for (int j=0; j<col; j++){
printf("%c", tab[i][j]); printf("%c", tab[i][j]);
...@@ -36,6 +39,7 @@ void afficher_tab_2D (char** tab, int lig, int col){ ...@@ -36,6 +39,7 @@ void afficher_tab_2D (char** tab, int lig, int col){
} }
void taille_fichier (const char* nomFichier, int* nbLig, int* nbCol){ void taille_fichier (const char* nomFichier, int* nbLig, int* nbCol){
//Donne la taille d'un fichier texte (colonne et ligne)
char test[3000]; //Stocke les caractères d'une ligne char test[3000]; //Stocke les caractères d'une ligne
int ligne = 0; // nb de lignes int ligne = 0; // nb de lignes
int colonne =0; // nb de colonnes int colonne =0; // nb de colonnes
...@@ -60,6 +64,7 @@ void taille_fichier (const char* nomFichier, int* nbLig, int* nbCol){ ...@@ -60,6 +64,7 @@ void taille_fichier (const char* nomFichier, int* nbLig, int* nbCol){
} }
char** lire_fichier (const char* nomFichier){ char** lire_fichier (const char* nomFichier){
//Traduit le contenu d'un fichier dans un tableau de char
FILE* fichier = fopen(nomFichier, "r"); FILE* fichier = fopen(nomFichier, "r");
if (fichier == NULL){ if (fichier == NULL){
printf("Erreur: fichier inaccessible \n"); printf("Erreur: fichier inaccessible \n");
...@@ -93,6 +98,7 @@ char** lire_fichier (const char* nomFichier){ ...@@ -93,6 +98,7 @@ char** lire_fichier (const char* nomFichier){
} }
void genere_fichier (const char* nomFichier, char** source, int ligne, int colonne){ void genere_fichier (const char* nomFichier, char** source, int ligne, int colonne){
//Génère un fichier a partir d'un tableau de caractère
FILE* fichier = NULL; FILE* fichier = NULL;
fichier = fopen(nomFichier, "w"); fichier = fopen(nomFichier, "w");
if (fichier !=NULL){ if (fichier !=NULL){
......
File added
...@@ -15,7 +15,25 @@ void clean_textures(textures_t *textures){ ...@@ -15,7 +15,25 @@ void clean_textures(textures_t *textures){
if (textures->fond != NULL){ if (textures->fond != NULL){
SDL_DestroyTexture(textures->fond); SDL_DestroyTexture(textures->fond);
} }
if (textures->comptoire != NULL){
SDL_DestroyTexture(textures->comptoire);
}
if (textures->envoi[0] != NULL){
SDL_DestroyTexture(textures->envoi[0]);
}
if (textures->frigo[0] != NULL){
SDL_DestroyTexture(textures->frigo[0]);
}
if (textures->four[0] != NULL){
SDL_DestroyTexture(textures->four[0]);
}
if (textures->lavabo[0] != NULL){
SDL_DestroyTexture(textures->lavabo[0]);
}
if (textures->poubelle != NULL){
SDL_DestroyTexture(textures->poubelle);
}
} }
void nettoyage_graphisme (SDL_Renderer *renderer, textures_t *textures, SDL_Window *fenetre){ void nettoyage_graphisme (SDL_Renderer *renderer, textures_t *textures, SDL_Window *fenetre){
...@@ -27,6 +45,13 @@ void nettoyage_graphisme (SDL_Renderer *renderer, textures_t *textures, SDL_Wind ...@@ -27,6 +45,13 @@ 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){
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->envoi[0] = charger_image ("Ressources/envoi0.bmp", renderer);
textures->frigo[0] = charger_image ("Ressources/frigo0.bmp", renderer);
textures->four[0] = charger_image ("Ressources/four0.bmp", renderer);
textures->poubelle = charger_image ("Ressources/trash0.bmp", renderer);
textures->lavabo[0] = charger_image ("Ressources/lavabo0.bmp", renderer);
// SDL_Color color = { 255, 0, 255 }; // SDL_Color color = { 255, 0, 255 };
//... = charger_texte ("Score : ", renderer, font, color); //... = charger_texte ("Score : ", renderer, font, color);
} }
...@@ -37,20 +62,26 @@ void apply_background (SDL_Renderer *renderer, textures_t *textures){ ...@@ -37,20 +62,26 @@ void apply_background (SDL_Renderer *renderer, textures_t *textures){
} }
} }
void apply_sprite (SDL_Renderer *renderer, SDL_Texture *image, sprite_t *sprite){
// applique la texture d'un sprite
SDL_Rect SrC = create_SDL_rect_from_texture(image);
SDL_Rect Des = create_SDL_rect_from_sprite(sprite);
SDL_RenderCopy(renderer, image, &SrC , &Des);
}
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
if (textures->joueur !=NULL){ if (textures->joueur !=NULL){
apply_sprite (renderer, textures->joueur, &world->joueur); SDL_RenderCopy(renderer, textures->joueur, NULL, &world->joueur.rect);
}
if (textures->poubelle !=NULL){
SDL_RenderCopy(renderer, textures->poubelle, NULL, &world->poubelle.rect);
}
if (textures->lavabo[0] !=NULL){
SDL_RenderCopy(renderer, textures->lavabo[0], NULL, &world->lavabo.rect);
}
if (textures->frigo[0] !=NULL){
SDL_RenderCopy(renderer, textures->frigo[0], NULL, &world->frigo.rect);
}
if (textures->four[0] !=NULL){
SDL_RenderCopy(renderer, textures->four[0], NULL, &world->four.rect);
}
if (textures->envoi[0] !=NULL){
SDL_RenderCopy(renderer, textures->envoi[0], NULL, &world->envoi.rect);
} }
} }
...@@ -62,7 +93,7 @@ void colorier_rect (SDL_Renderer *renderer, SDL_Rect rectangle, SDL_Color couleu ...@@ -62,7 +93,7 @@ void colorier_rect (SDL_Renderer *renderer, SDL_Rect rectangle, SDL_Color couleu
} }
} }
} }
/*
SDL_Rect create_SDL_rect_from_texture (SDL_Texture * texture){ SDL_Rect create_SDL_rect_from_texture (SDL_Texture * texture){
//Permet de créer un SDL_rect retournant la texture de la taille de la texture (SOURCE) //Permet de créer un SDL_rect retournant la texture de la taille de la texture (SOURCE)
int w; int w;
...@@ -80,11 +111,7 @@ SDL_Rect create_SDL_rect (int x, int y, int w, int h){ ...@@ -80,11 +111,7 @@ SDL_Rect create_SDL_rect (int x, int y, int w, int h){
rectangle.h = h; rectangle.h = h;
return rectangle; return rectangle;
} }
*/
SDL_Rect create_SDL_rect_from_sprite (sprite_t* sprite){
//Permet de créer un SDL_rect basé sur les données d'un sprite
return create_SDL_rect (sprite->x, sprite->y, sprite->w, sprite->h);
}
void update_graphics (SDL_Renderer *renderer, world_t *world, textures_t *textures){ void update_graphics (SDL_Renderer *renderer, world_t *world, textures_t *textures){
...@@ -93,4 +120,45 @@ void update_graphics (SDL_Renderer *renderer, world_t *world, textures_t *textur ...@@ -93,4 +120,45 @@ void update_graphics (SDL_Renderer *renderer, world_t *world, textures_t *textur
apply_graphics(renderer, textures, world); apply_graphics(renderer, textures, world);
SDL_RenderPresent(renderer); // Récupère les infos actualisés de render et les affiches SDL_RenderPresent(renderer); // Récupère les infos actualisés de render et les affiches
} }
\ No newline at end of file
SDL_Texture* charger_image (const char* nomfichier, SDL_Renderer* renderer){
//Charge une image et retourne la surface de texture associée
SDL_Surface * image = SDL_LoadBMP(nomfichier);
SDL_Texture *texture = SDL_CreateTextureFromSurface(renderer, image);
SDL_FreeSurface(image);
return texture;
}
SDL_Texture* charger_image_transparente(const char* nomfichier, SDL_Renderer* renderer, Uint8 r, Uint8 g, Uint8 b){
SDL_Surface * image = SDL_LoadBMP(nomfichier);
SDL_SetColorKey(image, SDL_TRUE, SDL_MapRGB(image->format, r, g, b));
SDL_Texture* texture = SDL_CreateTextureFromSurface(renderer, image);
SDL_FreeSurface(image);
return texture;
}
//int SDL_SetColorKey(SDL_Surface* surface, int flag, Uint32 key) ; // défini la couleur transparente dans une surface
//Uint32 SDL_MapRGB(const SDL_PixelFormat* format, Uint8 r, Uint8 g, Uint8 b); //map les couleurs d'une bitmap
SDL_Texture* charger_texte (const char* message, SDL_Renderer* renderer, TTF_Font *font, SDL_Color color){
SDL_Surface* texte = TTF_RenderText_Blended(font, message, color);
SDL_Texture* texture = SDL_CreateTextureFromSurface(renderer, texte);
SDL_FreeSurface(texte);
return texture;
}
void render_texte(SDL_Renderer *renderer, int x, int y, int w, int h, SDL_Texture* texte){
SDL_Rect rect = {x, y, w, h};
SDL_RenderCopy(renderer, texte, NULL, &rect);
}
/*
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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment