progprinc.c
3.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
#include <stdio.h>
#include <stdlib.h>
#include <libFile.h>
#include <libgraph.h>
#include <unistd.h>
#include <time.h>
#include <SDL/SDL.h>
#define MAX_ELEMENTS 50
typedef struct {
int x;
int y;
}position;
typedef struct {
position contenu[MAX_ELEMENTS];
int nombre;
} liste_champi;
void affichage(element_t e)
{
position *p = e;
printf("%d %d \n", p->x, p->y);
}
int main() {
SDL_keysym* detail;
srand(time(NULL));
char touche;
unsigned char bas;
int largeur = 1000;
int hauteur = 1000;
liste_champi muschrooms={.nombre=0};
liste_t listecenti={NULL,0,0};
int h,w,l,i;
char *titre = "Le Centipède";
int champi = chargerLutin("Lutins/millepatte_champi.bmp",0);
int Teted = chargerLutin("Lutins/millepatte_tete_droite.bmp",0);
/* int Teteg = chargerLutin("Lutins/millepatte_tete_gauche.bmp",0);
int Teteh = chargerLutin("Lutins/millepatte_tete_haut.bmp",0);
int Teteb = chargerLutin("Lutins/millepatte_tete_bas.bmp",0);
int Corpsg = chargerLutin("Lutins/millepatte_corps_gauche.bmp",0); */
int Corpsd = chargerLutin("Lutins/millepatte_corps_droite.bmp",0);
/* int Corpsh = chargerLutin("Lutins/millepatte_corps_haut.bmp",0);
int Corpsb = chargerLutin("Lutins/millepatte_corps_bas.bmp",0); */
if(champi<0){ printf("Champi pas là\n"); exit(-1); }
tailleLutin(champi,&l,&h);
position *pos;
position poschampi;
position posmillepatte;
creerSurface(largeur,hauteur,titre);
int x = 300;
int y = 500;
for(i=0; i<4; i++)
{
posmillepatte.x = (x + 50*i);
posmillepatte.y = y;
enfiler(&listecenti,&posmillepatte,sizeof(position));
}
//affichage des corpsd du centipede
for(i=0; i<4; i++)
{
pos = enieme(i,&listecenti);
afficherLutin(Corpsd,pos->x,pos->y);
}
posmillepatte.x = (x+200);
posmillepatte.y = y;
enfiler(&listecenti,&posmillepatte,sizeof(position)); //affichage de la tete du Centipède
pos = enieme(4, &listecenti);
afficherLutin(Teted,pos->x,pos->y);
for(i = 0 ; i < 20; i++)
{
rectanglePlein(i*50,0,1,1000,5); //pose de la grille
rectanglePlein(0,i*50,1000,1,5);
}
for(w=0;w<10;w++) {
poschampi.x = (rand()%20)*50; //fixe coordonnées des champignons
poschampi.y = (rand()%20)*50;
if(poschampi.y > 550 || poschampi.y < 450) {
muschrooms.contenu[muschrooms.nombre++]=poschampi; }
else w--;
}
printf("%d %d \n",l,h);
for(w=0;w<10;w++){
afficherLutin(champi,(muschrooms.contenu[w].x)+1,(muschrooms.contenu[w].y)+6);
}//affiche les champis
majSurface();
int gomme = creerLutin(0,0,50,50,0);
majSurface();
while(1){
if(lireTouche(&bas,&touche,(void **)&detail) && bas==1) {
if(detail->sym==SDLK_RIGHT) {
printf("dans le droite\n");
pos = premier(&listecenti);
afficherLutin(gomme,pos->x,pos->y);
defiler(&listecenti);
pos = dernier(&listecenti);
afficherLutin(gomme,pos->x,pos->y);
afficherLutin(Corpsd,(pos->x),pos->y);
posmillepatte.x = pos->x+50;
posmillepatte.y = pos->y;
enfiler(&listecenti,&posmillepatte,sizeof(posmillepatte));
afficherLutin(Teted,posmillepatte.x,posmillepatte.y);
majSurface();
}
if(detail->sym==SDLK_LEFT) {
}
if(detail->sym==SDLK_UP) {
}
if(detail->sym==SDLK_DOWN) {
}
if(touche=='a')
{
fermerSurface(); //condition d'arret
return 0;
}
}}
return 0;
}