Salut tout le monde, depuis quelque jours j'essaye de faire un jeu. Tout marche très bien, mais lorsque j'arrive aux collisions, elle ne marchent pas, pourtant j'ai le même code source que les tutoriels de ce site a propos de la SDL. En fait, lorsque j'essaye mes collisions avec un objet de la meme classe que ma classe Character ca marche, mais lorsque je crée une autre classe pour un element du decor et que je met le meme code source ca ne marche pas et je ne sais vraiment pas pourquoi. Si quelqu'un pourrait m'aider ce serait apprcier.

Voici les codes :

Main.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
 
 
#include "main.h"
#include "Timer.h"
#include "Character.h"
#include "Tree.h"
 
void applyStatus(Character &myChar, SDL_Surface *character, SDL_Surface *screen, SDL_Rect clipRight[], SDL_Rect clipLeft[], SDL_Rect clipUp[], SDL_Rect clipDown[], SDL_Rect clipRightSword[], SDL_Rect clipLeftSword[], SDL_Rect clipUpSword[], SDL_Rect clipDownSword[]);
 
int main(int argc, char** argv)
{
SDL_Surface *screen = NULL, *character = NULL, *tree = NULL;
SDL_Event event;
TTF_Font *font;
 
SDL_Rect clipRight[4], clipLeft[4], clipUp[4], clipDown[4];
SDL_Rect clipRightSword[4], clipLeftSword[4], clipUpSword[4], clipDownSword[4];
 
bool continuer = true;
 
Character myChar(500, 500);
Character otherChar(400, 400);
Tree myTree(600, 600);
Timer fps;
 
SDL_Init(SDL_INIT_VIDEO);
 
screen = SDL_SetVideoMode(SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_BPP, SDL_HWSURFACE | SDL_DOUBLEBUF | SDL_FULLSCREEN);
SDL_WM_SetCaption("Gladiateur", NULL);
 
TTF_Init();
 
font = TTF_OpenFont("CaslonBold.ttf", 28);
 
character = loadImage("spritehero.bmp");
 
tree = loadImage("arbre.bmp");
 
setClips(clipRight, clipLeft, clipUp, clipDown, clipRightSword, clipLeftSword, clipUpSword, clipDownSword);
 
while(continuer)
{
fps.start();
 
while(SDL_PollEvent(&event))
{
if(event.type == SDL_QUIT)
{
continuer = false;
}
 
if(event.type == SDL_KEYDOWN)
{
if(event.key.keysym.sym == SDLK_ESCAPE)
{
continuer = false;
}
}
 
myChar.handleEvent(event, myChar);
}
 
SDL_FillRect(screen, NULL, SDL_MapRGB(screen->format, 255, 255, 255));
 
myChar.move(myTree.getRects());
 
applySurface(otherChar.getX(), otherChar.getY(), character, screen, &clipDownSword[0]);
 
applySurface(myTree.getX(), myTree.getY(), tree, screen);
 
applyStatus(myChar, character, screen, clipRight, clipLeft, clipUp, clipDown, clipRightSword, clipLeftSword, clipUpSword, clipDownSword);
 
SDL_Flip(screen);
 
while(fps.getTicks() < 3000 / FRAMES_PER_SECOND)
{
 
}
}
 
SDL_FreeSurface(screen);
SDL_FreeSurface(character);
 
TTF_CloseFont(font);
 
TTF_Quit();
 
SDL_Quit();
 
return 0;
}
 
SDL_Surface *loadImage(std::string filename)
{
SDL_Surface *optimizedImage = NULL, *loadedImage = NULL;
 
loadedImage = IMG_Load(filename.c_str());
 
optimizedImage = SDL_DisplayFormat(loadedImage);
SDL_SetColorKey(optimizedImage, SDL_SRCCOLORKEY | SDL_HWACCEL, SDL_MapRGB(optimizedImage->format, 255, 0, 0));
 
SDL_FreeSurface(loadedImage);
 
return optimizedImage;
}
 
void applySurface(int x, int y, SDL_Surface *image, SDL_Surface *destination, SDL_Rect *clip)
{
SDL_Rect offset;
 
offset.x = x;
offset.y = y;
 
SDL_BlitSurface(image, clip, destination, &offset);
}
 
void applyStatus(Character &myChar, SDL_Surface *character, SDL_Surface *screen, SDL_Rect clipRight[], SDL_Rect clipLeft[], SDL_Rect clipUp[], SDL_Rect clipDown[], SDL_Rect clipRightSword[], SDL_Rect clipLeftSword[], SDL_Rect clipUpSword[], SDL_Rect clipDownSword[])
{
Timer fpsSword;
 
if(myChar.getStatus() == CHAR_RIGHT)
applySurface(myChar.getX(), myChar.getY(), character, screen, &clipRight[myChar.getFrame()]);
 
else if(myChar.getStatus() == CHAR_LEFT)
applySurface(myChar.getX(), myChar.getY(), character, screen, &clipLeft[myChar.getFrame()]);
 
else if(myChar.getStatus() == CHAR_UP)
applySurface(myChar.getX(), myChar.getY(), character, screen, &clipUp[myChar.getFrame()]);
 
else if(myChar.getStatus() == CHAR_DOWN)
applySurface(myChar.getX(), myChar.getY(), character, screen, &clipDown[myChar.getFrame()]);
 
else if(myChar.getStatus() == CHAR_RIGHTSWORD)
{
for(int i = 0 ; i < 4 ; i++)
{
fpsSword.start();
 
SDL_FillRect(screen, NULL, SDL_MapRGB(screen->format, 255, 255, 255));
 
applySurface(myChar.getX(), myChar.getY(), character, screen, &clipRightSword[i]);
 
SDL_Flip(screen);
 
while(fpsSword.getTicks() < 1500 / FRAMES_PER_SECOND)
{
 
}
}
 
myChar.setStatus(CHAR_RIGHT);
}
 
else if(myChar.getStatus() == CHAR_LEFTSWORD)
{
for(int i = 0 ; i < 4 ; i++)
{
fpsSword.start();
 
SDL_FillRect(screen, NULL, SDL_MapRGB(screen->format, 255, 255, 255));
 
applySurface(myChar.getX(), myChar.getY(), character, screen, &clipLeftSword[i]);
 
SDL_Flip(screen);
 
while(fpsSword.getTicks() < 1500 / FRAMES_PER_SECOND)
{
 
}
}
 
myChar.setStatus(CHAR_LEFT);
}
 
else if(myChar.getStatus() == CHAR_UPSWORD)
{
for(int i = 0 ; i < 4 ; i++)
{
fpsSword.start();
 
SDL_FillRect(screen, NULL, SDL_MapRGB(screen->format, 255, 255, 255));
 
applySurface(myChar.getX(), myChar.getY(), character, screen, &clipUpSword[i]);
 
SDL_Flip(screen);
 
while(fpsSword.getTicks() < 3000 / FRAMES_PER_SECOND)
{
 
}
}
 
myChar.setStatus(CHAR_UP);
}
 
else if(myChar.getStatus() == CHAR_DOWNSWORD)
{
for(int i = 0 ; i < 4 ; i++)
{
fpsSword.start();
 
SDL_FillRect(screen, NULL, SDL_MapRGB(screen->format, 255, 255, 255));
 
applySurface(myChar.getX(), myChar.getY(), character, screen, &clipDownSword[i]);
 
SDL_Flip(screen);
 
while(fpsSword.getTicks() < 3000 / FRAMES_PER_SECOND)
{
 
}
}
 
myChar.setStatus(CHAR_DOWN);
}
}
Main.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
 
 
#ifndef DEF_MAIN
#define DEF_MAIN
 
#include <iostream>
#include <string>
#include <fstream>
#include <vector>
#include <SDL/SDL.h>
#include <SDL_image.h>
#include <SDL_ttf.h>
 
#include "constantes.h"
 
SDL_Surface *loadImage(std::string filename);
void applySurface(int x, int y, SDL_Surface *image, SDL_Surface *destination, SDL_Rect *clip = NULL);
 
#endif
Character.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
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
 
 
#include "Character.h"
 
using namespace std;
 
Character::Character(int x, int y)
{
m_x = x;
m_y = y;
 
m_xVel = 0;
m_yVel = 0;
 
m_box.resize(1);
 
m_box[0].w = 50;
m_box[0].h = 50;
 
m_frame = 0;
 
m_status = CHAR_DOWN;
 
m_shiftBox();
}
 
void Character::attack(Character &myChar)
{
if(myChar.getStatus() == CHAR_RIGHT)
{
m_status = CHAR_RIGHTSWORD;
}
 
else if(myChar.getStatus() == CHAR_LEFT)
{
m_status = CHAR_LEFTSWORD;
}
 
else if(myChar.getStatus() == CHAR_UP)
{
m_status = CHAR_UPSWORD;
}
 
else if(myChar.getStatus() == CHAR_DOWN)
{
m_status = CHAR_DOWNSWORD;
}
}
 
void Character::handleEvent(SDL_Event event, Character &myChar)
{
if(event.type == SDL_KEYDOWN)
{
switch(event.key.keysym.sym)
{
case SDLK_RIGHT:
m_xVel += CHAR_SPEED;
break;
case SDLK_LEFT:
m_xVel -= CHAR_SPEED;
break;
case SDLK_UP:
m_yVel -= CHAR_SPEED;
break;
case SDLK_DOWN:
m_yVel += CHAR_SPEED;
break;
case SDLK_SPACE:
myChar.attack(myChar);
break;
}
}
 
if(event.type == SDL_KEYUP)
{
switch(event.key.keysym.sym)
{
case SDLK_RIGHT:
m_xVel -= CHAR_SPEED;
break;
case SDLK_LEFT:
m_xVel += CHAR_SPEED;
break;
case SDLK_UP:
m_yVel += CHAR_SPEED;
break;
case SDLK_DOWN:
m_yVel -= CHAR_SPEED;
break;
}
}
}
 
void Character::move(vector<SDL_Rect> &rects)
{
m_x += m_xVel;
 
m_shiftBox();
 
if(m_x < 0)
{
m_x = 0;
m_shiftBox();
}
 
if(m_x + CHAR_WIDTH / 16 > SCREEN_WIDTH)
{
m_x = SCREEN_WIDTH - CHAR_WIDTH / 16;
m_shiftBox();
}
 
if(checkCollision(m_box, rects))
{
m_x -= m_xVel;
m_shiftBox();
}
 
m_y += m_yVel;
 
m_shiftBox();
 
if(m_y < 0)
{
m_y = 0;
m_shiftBox();
}
 
if(m_y + CHAR_HEIGHT / 2 > SCREEN_HEIGHT)
{
m_y = SCREEN_HEIGHT - CHAR_HEIGHT / 2;
m_shiftBox();
}
 
if(checkCollision(m_box, rects))
{
m_y -= m_yVel;
m_shiftBox();
}
 
if(m_xVel < 0)
{
m_status = CHAR_LEFT;
m_frame++;
}
 
else if(m_xVel > 0)
{
m_status = CHAR_RIGHT;
m_frame++;
}
 
else if(m_yVel < 0)
{
m_status = CHAR_UP;
m_frame++;
}
 
else if(m_yVel > 0)
{
m_status = CHAR_DOWN;
m_frame++;
}
 
else
{
m_frame = 0;
}
 
if(m_frame >= 4)
{
m_frame = 0;
}
}
 
void Character::m_shiftBox()
{
int r = 0;
 
for(int set = 0 ; set < m_box.size() ; set++)
{
m_box[set].x = m_x + (CHAR_WIDTH - m_box[set].w) / 2;
 
m_box[set].y = m_y + r;
 
r += m_box[set].h;
}
}
 
vector<SDL_Rect> &Character::getRects()
{
return m_box;
}
 
void Character::setStatus(int newStatus)
{
m_status = newStatus;
}
 
int Character::getX()
{
return m_x;
}
 
int Character::getY()
{
return m_y;
}
 
int Character::getFrame()
{
return m_frame;
}
 
int Character::getStatus()
{
return m_status;
}
 
void setClips(SDL_Rect clipRight[], SDL_Rect clipLeft[] ,SDL_Rect clipUp[], SDL_Rect clipDown[], SDL_Rect clipRightSword[], SDL_Rect clipLeftSword[], SDL_Rect clipUpSword[], SDL_Rect clipDownSword[])
{
clipRight[0].x = 0;
clipRight[0].y = 0;
clipRight[0].w = CHAR_WIDTH / 16;
clipRight[0].h = CHAR_HEIGHT / 2;
 
clipRight[1].x = 50;
clipRight[1].y = 0;
clipRight[1].w = CHAR_WIDTH / 16;
clipRight[1].h = CHAR_HEIGHT / 2;
 
clipRight[2].x = 100;
clipRight[2].y = 0;
clipRight[2].w = CHAR_WIDTH / 16;
clipRight[2].h = CHAR_HEIGHT / 2;
 
clipRight[3].x = 150;
clipRight[3].y = 0;
clipRight[3].w = CHAR_WIDTH / 16;
clipRight[3].h = CHAR_HEIGHT / 2;
 
clipLeft[0].x = 200;
clipLeft[0].y = 0;
clipLeft[0].w = CHAR_WIDTH / 16;
clipLeft[0].h = CHAR_HEIGHT / 2;
 
clipLeft[1].x = 250;
clipLeft[1].y = 0;
clipLeft[1].w = CHAR_WIDTH / 16;
clipLeft[1].h = CHAR_HEIGHT / 2;
 
clipLeft[2].x = 300;
clipLeft[2].y = 0;
clipLeft[2].w = CHAR_WIDTH / 16;
clipLeft[2].h = CHAR_HEIGHT / 2;
 
clipLeft[3].x = 350;
clipLeft[3].y = 0;
clipLeft[3].w = CHAR_WIDTH / 16;
clipLeft[3].h = CHAR_HEIGHT / 2;
 
clipDown[0].x = 400;
clipDown[0].y = 0;
clipDown[0].w = CHAR_WIDTH / 16;
clipDown[0].h = CHAR_HEIGHT / 2;
 
clipDown[1].x = 450;
clipDown[1].y = 0;
clipDown[1].w = CHAR_WIDTH / 16;
clipDown[1].h = CHAR_HEIGHT / 2;
 
clipDown[2].x = 500;
clipDown[2].y = 0;
clipDown[2].w = CHAR_WIDTH / 16;
clipDown[2].h = CHAR_HEIGHT / 2;
 
clipDown[3].x = 550;
clipDown[3].y = 0;
clipDown[3].w = CHAR_WIDTH / 16;
clipDown[3].h = CHAR_HEIGHT / 2;
 
clipUp[0].x = 600;
clipUp[0].y = 0;
clipUp[0].w = CHAR_WIDTH / 16;
clipUp[0].h = CHAR_HEIGHT / 2;
 
clipUp[1].x = 650;
clipUp[1].y = 0;
clipUp[1].w = CHAR_WIDTH / 16;
clipUp[1].h = CHAR_HEIGHT / 2;
 
clipUp[2].x = 700;
clipUp[2].y = 0;
clipUp[2].w = CHAR_WIDTH / 16;
clipUp[2].h = CHAR_HEIGHT / 2;
 
clipUp[3].x = 750;
clipUp[3].y = 0;
clipUp[3].w = CHAR_WIDTH / 16;
clipUp[3].h = CHAR_HEIGHT / 2;
 
clipRightSword[0].x = 0;
clipRightSword[0].y = CHAR_HEIGHT / 2;
clipRightSword[0].w = CHAR_WIDTH / 16;
clipRightSword[0].h = CHAR_HEIGHT / 2;
 
clipRightSword[1].x = 50;
clipRightSword[1].y = CHAR_HEIGHT / 2;
clipRightSword[1].w = CHAR_WIDTH / 16;
clipRightSword[1].h = CHAR_HEIGHT / 2;
 
clipRightSword[2].x = 100;
clipRightSword[2].y = CHAR_HEIGHT / 2;
clipRightSword[2].w = CHAR_WIDTH / 16;
clipRightSword[2].h = CHAR_HEIGHT / 2;
 
clipRightSword[3].x = 150;
clipRightSword[3].y = CHAR_HEIGHT / 2;
clipRightSword[3].w = CHAR_WIDTH / 16;
clipRightSword[3].h = CHAR_HEIGHT / 2;
 
clipLeftSword[0].x = 200;
clipLeftSword[0].y = CHAR_HEIGHT / 2;
clipLeftSword[0].w = CHAR_WIDTH / 16;
clipLeftSword[0].h = CHAR_HEIGHT / 2;
 
clipLeftSword[1].x = 250;
clipLeftSword[1].y = CHAR_HEIGHT / 2;
clipLeftSword[1].w = CHAR_WIDTH / 16;
clipLeftSword[1].h = CHAR_HEIGHT / 2;
 
clipLeftSword[2].x = 300;
clipLeftSword[2].y = CHAR_HEIGHT / 2;
clipLeftSword[2].w = CHAR_WIDTH / 16;
clipLeftSword[2].h = CHAR_HEIGHT / 2;
 
clipLeftSword[3].x = 350;
clipLeftSword[3].y = CHAR_HEIGHT / 2;
clipLeftSword[3].w = CHAR_WIDTH / 16;
clipLeftSword[3].h = CHAR_HEIGHT / 2;
 
clipDownSword[0].x = 400;
clipDownSword[0].y = CHAR_HEIGHT / 2;
clipDownSword[0].w = CHAR_WIDTH / 16;
clipDownSword[0].h = CHAR_HEIGHT / 2;
 
clipDownSword[1].x = 450;
clipDownSword[1].y = CHAR_HEIGHT / 2;
clipDownSword[1].w = CHAR_WIDTH / 16;
clipDownSword[1].h = CHAR_HEIGHT / 2;
 
clipDownSword[2].x = 500;
clipDownSword[2].y = CHAR_HEIGHT / 2;
clipDownSword[2].w = CHAR_WIDTH / 16;
clipDownSword[2].h = CHAR_HEIGHT / 2;
 
clipDownSword[3].x = 550;
clipDownSword[3].y = CHAR_HEIGHT / 2;
clipDownSword[3].w = CHAR_WIDTH / 16;
clipDownSword[3].h = CHAR_HEIGHT / 2;
 
clipUpSword[0].x = 600;
clipUpSword[0].y = CHAR_HEIGHT / 2;
clipUpSword[0].w = CHAR_WIDTH / 16;
clipUpSword[0].h = CHAR_HEIGHT / 2;
 
clipUpSword[1].x = 650;
clipUpSword[1].y = CHAR_HEIGHT / 2;
clipUpSword[1].w = CHAR_WIDTH / 16;
clipUpSword[1].h = CHAR_HEIGHT / 2;
 
clipUpSword[2].x = 700;
clipUpSword[2].y = CHAR_HEIGHT / 2;
clipUpSword[2].w = CHAR_WIDTH / 16;
clipUpSword[2].h = CHAR_HEIGHT / 2;
 
clipUpSword[3].x = 750;
clipUpSword[3].y = CHAR_HEIGHT / 2;
clipUpSword[3].w = CHAR_WIDTH / 16;
clipUpSword[3].h = CHAR_HEIGHT / 2;
}
 
bool checkCollision(vector<SDL_Rect> &A, vector<SDL_Rect> &B)
{
int rightA, rightB;
int leftA, leftB;
int topA, topB;
int downA, downB;
 
for(int Abox = 0 ; Abox < A.size() ; Abox++)
{
rightA = A[Abox].x + A[Abox].w;
leftA = A[Abox].x;
topA = A[Abox].y;
downA = A[Abox].y + A[Abox].h;
 
for(int Bbox = 0 ; Bbox < B.size() ; Bbox++)
{
rightB = B[Bbox].x + B[Bbox].w;
leftB = B[Bbox].x;
topB = B[Bbox].y;
downB = B[Bbox].y + B[Bbox].h;
 
if(((rightA <= leftB) || (leftA >= rightB) || (topA >= downB) || (downA <= topB)) == false)
{
return true;
}
}
}
 
return false;
}
Character.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
36
37
 
 
#ifndef DEF_CHARACTER
#define DEF_CHARACTER
 
#include "main.h"
#include "Timer.h"
 
class Character
{
public:
Character(int x, int y);
void attack(Character &myChar);
void handleEvent(SDL_Event event, Character &myChar);
void move(std::vector<SDL_Rect> &rects);
std::vector<SDL_Rect> &getRects();
 
void setStatus(int newStatus);
int getX();
int getY();
int getStatus();
int getFrame();
 
private:
int m_x, m_y;
int m_xVel, m_yVel;
int m_status;
int m_frame;
 
std::vector<SDL_Rect> m_box;
void m_shiftBox();
};
 
void setClips(SDL_Rect clipRight[], SDL_Rect clipLeft[] ,SDL_Rect clipUp[], SDL_Rect clipDown[], SDL_Rect clipRightSword[], SDL_Rect clipLeftSword[], SDL_Rect clipUpSword[], SDL_Rect clipDownSword[]);
bool checkCollision(std::vector<SDL_Rect> &A, std::vector<SDL_Rect> &B);
 
#endif
Tree.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
 
 
#include "Tree.h"
 
using namespace std;
 
Tree::Tree(int x, int y)
{
m_x = x;
m_y = y;
 
m_box.resize(1);
 
m_box[0].w = 50;
m_box[0].h = 50;
}
 
vector<SDL_Rect> &Tree::getRects()
{
return m_box;
}
 
int Tree::getX()
{
return m_x;
}
 
int Tree::getY()
{
return m_y;
}
Tree.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
 
 
#ifndef DEF_TREE
#define DEF_TREE
 
#include "main.h"
 
class Tree
{
public:
Tree(int x, int y);
std::vector<SDL_Rect> &getRects();
 
int getX();
int getY();
 
private:
int m_x, m_y;
std::vector<SDL_Rect> m_box;
};
 
#endif
Constantes.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
 
 
#ifndef DEF_CONSTANTES
#define DEF_CONSTANTES
 
const int SCREEN_WIDTH = 1280;
const int SCREEN_HEIGHT = 960;
const int SCREEN_BPP = 32;
 
const int FRAMES_PER_SECOND = 30;
 
const int CHAR_WIDTH = 800;
const int CHAR_HEIGHT = 100;
 
const int CHAR_SPEED = 15;
 
enum {CHAR_RIGHT, CHAR_LEFT, CHAR_UP, CHAR_DOWN, CHAR_RIGHTSWORD, CHAR_LEFTSWORD, CHAR_UPSWORD, CHAR_DOWNSWORD};
 
#endif

Et il y a aussi les codes pour le timer, mais je ne crois pas qu'ils aient un rapport, si vous voulez que je les mettent dite le moi et je vais le faire.

Merci à l'avance!!!