Bonjour ou bonsoir,

En fait je suis en train de faire un petit jeu(sokoban du sdz) en C++ avec la SDL mais dés lors ou j'utilise des class a la place des tableau de int pour gérée le terrain j'ai undifined reference.

voici les sources(seulement ce qui semble être concerner) :

jeu.h :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
#ifndef H_JEU
#define H_JEU
 
    #include "include.h"
    #include "level.h"
    #include "perso.h"
 
    class Jeu
    {
        private :
 
        SDL_Surface *mur, *caisse, *caisse_ok, *cible;
        SDL_Surface *perso[4];
 
        SDL_Rect r_perso;
 
        Level niveau[BLOC_HAUTEUR][BLOC_LARGEUR];
        Perso t;
        bool fini;
 
        public :
 
        Jeu();
        ~Jeu();
 
        bool Init();
        bool Load_Level(std::string filename);
 
        void Show(SDL_Surface* screen);
        void Move(int direction);
        void Verif_fini();
        void Vide_terrain();
    };
 
#endif
jeu.cpp :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
#include "jeu.h"
 
Jeu::Jeu()
{
    int i = 0;
 
    Vide_terrain();
 
    for(i = 0; i < 4; i++)
    {
        perso[i] = NULL;
    }
 
    t.SetDirection(HAUT);
 
    mur = NULL;
    caisse = NULL;
    caisse_ok = NULL;
    cible = NULL;
 
    fini = false;
}
 
Jeu::~Jeu()
{
    int i = 0;
 
    for(i = 0; i < 4; i++)
    {
        SDL_FreeSurface(perso[i]);
    }
 
    SDL_FreeSurface(mur);
    SDL_FreeSurface(caisse);
    SDL_FreeSurface(caisse_ok);
    SDL_FreeSurface(cible);
}
 
bool Jeu::Init()
{
    int i = 0, j = 0;
 
    if(!(Load_Level("Level/test.map")))
    {
        return false;
    }
 
    mur = SDL_LoadBMP("Image/mur.bmp");
    caisse = SDL_LoadBMP("Image/caisse.bmp");
    caisse_ok = SDL_LoadBMP("Image/caisse_ok.bmp");
    cible = SDL_LoadBMP("Image/cible.bmp");
 
    for(i = 0; i < BLOC_HAUTEUR; i++)
    {
        for(j = 0; j < BLOC_LARGEUR; j++)
        {
            niveau[i][j].SetImage(mur, caisse, caisse_ok, cible);
        }
    }
 
    perso[HAUT] = SDL_LoadBMP("Image/perso_haut.bmp");
    perso[BAS] = SDL_LoadBMP("Image/perso_bas.bmp");
    perso[DROITE] = SDL_LoadBMP("Image/perso_droite.bmp");
    perso[GAUCHE] = SDL_LoadBMP("Image/perso_gauche.bmp");
 
    for(i = 0; i < 4; i++)
    {
        SDL_SetColorKey(perso[i], SDL_SRCCOLORKEY, SDL_MapRGB(perso[i]->format, 255, 255, 255));
 
        if(perso[i] == NULL)
        {
            std::cout << "Impossible de charger les images du perso" << std::endl;
 
            return false;
        }
    }
 
    t.SetImage(perso[HAUT], perso[BAS], perso[DROITE], perso[GAUCHE]);
 
    if((mur == NULL) || (caisse == NULL) || (caisse_ok == NULL) || (cible == NULL))
    {
        std::cout << "Impossible de charger l'image du mur, des caisses et de la cible" << std::endl;
 
        return false;
    }
 
    for(i = 0; i < BLOC_HAUTEUR; i++)
    {
        for(j = 0; j < BLOC_LARGEUR; j++)
        {
            if(niveau[i][j].GetType() == PERSO)
            {
                r_perso.x = j;
                r_perso.y = i;
            }
        }
    }
 
    t.SetPos(&r_perso);
 
    return true;
}
 
bool Jeu::Load_Level(std::string filename)
{
    std::ifstream file(filename.c_str());
    char c;
 
    int i = 0, j = 0;
 
    if(file)
    {
        for(i = 0; i < BLOC_HAUTEUR; i++)
        {
            for(j = 0; j < BLOC_LARGEUR; j++)
            {
                file.get(c);
 
                niveau[i][j].SetType(c - '0');
            }
        }
    }
    else
    {
        std::cout << "Impossible de charger le niveau" << std::endl;
 
        return false;
    }
 
    return true;
}
 
void Jeu::Show(SDL_Surface* screen)
{
    SDL_Rect r_dest;
 
    int i = 0, j = 0;
 
    for(i = 0; i < BLOC_HAUTEUR; i++)
    {
        for(j = 0; j < BLOC_LARGEUR; j++)
        {
            r_dest.x = j * TAILLE_IMAGE;
            r_dest.y = i * TAILLE_IMAGE;
 
            niveau[i][j].SetPos(&r_dest);
            niveau[i][j].Show(screen);
        }
    }
 
    r_dest.x = r_perso.x * TAILLE_IMAGE;
    r_dest.y = r_perso.y * TAILLE_IMAGE;
 
    t.SetPos(&r_dest);
    t.Show(screen);
}
 
void Jeu::Move(int direction)
{
    switch(direction)
    {
        case HAUT :
            t.SetDirection(HAUT);
 
            if(t.GetPosY() -1 < 0)
            {
                break;
            }
 
            if(niveau[t.GetPosY() -1][t.GetPosX()].CompType(MUR))
            {
                break;
            }
 
            if(((niveau[t.GetPosY() -1][t.GetPosX()].CompType(CAISSE)) || (niveau[t.GetPosY() -1][t.GetPosX()].CompType(CAISSE_OK)))
            && ((niveau[t.GetPosY() -2][t.GetPosX()].CompType(MUR)) || (niveau[t.GetPosY() -2][t.GetPosX()].CompType(CAISSE)) || (niveau[t.GetPosY() -2][t.GetPosX()].CompType(CAISSE_OK))))
            {
                break;
            }
 
            t.PousseCaisse(niveau[t.GetPosY() -1][t.GetPosX()], niveau[t.GetPosY() -2][t.GetPosX()]);
 
            r_perso.y -= 1;
        break;
 
        case BAS :
            t.SetDirection(BAS);
 
            if(t.GetPosY() +1 < 0)
            {
                break;
            }
 
            if(niveau[t.GetPosY() +1][t.GetPosX()].CompType(MUR))
            {
                break;
            }
 
            if(((niveau[t.GetPosY() +1][t.GetPosX()].CompType(CAISSE)) || (niveau[t.GetPosY() +1][t.GetPosX()].CompType(CAISSE_OK)))
            && ((niveau[t.GetPosY() +2][t.GetPosX()].CompType(MUR)) || (niveau[t.GetPosY() +2][t.GetPosX()].CompType(CAISSE)) || (niveau[t.GetPosY() +2][t.GetPosX()].CompType(CAISSE_OK))))
            {
                break;
            }
 
            t.PousseCaisse(niveau[t.GetPosY() +1][t.GetPosX()], niveau[t.GetPosY() +2][t.GetPosX()]);
 
            r_perso.y += 1;
        break;
 
        case DROITE :
            t.SetDirection(DROITE);
 
            if(t.GetPosX() +1 < 0)
            {
                break;
            }
 
            if(niveau[t.GetPosY()][t.GetPosX() +1].CompType(MUR))
            {
                break;
            }
 
            if(((niveau[t.GetPosY()][t.GetPosX() +1].CompType(CAISSE)) || (niveau[t.GetPosY()][t.GetPosX() +1].CompType(CAISSE_OK)))
            && ((niveau[t.GetPosY()][t.GetPosX() +2].CompType(MUR)) || (niveau[t.GetPosY()][t.GetPosX() +2].CompType(CAISSE)) || (niveau[t.GetPosY()][t.GetPosX() +2].CompType(CAISSE_OK))))
            {
                break;
            }
 
            t.PousseCaisse(niveau[t.GetPosY()][t.GetPosX() +1], niveau[t.GetPosY()][t.GetPosX() +2]);
 
            r_perso.x += 1;
        break;
 
        case GAUCHE :
            t.SetDirection(GAUCHE);
 
            if(t.GetPosX() -1 < 0)
            {
                break;
            }
 
            if(niveau[t.GetPosY()][t.GetPosX() -1].CompType(MUR))
            {
                break;
            }
 
            if(((niveau[t.GetPosY()][t.GetPosX() -1].CompType(CAISSE)) || (niveau[t.GetPosY()][t.GetPosX() -1].CompType(CAISSE_OK)))
            && ((niveau[t.GetPosY()][t.GetPosX() -2].CompType(MUR)) || (niveau[t.GetPosY()][t.GetPosX() -2].CompType(CAISSE)) || (niveau[t.GetPosY()][t.GetPosX() -2].CompType(CAISSE_OK))))
            {
                break;
            }
 
            t.PousseCaisse(niveau[t.GetPosY()][t.GetPosX() -1], niveau[t.GetPosY()][t.GetPosX() -2]);
 
            r_perso.x -= 1;
        break;
 
        default :
        break;
    }
}
 
void Jeu::Verif_fini()
{
    int i = 0, j = 0;
 
    for(i = 0; i < BLOC_HAUTEUR; i++)
    {
        for(j = 0; j < BLOC_LARGEUR; j++)
        {
            if((niveau[i][j].CompType(CAISSE)) || (niveau[i][j].CompType(CIBLE)))
            {
                fini = true;
            }
            else
            {
                fini = false;
            }
        }
    }
}
 
void Jeu::Vide_terrain()
{
    int i = 0, j = 0;
 
    for(i = 0; i < BLOC_HAUTEUR; i++)
    {
        for(j = 0; j < BLOC_LARGEUR; j++)
        {
            niveau[i][j].SetType(VIDE);
        }
    }
}
level.h
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
#ifndef H_LEVEL
#define H_LEVEL
 
    #include "include.h"
 
    class Level
    {
        private :
 
        std::vector<SDL_Surface*> image;
 
        int curimage;
 
        Bloc type;
 
        SDL_Rect pos;
 
        public :
 
        Level();
        ~Level();
 
        void Init();
        void SetPos(SDL_Rect* p);
        void SetImage(SDL_Surface* mur, SDL_Surface* caisse, SDL_Surface* caisse_ok, SDL_Surface* cible);
        void Show(SDL_Surface* screen);
        void SetType(int t);
 
        bool GetClic(int x, int y);
        bool CompType(Bloc bloc);
 
        Bloc GetType();
    };
 
#endif
level.cpp :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
#include "level.h"
 
Level::Level()
{
    int i = 0;
 
    image.resize(4);
 
    for(i = 0; i < 4; i++)
    {
        image[i] = NULL;
    }
 
    curimage = 0;
 
    pos.h = 0;
    pos.w = 0;
    pos.x = 0;
    pos.y = 0;
}
 
Level::~Level()
{
 
}
 
void Level::Init()
{
    curimage = 0;
    type = VIDE;
}
 
void Level::SetPos(SDL_Rect* p)
{
    pos = *p;
}
 
void Level::SetImage(SDL_Surface* mur, SDL_Surface* caisse, SDL_Surface* caisse_ok, SDL_Surface* cible)
{
    image[0] = mur;
    image[1] = caisse;
    image[2] = caisse_ok;
    image[3] = cible;
}
 
void Level::Show(SDL_Surface* screen)
{
    if(image[curimage])
    {
        SDL_BlitSurface(image[curimage], NULL, screen, &pos);
    }
}
 
bool Level::GetClic(int x, int y)
{
    return ((x > pos.x) && (x < pos.x + pos.w) && (y > pos.y) && (y < pos.y + pos.h));
}
 
Bloc Level::GetType()
{
    return type;
}
 
void Level::SetType(int t)
{
    switch(t)
    {
        case MUR :
            curimage = 0;
        break;
 
        case CAISSE :
            curimage = 1;
        break;
 
        case CAISSE_OK :
            curimage = 2;
        break;
 
        case CIBLE :
            curimage = 3;
        break;
 
        default :
            curimage = -1;
        break;
    }
}
 
bool Level::CompType(Bloc bloc)
{
    return bloc == type;
}
perso.h :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
#ifndef H_PERSO
#define H_PERSO
 
    #include "include.h"
    #include "level.h"
 
    class Perso
    {
        private :
 
        std::vector<SDL_Surface*> image;
 
        int curimage;
 
        SDL_Rect pos;
 
        public :
 
        Perso();
        ~Perso();
 
        void Init();
        void SetImage(SDL_Surface* p_haut, SDL_Surface* p_bas, SDL_Surface* p_droite, SDL_Surface* p_gauche);
        void SetPos(SDL_Rect* p);
        void SetDirection(int direction);
        void Show(SDL_Surface* screen);
        void PousseCaisse(Level &bloc1, Level &bloc2);
 
        int GetPosX();
        int GetPosY();
    };
 
#endif
perso.cpp :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
#include "perso.h"
#include "level.h"
 
Perso::Perso()
{
    int i = 0;
 
    image.resize(4);
 
    for(i = 0; i < 4; i++)
    {
        image[i] = NULL;
    }
 
    curimage = 0;
 
    pos.h = 0;
    pos.w = 0;
    pos.x = 0;
    pos.y = 0;
}
 
void Perso::Init()
{
    curimage = 0;
}
 
void Perso::SetImage(SDL_Surface* p_haut, SDL_Surface* p_bas, SDL_Surface* p_droite, SDL_Surface* p_gauche)
{
    image[HAUT] = p_haut;
    image[BAS] = p_bas;
    image[DROITE] = p_droite;
    image[GAUCHE] = p_gauche;
}
 
void Perso::SetPos(SDL_Rect* p)
{
    pos = *p;
}
 
void Perso::SetDirection(int direction)
{
    curimage = direction;
}
 
void Perso::Show(SDL_Surface* screen)
{
    if(image[curimage])
    {
        SDL_BlitSurface(image[curimage], NULL, screen, &pos);
    }
}
 
void Perso::PousseCaisse(Level &bloc1, Level &bloc2)
{
    if((bloc1.CompType(CAISSE)) || (bloc1.CompType(CAISSE_OK)))
    {
        if(bloc2.CompType(CIBLE))
        {
            bloc2.SetType(CAISSE_OK);
        }
        else
        {
            bloc2.SetType(CAISSE);
        }
 
        if(bloc1.CompType(CAISSE_OK))
        {
            bloc1.SetType(CIBLE);
        }
        else
        {
            bloc1.SetType(VIDE);
        }
    }
}
 
int Perso::GetPosX()
{
    return pos.x;
}
 
int Perso::GetPosY()
{
    return pos.y;
}
J'èspere que vous pourriez m'aider.