diff --git a/projets/Graphique/Makefile b/projets/Graphique/Makefile new file mode 100644 index 0000000..5791d72 --- /dev/null +++ b/projets/Graphique/Makefile @@ -0,0 +1,29 @@ +# +# Makefile pour la bibliotheque graphique +# + +SOURCES = $(wildcard *.c) +OBJETS = $(SOURCES:.c=.o) +CIBLE = libgraph.a + +# +# Nom de la cible principale +# + +all: $(CIBLE) + +# +# Cible de nettoyage +# + +clean: + rm -f core *.o $(CIBLE) + +# +# Dependances pour la bibliotheque +# + +$(CIBLE): $(OBJETS) + $(AR) rs $@ $? + +$(CIBLE:.a=).o: $(CIBLE:.a=).c $(CIBLE:.a=).h diff --git a/projets/Graphique/libgraph.a b/projets/Graphique/libgraph.a new file mode 100644 index 0000000..7d60157 Binary files /dev/null and b/projets/Graphique/libgraph.a differ diff --git a/projets/Graphique/libgraph.c b/projets/Graphique/libgraph.c new file mode 100644 index 0000000..bff8b0f --- /dev/null +++ b/projets/Graphique/libgraph.c @@ -0,0 +1,180 @@ +/**** Bibliotheque graphique ****/ + +/** Fichiers d'inclusion **/ + +#include + +#include "libgraph.h" + +/** Types **/ + +typedef struct { int r,v,b; } couleur; + +/** Constantes **/ + +#define BITS_PAR_PIXEL 32 + +static const couleur couleurs[]={ + {255,255,255}, + {0,0,0}, + {255,0,0}, + {0,255,0}, + {0,0,255}, + {255,105,180}, + {150,150,150}, + {-1,-1,-1} + }; + +/** Variables globales **/ + +static SDL_Surface *surface; + +/** Fonctions **/ + +/* Initialisation de la surface dessinable */ + +unsigned char creerSurface(int largeur,int hauteur,char *titre){ +SDL_Init(SDL_INIT_VIDEO); +SDL_WM_SetCaption(titre,titre); +surface=SDL_SetVideoMode(largeur,hauteur,BITS_PAR_PIXEL,SDL_DOUBLEBUF); +return (surface!=NULL); +} + +/* Fermeture de la surface dessinable */ + +void fermerSurface(void){ +if(surface!=NULL) SDL_FreeSurface(surface); +SDL_Quit(); +} + +/* Creation d'une couleur */ + +static int creerCouleur(int ncouleur){ +couleur c=couleurs[ncouleur]; +return SDL_MapRGB(surface->format,c.r,c.v,c.b); +} + +/* Dessin d'un rectangle plein */ + +void rectanglePlein(int x,int y,int l,int h,int c){ +SDL_Rect rectangle={x,y,l,h}; +SDL_FillRect(surface,&rectangle,creerCouleur(c)); +//SDL_Flip(surface); +} + +/* Manipulation de lutins */ + +static SDL_Surface *lutins[MAX_LUTINS]; +static int lutins_nb=0; + +static void configurerLutin(SDL_Surface *lutin,int ncouleur){ +couleur c=couleurs[ncouleur]; +int fond=SDL_MapRGB(lutin->format,c.r,c.v,c.b); +SDL_SetColorKey(lutin,SDL_SRCCOLORKEY|SDL_RLEACCEL,fond); +} + +int chargerLutin(char *fichier,int couleur){ +if(lutins_nb>=MAX_LUTINS) return -2; +SDL_Surface *lutin=SDL_LoadBMP(fichier); +if(lutin!=NULL){ + lutins[lutins_nb++]=lutin; + if(couleur>=0) configurerLutin(lutin,couleur); + return lutins_nb-1; + } +return -1; +} + +void afficherLutin(int lutin,int x,int y){ +SDL_Rect position; +position.x=x; +position.y=y; +SDL_BlitSurface(lutins[lutin],NULL,surface,&position); +} + +int creerLutin(int x,int y,int largeur,int hauteur,int couleur){ +if(lutins_nb>=MAX_LUTINS) return -2; +int rmask,gmask,bmask,amask; +#if SDL_BYTEORDER == SDL_BIG_ENDIAN +rmask=0xff000000; gmask=0x00ff0000; bmask=0x0000ff00; amask=0x000000ff; +#else +rmask=0x000000ff; gmask=0x0000ff00; bmask=0x00ff0000; amask=0xff000000; +#endif +if(couleur<0) amask=0x00000000; +SDL_Surface *lutin=SDL_CreateRGBSurface(0,largeur,hauteur,BITS_PAR_PIXEL,rmask,gmask,bmask,amask); +SDL_Rect fenetre; +fenetre.x=x; +fenetre.y=y; +fenetre.h=hauteur; +fenetre.w=largeur; +SDL_BlitSurface(surface,&fenetre,lutin,NULL); +lutins[lutins_nb++]=lutin; +if(couleur>=0) configurerLutin(lutin,couleur); +return lutins_nb-1; +} + +void tailleLutin(int lutin,int *largeur,int *hauteur){ +*largeur=lutins[lutin]->w; +*hauteur=lutins[lutin]->h; +} + +int sauverLutin(int lutin,char *nom){ return SDL_SaveBMP(lutins[lutin],nom); } + +/* Manipulation de copie de surface en BMP */ + +int sauverSurface(char *fichier){ return SDL_SaveBMP(surface,fichier); } + +unsigned char chargerSurface(char *fichier){ +SDL_Surface *image=SDL_LoadBMP(fichier); +if(image!=NULL){ + SDL_BlitSurface(image,NULL,surface,NULL); + SDL_Flip(surface); + } +return (image!=NULL); +} + +void majSurface(void){ SDL_Flip(surface); } + +/* Trouver la couleur d'un pixel */ + +int couleurPixel(int x,int y){ +int bpp=surface->format->BytesPerPixel; +Uint32 *p=(Uint32 *)(surface->pixels+y*surface->pitch+x*bpp); +Uint8 r,v,b; +SDL_GetRGB(*p,surface->format,&r,&v,&b); +int i=0; +while(1){ + if(couleurs[i].r<0) break; + if(r==couleurs[i].r && v==couleurs[i].v && b==couleurs[i].b) break; + i++; + } +if(couleurs[i].r<0) return -1; else return i; +} + +/* Fonction de traitement des événements */ + +unsigned char lireTouche(unsigned char *bas,char *touche,void **detail){ +static SDL_keysym _detail; +SDL_Event event; +while(SDL_PollEvent(&event)){ + if(event.type==SDL_KEYDOWN || event.type==SDL_KEYUP){ + *bas=(event.type==SDL_KEYDOWN)?1:0; + char* nom=SDL_GetKeyName(event.key.keysym.sym); + if(strlen(nom)==1 && nom[0]>=32 && nom[0]<128) *touche=nom[0]; else *touche=0; + _detail=event.key.keysym; + *detail=&_detail; + return 1; + } + } +return 0; +} + +void attendreEvenement(void){ +SDL_Event event; +while(SDL_WaitEvent(&event)) + switch(event.type){ + case SDL_KEYDOWN: + case SDL_MOUSEBUTTONDOWN: + case SDL_QUIT: + return; + } +} diff --git a/projets/Graphique/libgraph.h b/projets/Graphique/libgraph.h new file mode 100644 index 0000000..e0e7097 --- /dev/null +++ b/projets/Graphique/libgraph.h @@ -0,0 +1,33 @@ +/**** Bibliotheque graphique (definitions) ****/ + +/** Constantes **/ + +#define COULEUR_BLANC 0 +#define COULEUR_NOIR 1 +#define COULEUR_ROUGE 2 +#define COULEUR_VERT 3 +#define COULEUR_BLEU 4 +#define COULEUR_ROSE 5 +#define COULEUR_GRIS 6 + +#define MAX_LUTINS 16 + +/** Prototypes **/ + +unsigned char creerSurface(int largeur,int hauteur,char *titre); +unsigned char chargerSurface(char *fichier); +int sauverSurface(char *fichier); +void majSurface(void); +void fermerSurface(void); + +void rectanglePlein(int x,int y,int l,int h,int c); +int couleurPixel(int x,int y); + +int chargerLutin(char *fichier,int couleur); +void afficherLutin(int lutin,int x,int y); +int creerLutin(int x,int y,int largeur,int hauteur,int couleur); +int sauverLutin(int lutin,char *nom); +void tailleLutin(int lutin,int *largeur,int *hauteur); + +unsigned char lireTouche(unsigned char *bas,char *touche,void **detail); +void attendreEvenement(void); diff --git a/projets/Graphique/libgraph.o b/projets/Graphique/libgraph.o new file mode 100644 index 0000000..a156c1f Binary files /dev/null and b/projets/Graphique/libgraph.o differ diff --git a/projets/Liste/Makefile b/projets/Liste/Makefile new file mode 100644 index 0000000..7a639be --- /dev/null +++ b/projets/Liste/Makefile @@ -0,0 +1,29 @@ +# +# Makefile pour la bibliotheque graphique +# + +SOURCES = $(wildcard *.c) +OBJETS = $(SOURCES:.c=.o) +CIBLE = libListe.a + +# +# Nom de la cible principale +# + +all: $(CIBLE) + +# +# Cible de nettoyage +# + +clean: + rm -f core *.o $(CIBLE) + +# +# Dependances pour la bibliotheque +# + +$(CIBLE): $(OBJETS) + $(AR) rs $@ $? + +$(CIBLE:.a=).o: $(CIBLE:.a=).c $(CIBLE:.a=).h diff --git a/projets/Liste/libFile.c b/projets/Liste/libFile.c new file mode 100644 index 0000000..e8dc8ae --- /dev/null +++ b/projets/Liste/libFile.c @@ -0,0 +1,49 @@ +#include +#include +#include "libFile.h" +#include + +int taille(liste_t *l) +{ + return l->nombre; +} + +int enfiler (liste_t *l, element_t e, int taille){ +element_t nouveau=malloc(taille); +memcpy(nouveau,e,taille); +if (l->nombre >= l->alloue) + { + l->contenu = realloc(l->contenu, l->alloue+100); + l->alloue+=100; + } +l->contenu[l->nombre++]=nouveau; +return 0; +} + +void affichage(element_t e) +{ + liste_t *l=e; + printf("%d",l->contenu); +} + +int afficher(liste_t *l, void(*affichage)(element_t)) { +int i; +for(i=0; icontenu[i]); +return 0; +} + +int defiler(liste_t *l) +{ + int i; + + if(taille(l)>=1) + { + free(l->contenu[0]); + for(i=0; i < taille(l); i++) + { + l->contenu[i]=l->contenu[i+1]; + } + l->nombre--; + } + return 0; +} diff --git a/projets/Liste/libFile.h b/projets/Liste/libFile.h new file mode 100644 index 0000000..ea924ff --- /dev/null +++ b/projets/Liste/libFile.h @@ -0,0 +1,13 @@ +typedef void *element_t; + + typedef struct { + element_t *contenu; + int nombre; + int alloue; +} liste_t; + +int taille(liste_t *l); +int enfiler (liste_t *l, element_t e, int taille); +int afficher (liste_t *l, void(*affichage)(element_t)); +int defiler(liste_t *l); +void affichage(element_t e); diff --git a/projets/Liste/libFile.o b/projets/Liste/libFile.o new file mode 100644 index 0000000..2bd4188 Binary files /dev/null and b/projets/Liste/libFile.o differ diff --git a/projets/Liste/libListe.a b/projets/Liste/libListe.a new file mode 100644 index 0000000..99cdace Binary files /dev/null and b/projets/Liste/libListe.a differ diff --git a/projets/Lutins/invader_bombe.bmp b/projets/Lutins/invader_bombe.bmp new file mode 100644 index 0000000..0b3e39b Binary files /dev/null and b/projets/Lutins/invader_bombe.bmp differ diff --git a/projets/Lutins/invader_bouclier.bmp b/projets/Lutins/invader_bouclier.bmp new file mode 100644 index 0000000..f71e3f3 Binary files /dev/null and b/projets/Lutins/invader_bouclier.bmp differ diff --git a/projets/Lutins/invader_canon.bmp b/projets/Lutins/invader_canon.bmp new file mode 100644 index 0000000..2b450dd Binary files /dev/null and b/projets/Lutins/invader_canon.bmp differ diff --git a/projets/Lutins/invader_canon_ferraille.bmp b/projets/Lutins/invader_canon_ferraille.bmp new file mode 100644 index 0000000..575ec72 Binary files /dev/null and b/projets/Lutins/invader_canon_ferraille.bmp differ diff --git a/projets/Lutins/invader_missile.bmp b/projets/Lutins/invader_missile.bmp new file mode 100644 index 0000000..2095002 Binary files /dev/null and b/projets/Lutins/invader_missile.bmp differ diff --git a/projets/Lutins/invader_monstre1_1.bmp b/projets/Lutins/invader_monstre1_1.bmp new file mode 100644 index 0000000..cf56472 Binary files /dev/null and b/projets/Lutins/invader_monstre1_1.bmp differ diff --git a/projets/Lutins/invader_monstre1_2.bmp b/projets/Lutins/invader_monstre1_2.bmp new file mode 100644 index 0000000..cf56472 Binary files /dev/null and b/projets/Lutins/invader_monstre1_2.bmp differ diff --git a/projets/Lutins/invader_monstre2_1.bmp b/projets/Lutins/invader_monstre2_1.bmp new file mode 100644 index 0000000..40bbf1f Binary files /dev/null and b/projets/Lutins/invader_monstre2_1.bmp differ diff --git a/projets/Lutins/invader_monstre2_2.bmp b/projets/Lutins/invader_monstre2_2.bmp new file mode 100644 index 0000000..f99ec39 Binary files /dev/null and b/projets/Lutins/invader_monstre2_2.bmp differ diff --git a/projets/Lutins/invader_monstre3_1.bmp b/projets/Lutins/invader_monstre3_1.bmp new file mode 100644 index 0000000..a17556a Binary files /dev/null and b/projets/Lutins/invader_monstre3_1.bmp differ diff --git a/projets/Lutins/invader_monstre3_2.bmp b/projets/Lutins/invader_monstre3_2.bmp new file mode 100644 index 0000000..a17556a Binary files /dev/null and b/projets/Lutins/invader_monstre3_2.bmp differ diff --git a/projets/Lutins/invader_monstre_bouillie.bmp b/projets/Lutins/invader_monstre_bouillie.bmp new file mode 100644 index 0000000..fa89282 Binary files /dev/null and b/projets/Lutins/invader_monstre_bouillie.bmp differ diff --git a/projets/Lutins/invader_ovni.bmp b/projets/Lutins/invader_ovni.bmp new file mode 100644 index 0000000..da5fbd8 Binary files /dev/null and b/projets/Lutins/invader_ovni.bmp differ diff --git a/projets/Lutins/millepatte_champi.bmp b/projets/Lutins/millepatte_champi.bmp new file mode 100644 index 0000000..6126777 Binary files /dev/null and b/projets/Lutins/millepatte_champi.bmp differ diff --git a/projets/Lutins/millepatte_corps_bas.bmp b/projets/Lutins/millepatte_corps_bas.bmp new file mode 100644 index 0000000..ed4f660 Binary files /dev/null and b/projets/Lutins/millepatte_corps_bas.bmp differ diff --git a/projets/Lutins/millepatte_corps_droite.bmp b/projets/Lutins/millepatte_corps_droite.bmp new file mode 100644 index 0000000..36b049d Binary files /dev/null and b/projets/Lutins/millepatte_corps_droite.bmp differ diff --git a/projets/Lutins/millepatte_corps_gauche.bmp b/projets/Lutins/millepatte_corps_gauche.bmp new file mode 100644 index 0000000..a67092c Binary files /dev/null and b/projets/Lutins/millepatte_corps_gauche.bmp differ diff --git a/projets/Lutins/millepatte_corps_haut.bmp b/projets/Lutins/millepatte_corps_haut.bmp new file mode 100644 index 0000000..92dd3c7 Binary files /dev/null and b/projets/Lutins/millepatte_corps_haut.bmp differ diff --git a/projets/Lutins/millepatte_tete_bas.bmp b/projets/Lutins/millepatte_tete_bas.bmp new file mode 100644 index 0000000..c582ab3 Binary files /dev/null and b/projets/Lutins/millepatte_tete_bas.bmp differ diff --git a/projets/Lutins/millepatte_tete_droite.bmp b/projets/Lutins/millepatte_tete_droite.bmp new file mode 100644 index 0000000..7bce015 Binary files /dev/null and b/projets/Lutins/millepatte_tete_droite.bmp differ diff --git a/projets/Lutins/millepatte_tete_gauche.bmp b/projets/Lutins/millepatte_tete_gauche.bmp new file mode 100644 index 0000000..f94c70b Binary files /dev/null and b/projets/Lutins/millepatte_tete_gauche.bmp differ diff --git a/projets/Lutins/millepatte_tete_haut.bmp b/projets/Lutins/millepatte_tete_haut.bmp new file mode 100644 index 0000000..c74c0c1 Binary files /dev/null and b/projets/Lutins/millepatte_tete_haut.bmp differ diff --git a/projets/Makefile b/projets/Makefile new file mode 100644 index 0000000..0ca8ef6 --- /dev/null +++ b/projets/Makefile @@ -0,0 +1,24 @@ +REPERTOIRES = Graphique Liste Testliste +COMPILE = $(REPERTOIRES:%=all-%) +DEVERMINE = $(REPERTOIRES:%=debug-%) +NETTOYAGE = $(REPERTOIRES:%=clean-%) +export CFLAGS += -Wall + +all: $(COMPILE) +$(COMPILE): + $(MAKE) -C $(@:all-%=%) + +debug: $(DEVERMINE) +$(DEVERMINE): CFLAGS += -g -DDEVERMINE +$(DEVERMINE): + $(MAKE) -C $(@:debug-%=%) + +clean: $(NETTOYAGE) +$(NETTOYAGE): + $(MAKE) -C $(@:clean-%=%) clean + +all-Main: all-Bibliotheque +debug-Main: debug-Bibliotheque + +.PHONY: $(COMPILE) $(DEVERMINE) $(NETTOYAGE) +.PHONY: all debug clean diff --git a/projets/Testliste/Makefile b/projets/Testliste/Makefile new file mode 100644 index 0000000..c54edfb --- /dev/null +++ b/projets/Testliste/Makefile @@ -0,0 +1,12 @@ +SOURCES = $(wildcard *.c) +OBJETS = $(SOURCES:.c=.o) +BIBLIOTHEQUES = -L ../Liste -lListe +EXECUTABLE = projet +CFLAGS += -Wall -I ../Liste + +all: $(EXECUTABLE) +$(EXECUTABLE): $(OBJETS) + $(CC) -o $@ $^ $(BIBLIOTHEQUES) + +clean: + rm -rf $(EXECUTABLE) *.o diff --git a/projets/Testliste/projet b/projets/Testliste/projet new file mode 100755 index 0000000..da2800b Binary files /dev/null and b/projets/Testliste/projet differ diff --git a/projets/Testliste/test.c b/projets/Testliste/test.c new file mode 100644 index 0000000..c8e54b3 --- /dev/null +++ b/projets/Testliste/test.c @@ -0,0 +1,27 @@ +#include +#include +#include "libFile.h" +#include + + +int main(){ + +liste_t desnombres={NULL,0,0}; + +int petit = 10; +int moyen = 100; +int grand = 1000; + +enfiler(&desnombres,&petit,sizeof(int)); +enfiler(&desnombres,&moyen,sizeof(int)); +enfiler(&desnombres,&grand,sizeof(int)); +enfiler(&desnombres,&petit,sizeof(int)); + +afficher(&desnombres,affichage); + +defiler(&desnombres); + +afficher(&desnombres,affichage); + +return 0; +} diff --git a/projets/Testliste/test.o b/projets/Testliste/test.o new file mode 100644 index 0000000..8f431d5 Binary files /dev/null and b/projets/Testliste/test.o differ -- libgit2 0.21.2