Commit 0b5eb1df3377d5d28b4532338e59d3e7dd7d0bf4
0 parents
1ere Version
Showing
8 changed files
with
238 additions
and
0 deletions
Show diff stats
1 | +++ a/ListeC/Liste.c | |
... | ... | @@ -0,0 +1,41 @@ |
1 | +#include <stdio.h> | |
2 | +#include <stdlib.h> | |
3 | +#include "Liste.h" | |
4 | + | |
5 | +void creer_liste(struct liste_entite *l) | |
6 | +{ | |
7 | + l = malloc(sizeof(struct liste_entite)); | |
8 | +} | |
9 | + | |
10 | +struct entite creer_entite(int x, int y, int idd) | |
11 | +{ | |
12 | + struct entite e; | |
13 | + e.posx=x; | |
14 | + e.posy=y; | |
15 | + e.id=idd; | |
16 | + return e; | |
17 | +} | |
18 | + | |
19 | +void ajout_tete(struct liste_entite **pL, struct entite x) | |
20 | +{ | |
21 | + struct liste_entite *tmp; | |
22 | + tmp = malloc(sizeof(struct liste_entite)); | |
23 | + tmp->enti = x; | |
24 | + tmp->suivant = *pL; | |
25 | + *pL = tmp; | |
26 | +} | |
27 | + | |
28 | + | |
29 | +void imprimer_liste(struct liste_entite *l) | |
30 | +{ | |
31 | + struct liste_entite *p; | |
32 | + p = l; | |
33 | + while (p != NULL) | |
34 | + { | |
35 | + printf("%d -> ",p->enti.posx); | |
36 | + p=p->suivant; | |
37 | + } | |
38 | + printf("\n"); | |
39 | +} | |
40 | + | |
41 | + | ... | ... |
1 | +++ a/ListeC/Liste.h | |
... | ... | @@ -0,0 +1,25 @@ |
1 | +#include <stdio.h> | |
2 | +#include <stdlib.h> | |
3 | + | |
4 | +struct entite | |
5 | +{ | |
6 | + int posx; | |
7 | + int posy; | |
8 | + int id; | |
9 | +}; | |
10 | + | |
11 | + | |
12 | +struct liste_entite | |
13 | +{ | |
14 | + struct entite enti; | |
15 | + struct liste_entite *suivant; | |
16 | +}; | |
17 | + | |
18 | + | |
19 | +void ajout_tete(struct liste_entite**, struct entite); | |
20 | + | |
21 | +void creer_liste(struct liste_entite*); | |
22 | + | |
23 | +struct entite creer_entite(int,int,int); | |
24 | + | |
25 | +void imprimer_liste(struct liste_entite*); | ... | ... |
1 | +++ a/Main/Makefile | |
... | ... | @@ -0,0 +1,27 @@ |
1 | +CC=clang | |
2 | +TARGET=exec | |
3 | +CFLAGS=-g -W -Wall -Wextra | |
4 | +LDFLAGS=-I Graphique -l graph -L ../Graphique -l SDL -l SDL_ttf | |
5 | + | |
6 | +default: $(TARGET) | |
7 | + | |
8 | +Liste.o : ../ListeC/Liste.c ../ListeC/Liste.h | |
9 | + clang $(CFLAGS) -c ../ListeC/Liste.c | |
10 | + | |
11 | +Monstre.o : ../Monstre/Monstre.c ../Monstre/Monstre.h ../ListeC/Liste.h | |
12 | + clang $(CFLAGS) -c ../Monstre/Monstre.c | |
13 | + | |
14 | +Missile.o : ../Missile/Missile.c ../Missile/Missile.h ../ListeC/Liste.h | |
15 | + clang $(CFLAGS) -c ../Missile/Missile.c | |
16 | + | |
17 | +main.o : main.c ../ListeC/Liste.h | |
18 | + clang $(CFLAGS) -c main.c | |
19 | + | |
20 | + | |
21 | +$(TARGET): Liste.o main.o Monstre.o Missile.o | |
22 | + clang main.o Liste.o Monstre.o Missile.o -o $(TARGET) $(LDFLAGS) | |
23 | + | |
24 | +.PHONY: clean | |
25 | +clean: | |
26 | + rm -f *.o | |
27 | + rm -f $(TARGET) | ... | ... |
1 | +++ a/Main/main.c | |
... | ... | @@ -0,0 +1,63 @@ |
1 | +#include <stdio.h> | |
2 | +#include <unistd.h> | |
3 | +#include <SDL/SDL.h> | |
4 | +#include "../Graphique/libgraph.h" | |
5 | +#include "../ListeC/Liste.h" | |
6 | +#include "../Monstre/Monstre.h" | |
7 | +#include "../Missile/Missile.h" | |
8 | + | |
9 | +#define TailleX 500 | |
10 | +#define TailleY 500 | |
11 | +//clang Try.c -I Graphique -l graph -L Graphique -l SDL -l SDL_ttf | |
12 | + | |
13 | + | |
14 | +char touche() | |
15 | +{ | |
16 | + char touche; | |
17 | + evenement even; | |
18 | + lireEvenement (&even,&touche,NULL); | |
19 | + return touche; | |
20 | +} | |
21 | + | |
22 | +int main() | |
23 | +{ | |
24 | + struct liste_entite *enemies = NULL; | |
25 | + creer_liste(enemies); | |
26 | + ajout_tete(&enemies,creer_entite(50,50,0)); | |
27 | + ajout_tete(&enemies,creer_entite(150,50,0)); | |
28 | + ajout_tete(&enemies,creer_entite(250,50,0)); | |
29 | + imprimer_liste(enemies); | |
30 | + int sens=1; | |
31 | + int *psens=&sens; | |
32 | + | |
33 | + struct entite joueur; | |
34 | + joueur.posx=225; | |
35 | + joueur.posy=470; | |
36 | + int canon = chargerLutin("../../Lutins/invader_canon.bmp",COULEUR_NOIR); | |
37 | + | |
38 | + struct liste_entite *tires = NULL; | |
39 | + creer_liste(tires); | |
40 | + //ajout_tete(&tires,creer_entite(225,470,0)); | |
41 | + Tirer(joueur,&tires); | |
42 | + imprimer_liste(tires); | |
43 | + int missile = chargerLutin("../../Lutins/invader_missile.bmp",COULEUR_NOIR); | |
44 | + | |
45 | + char Nom[20]="PremiereFenetre"; | |
46 | + creerSurface(TailleX,TailleY,Nom); | |
47 | + int lulu = chargerLutin("../../Lutins/invader_monstre1_1.bmp",COULEUR_NOIR); | |
48 | + | |
49 | + while(1) | |
50 | + { | |
51 | + afficherLutin(canon,joueur.posx,joueur.posy); | |
52 | + DeplacementLutin(lulu,enemies,psens,1); | |
53 | + | |
54 | + char c = touche(); | |
55 | + printf("%c",c); | |
56 | + DeplacementTire(missile,tires); | |
57 | + | |
58 | + majSurface(); | |
59 | + rectanglePlein(0,0,TailleX,TailleY,COULEUR_NOIR); | |
60 | + SDL_Delay(20); | |
61 | + } | |
62 | + return 0; | |
63 | +} | ... | ... |
1 | +++ a/Missile/Missile.c | |
... | ... | @@ -0,0 +1,23 @@ |
1 | +#include <stdio.h> | |
2 | +#include <stdlib.h> | |
3 | +#include "../Graphique/libgraph.h" | |
4 | +#include "../ListeC/Liste.h" | |
5 | +#include "Missile.h" | |
6 | + | |
7 | + | |
8 | +void Tirer(struct entite joueur, struct liste_entite **pl) | |
9 | +{ | |
10 | + ajout_tete(pl,creer_entite(joueur.posx+18,joueur.posy-5,0)); | |
11 | +} | |
12 | + | |
13 | + | |
14 | +void DeplacementTire(int tire,struct liste_entite *l) | |
15 | +{ | |
16 | + struct liste_entite *ml=l; | |
17 | + while(ml != NULL) | |
18 | + { | |
19 | + ml->enti.posy-=5; | |
20 | + afficherLutin(tire,ml->enti.posx,ml->enti.posy); | |
21 | + ml=ml->suivant; | |
22 | + } | |
23 | +} | ... | ... |
1 | +++ a/Monstre/Monstre.c | |
... | ... | @@ -0,0 +1,49 @@ |
1 | +#include <stdio.h> | |
2 | +#include <stdlib.h> | |
3 | +#include "../Graphique/libgraph.h" | |
4 | +#include "../ListeC/Liste.h" | |
5 | +#include "Monstre.h" | |
6 | + | |
7 | +//sens 1 = Va vers la droite | |
8 | +void DeplacementLutin(int lutin,struct liste_entite *l, int *psens, int speed) | |
9 | +{ | |
10 | + int ind=0; | |
11 | + struct liste_entite *ml=l; | |
12 | + while(ml != NULL) | |
13 | + { | |
14 | + if (*psens==1) | |
15 | + { | |
16 | + ml->enti.posx+=speed; | |
17 | + if(ml->enti.posx>=450)ind=1; | |
18 | + afficherLutin(lutin,ml->enti.posx,ml->enti.posy); | |
19 | + } | |
20 | + else | |
21 | + { | |
22 | + ml->enti.posx-=speed; | |
23 | + if(ml->enti.posx<=50)ind=2; | |
24 | + afficherLutin(lutin,ml->enti.posx,ml->enti.posy); | |
25 | + } | |
26 | + ml=ml->suivant; | |
27 | + } | |
28 | + if (ind==1) | |
29 | + { | |
30 | + *psens=0; | |
31 | + struct liste_entite *ml2=l; | |
32 | + while(ml2 != NULL) | |
33 | + { | |
34 | + ml2->enti.posy+=30; | |
35 | + ml2=ml2->suivant; | |
36 | + } | |
37 | + } | |
38 | + else if (ind==2) | |
39 | + { | |
40 | + *psens=1; | |
41 | + struct liste_entite *ml2=l; | |
42 | + while(ml2 != NULL) | |
43 | + { | |
44 | + ml2->enti.posy+=30; | |
45 | + ml2=ml2->suivant; | |
46 | + } | |
47 | + } | |
48 | +} | |
49 | + | ... | ... |