diff --git a/ListeC/Liste.c b/ListeC/Liste.c new file mode 100644 index 0000000..fc20058 --- /dev/null +++ b/ListeC/Liste.c @@ -0,0 +1,41 @@ +#include +#include +#include "Liste.h" + +void creer_liste(struct liste_entite *l) +{ + l = malloc(sizeof(struct liste_entite)); +} + +struct entite creer_entite(int x, int y, int idd) +{ + struct entite e; + e.posx=x; + e.posy=y; + e.id=idd; + return e; +} + +void ajout_tete(struct liste_entite **pL, struct entite x) +{ + struct liste_entite *tmp; + tmp = malloc(sizeof(struct liste_entite)); + tmp->enti = x; + tmp->suivant = *pL; + *pL = tmp; +} + + +void imprimer_liste(struct liste_entite *l) +{ + struct liste_entite *p; + p = l; + while (p != NULL) + { + printf("%d -> ",p->enti.posx); + p=p->suivant; + } + printf("\n"); +} + + diff --git a/ListeC/Liste.h b/ListeC/Liste.h new file mode 100644 index 0000000..d2599fc --- /dev/null +++ b/ListeC/Liste.h @@ -0,0 +1,25 @@ +#include +#include + +struct entite +{ + int posx; + int posy; + int id; +}; + + +struct liste_entite +{ + struct entite enti; + struct liste_entite *suivant; +}; + + +void ajout_tete(struct liste_entite**, struct entite); + +void creer_liste(struct liste_entite*); + +struct entite creer_entite(int,int,int); + +void imprimer_liste(struct liste_entite*); diff --git a/Main/Makefile b/Main/Makefile new file mode 100644 index 0000000..3e94592 --- /dev/null +++ b/Main/Makefile @@ -0,0 +1,27 @@ +CC=clang +TARGET=exec +CFLAGS=-g -W -Wall -Wextra +LDFLAGS=-I Graphique -l graph -L ../Graphique -l SDL -l SDL_ttf + +default: $(TARGET) + +Liste.o : ../ListeC/Liste.c ../ListeC/Liste.h + clang $(CFLAGS) -c ../ListeC/Liste.c + +Monstre.o : ../Monstre/Monstre.c ../Monstre/Monstre.h ../ListeC/Liste.h + clang $(CFLAGS) -c ../Monstre/Monstre.c + +Missile.o : ../Missile/Missile.c ../Missile/Missile.h ../ListeC/Liste.h + clang $(CFLAGS) -c ../Missile/Missile.c + +main.o : main.c ../ListeC/Liste.h + clang $(CFLAGS) -c main.c + + +$(TARGET): Liste.o main.o Monstre.o Missile.o + clang main.o Liste.o Monstre.o Missile.o -o $(TARGET) $(LDFLAGS) + +.PHONY: clean +clean: + rm -f *.o + rm -f $(TARGET) diff --git a/Main/main.c b/Main/main.c new file mode 100644 index 0000000..6cd88fb --- /dev/null +++ b/Main/main.c @@ -0,0 +1,63 @@ +#include +#include +#include +#include "../Graphique/libgraph.h" +#include "../ListeC/Liste.h" +#include "../Monstre/Monstre.h" +#include "../Missile/Missile.h" + +#define TailleX 500 +#define TailleY 500 +//clang Try.c -I Graphique -l graph -L Graphique -l SDL -l SDL_ttf + + +char touche() +{ + char touche; + evenement even; + lireEvenement (&even,&touche,NULL); + return touche; +} + +int main() +{ + struct liste_entite *enemies = NULL; + creer_liste(enemies); + ajout_tete(&enemies,creer_entite(50,50,0)); + ajout_tete(&enemies,creer_entite(150,50,0)); + ajout_tete(&enemies,creer_entite(250,50,0)); + imprimer_liste(enemies); + int sens=1; + int *psens=&sens; + + struct entite joueur; + joueur.posx=225; + joueur.posy=470; + int canon = chargerLutin("../../Lutins/invader_canon.bmp",COULEUR_NOIR); + + struct liste_entite *tires = NULL; + creer_liste(tires); + //ajout_tete(&tires,creer_entite(225,470,0)); + Tirer(joueur,&tires); + imprimer_liste(tires); + int missile = chargerLutin("../../Lutins/invader_missile.bmp",COULEUR_NOIR); + + char Nom[20]="PremiereFenetre"; + creerSurface(TailleX,TailleY,Nom); + int lulu = chargerLutin("../../Lutins/invader_monstre1_1.bmp",COULEUR_NOIR); + + while(1) + { + afficherLutin(canon,joueur.posx,joueur.posy); + DeplacementLutin(lulu,enemies,psens,1); + + char c = touche(); + printf("%c",c); + DeplacementTire(missile,tires); + + majSurface(); + rectanglePlein(0,0,TailleX,TailleY,COULEUR_NOIR); + SDL_Delay(20); + } + return 0; +} diff --git a/Missile/Missile.c b/Missile/Missile.c new file mode 100644 index 0000000..c66e2fe --- /dev/null +++ b/Missile/Missile.c @@ -0,0 +1,23 @@ +#include +#include +#include "../Graphique/libgraph.h" +#include "../ListeC/Liste.h" +#include "Missile.h" + + +void Tirer(struct entite joueur, struct liste_entite **pl) +{ + ajout_tete(pl,creer_entite(joueur.posx+18,joueur.posy-5,0)); +} + + +void DeplacementTire(int tire,struct liste_entite *l) +{ + struct liste_entite *ml=l; + while(ml != NULL) + { + ml->enti.posy-=5; + afficherLutin(tire,ml->enti.posx,ml->enti.posy); + ml=ml->suivant; + } +} diff --git a/Missile/Missile.h b/Missile/Missile.h new file mode 100644 index 0000000..070415a --- /dev/null +++ b/Missile/Missile.h @@ -0,0 +1,6 @@ +#include +#include + +void Tirer(struct entite, struct liste_entite**); + +void DeplacementTire(int,struct liste_entite*); diff --git a/Monstre/Monstre.c b/Monstre/Monstre.c new file mode 100644 index 0000000..689d6a0 --- /dev/null +++ b/Monstre/Monstre.c @@ -0,0 +1,49 @@ +#include +#include +#include "../Graphique/libgraph.h" +#include "../ListeC/Liste.h" +#include "Monstre.h" + +//sens 1 = Va vers la droite +void DeplacementLutin(int lutin,struct liste_entite *l, int *psens, int speed) +{ + int ind=0; + struct liste_entite *ml=l; + while(ml != NULL) + { + if (*psens==1) + { + ml->enti.posx+=speed; + if(ml->enti.posx>=450)ind=1; + afficherLutin(lutin,ml->enti.posx,ml->enti.posy); + } + else + { + ml->enti.posx-=speed; + if(ml->enti.posx<=50)ind=2; + afficherLutin(lutin,ml->enti.posx,ml->enti.posy); + } + ml=ml->suivant; + } + if (ind==1) + { + *psens=0; + struct liste_entite *ml2=l; + while(ml2 != NULL) + { + ml2->enti.posy+=30; + ml2=ml2->suivant; + } + } + else if (ind==2) + { + *psens=1; + struct liste_entite *ml2=l; + while(ml2 != NULL) + { + ml2->enti.posy+=30; + ml2=ml2->suivant; + } + } +} + diff --git a/Monstre/Monstre.h b/Monstre/Monstre.h new file mode 100644 index 0000000..231eafa --- /dev/null +++ b/Monstre/Monstre.h @@ -0,0 +1,4 @@ +#include +#include + +void DeplacementLutin(int,struct liste_entite*,int*,int); -- libgit2 0.21.2