Merge lp:~flozz/damn-monkey/game-management into lp:damn-monkey
- game-management
- Merge into trunk
Proposed by
Fabien LOISON
Status: | Merged |
---|---|
Approved by: | Fabien LOISON |
Approved revision: | 37 |
Merged at revision: | 21 |
Proposed branch: | lp:~flozz/damn-monkey/game-management |
Merge into: | lp:damn-monkey |
Diff against target: |
1303 lines (+1205/-5) 9 files modified
Makefile (+9/-2) levels/level_01.map (+17/-0) pixmaps/jumpman.sprite (+9/-0) src/game.c (+945/-0) src/game.h (+139/-0) src/levels/level_01.c (+58/-0) src/levels/level_01.h (+20/-0) src/main.c (+7/-2) src/parser.c (+1/-1) |
To merge this branch: | bzr merge lp:~flozz/damn-monkey/game-management |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Fabien LOISON | Pending | ||
Review via email: mp+60277@code.launchpad.net |
Commit message
Description of the change
To post a comment you must log in.
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'Makefile' |
2 | --- Makefile 2011-05-06 15:04:27 +0000 |
3 | +++ Makefile 2011-05-07 13:57:29 +0000 |
4 | @@ -11,8 +11,8 @@ |
5 | EXEC = damn-monkey |
6 | |
7 | |
8 | -$(EXEC): main.o main_menu.o main_functions.o menu.o credits.o refresh.o parser.o sprite.o pause_menu.o |
9 | - $(CC) -o bin/$(EXEC) $(LDFLAGS) obj/main.o obj/main_menu.o obj/main_functions.o obj/menu.o obj/credits.o obj/refresh.o obj/parser.o obj/sprite.o obj/pause_menu.o |
10 | +$(EXEC): main.o main_menu.o main_functions.o menu.o credits.o refresh.o parser.o sprite.o game.o level_01.o pause_menu.o |
11 | + $(CC) -o bin/$(EXEC) $(LDFLAGS) obj/main.o obj/main_menu.o obj/main_functions.o obj/menu.o obj/credits.o obj/refresh.o obj/parser.o obj/sprite.o obj/game.o obj/level_01.o obj/pause_menu.o |
12 | |
13 | main.o: src/main.c |
14 | $(CC) $(CFLAGS) -o obj/main.o -c src/main.c |
15 | @@ -38,9 +38,16 @@ |
16 | sprite.o: src/sprite.c |
17 | $(CC) $(CFLAGS) -o obj/sprite.o -c src/sprite.c |
18 | |
19 | +game.o: src/game.c |
20 | + $(CC) $(CFLAGS) -o obj/game.o -c src/game.c |
21 | + |
22 | +level_01.o: src/levels/level_01.c |
23 | + $(CC) $(CFLAGS) -o obj/level_01.o -c src/levels/level_01.c |
24 | + |
25 | pause_menu.o: src/pause_menu.c |
26 | $(CC) $(CFLAGS) -o obj/pause_menu.o -c src/pause_menu.c |
27 | |
28 | + |
29 | clean: |
30 | rm -f obj/* |
31 | rm -f bin/* |
32 | |
33 | === added directory 'levels' |
34 | === added file 'levels/level_01.map' |
35 | --- levels/level_01.map 1970-01-01 00:00:00 +0000 |
36 | +++ levels/level_01.map 2011-05-07 13:57:29 +0000 |
37 | @@ -0,0 +1,17 @@ |
38 | +jumpman-start-left ; 762 ; 557 ; 0 ; 0 ; |
39 | +finish-collide ; 462 ; 88 ; 491 ; 91 ; |
40 | +platform-collide ; 799 ; 558 ; 661 ; 558 ; |
41 | +platform-collide ; 661 ; 558 ; 13 ; 542 ; |
42 | +platform-collide ; 135 ; 467 ; 787 ; 451 ; |
43 | +platform-collide ; 665 ; 382 ; 13 ; 366 ; |
44 | +platform-collide ; 135 ; 291 ; 787 ; 275 ; |
45 | +platform-collide ; 667 ; 206 ; 297 ; 175 ; |
46 | +platform-collide ; 297 ; 175 ; 8 ; 175 ; |
47 | +platform-collide ; 297 ; 175 ; 297 ; 117 ; |
48 | +ladder-collide ; 156 ; 465 ; 185 ; 547 ; |
49 | +ladder-collide ; 394 ; 374 ; 423 ; 462 ; |
50 | +ladder-collide ; 600 ; 379 ; 629 ; 457 ; |
51 | +ladder-collide ; 275 ; 286 ; 304 ; 374 ; |
52 | +ladder-collide ; 149 ; 289 ; 178 ; 371 ; |
53 | +ladder-collide ; 604 ; 200 ; 633 ; 280 ; |
54 | +ladder-collide ; 462 ; 90 ; 491 ; 192 ; |
55 | |
56 | === added file 'pixmaps/jumpman.png' |
57 | Binary files pixmaps/jumpman.png 1970-01-01 00:00:00 +0000 and pixmaps/jumpman.png 2011-05-07 13:57:29 +0000 differ |
58 | === added file 'pixmaps/jumpman.sprite' |
59 | --- pixmaps/jumpman.sprite 1970-01-01 00:00:00 +0000 |
60 | +++ pixmaps/jumpman.sprite 2011-05-07 13:57:29 +0000 |
61 | @@ -0,0 +1,9 @@ |
62 | +look-right ; 0 ; 0 ; 23 ; 31 ; 1 ; 0 ; |
63 | +walk-right ; 24 ; 0 ; 29 ; 31 ; 2 ; 100 ; |
64 | +look-left ; 0 ; 32 ; 23 ; 31 ; 1 ; 0 ; |
65 | +walk-left ; 24 ; 32 ; 29 ; 31 ; 2 ; 100 ; |
66 | +jump-right ; 54 ; 0 ; 29 ; 31 ; 1 ; 0 ; |
67 | +jump-left ; 54 ; 32 ; 29 ; 31 ; 1 ; 0 ; |
68 | +ladder ; 24 ; 64 ; 23 ; 31 ; 1 ; 0 ; |
69 | +walk-ladder ; 0 ; 64 ; 23 ; 31 ; 2 ; 120 ; |
70 | +dead ; 0 ; 96 ; 31 ; 31 ; 4 ; 100 ; |
71 | |
72 | === added file 'pixmaps/level_01.png' |
73 | Binary files pixmaps/level_01.png 1970-01-01 00:00:00 +0000 and pixmaps/level_01.png 2011-05-07 13:57:29 +0000 differ |
74 | === added file 'src/game.c' |
75 | --- src/game.c 1970-01-01 00:00:00 +0000 |
76 | +++ src/game.c 2011-05-07 13:57:29 +0000 |
77 | @@ -0,0 +1,945 @@ |
78 | +/*************************************************************************** |
79 | +* * |
80 | +* This file is part of Damn Monkey * |
81 | +* * |
82 | +* Copyright (C) 2010 - 2011 Fabien LOISON, Mathilde BOUTIGNY, * |
83 | +* Vincent PEYROUSE, Germain CARRÉ and Matthis FRENAY * |
84 | +* * |
85 | +* Damn Monkey is free software: you can redistribute it and/or modify * |
86 | +* it under the terms of the GNU General Public License as published by * |
87 | +* the Free Software Foundation, either version 3 of the License, or * |
88 | +* (at your option) any later version. * |
89 | +* * |
90 | +* This program is distributed in the hope that it will be useful, * |
91 | +* but WITHOUT ANY WARRANTY; without even the implied warranty of * |
92 | +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * |
93 | +* GNU General Public License for more details. * |
94 | +* * |
95 | +* You should have received a copy of the GNU General Public License * |
96 | +* along with this program. If not, see <http://www.gnu.org/licenses/>. * |
97 | +* * |
98 | +***************************************************************************/ |
99 | + |
100 | + |
101 | +/** |
102 | + * \file game.c |
103 | + * \brief Contain all the principal mechanism of the game (Jumpan moves,...) |
104 | + */ |
105 | + |
106 | + |
107 | +#include "game.h" |
108 | + |
109 | + |
110 | +/** |
111 | + * \fn void init_game() |
112 | + * \brief Initialize the game. |
113 | + * |
114 | + * This function Initialize the game and must be called only once. |
115 | + */ |
116 | +void init_game() |
117 | +{ |
118 | + //Init game vars |
119 | + GAME_SPEED = 1; |
120 | + GAME_STATE = GAME_STATE_NONE; |
121 | + //Init Jumpman |
122 | + JUMPMAN.pos_x = 42; |
123 | + JUMPMAN.pos_y = 42; |
124 | + JUMPMAN.movement = SPRITE_LOOK_RIGHT; |
125 | + JUMPMAN.sprite = new_sprite("jumpman"); |
126 | + JUMPMAN.platform_collide.shape = COLLIDE_POINT; |
127 | + JUMPMAN.platform_collide.x2 = 0; |
128 | + JUMPMAN.platform_collide.y2 = 0; |
129 | + JUMPMAN.platform_collide.shape = COLLIDE_POINT; |
130 | + JUMPMAN.enemy_collide.shape = COLLIDE_RECT; |
131 | + update_jumpman(); |
132 | +} |
133 | + |
134 | + |
135 | +/** |
136 | + * \fn void update_jumpman() |
137 | + * \brief Update all the informations about Jumman (collides points, position,...). |
138 | + * This function must be called after each modifications made on Jumpman. |
139 | + */ |
140 | +void update_jumpman() |
141 | +{ |
142 | + //Check the Jumpman position (Jumpman must stay in the screen area). |
143 | + if (JUMPMAN.pos_x <= 0) |
144 | + { |
145 | + JUMPMAN.pos_x = 1; |
146 | + } |
147 | + else if (JUMPMAN.pos_y <= 0) |
148 | + { |
149 | + JUMPMAN.pos_y = 1; |
150 | + } |
151 | + else if (JUMPMAN.pos_x > (800 - JUMPMAN.sprite->items[JUMPMAN.movement].w)) |
152 | + { |
153 | + JUMPMAN.pos_x = 800 - JUMPMAN.sprite->items[JUMPMAN.movement].w; |
154 | + } |
155 | + else if (JUMPMAN.pos_y > (600 - JUMPMAN.sprite->items[JUMPMAN.movement].h)) |
156 | + { |
157 | + JUMPMAN.pos_y = 600 - JUMPMAN.sprite->items[JUMPMAN.movement].h; |
158 | + } |
159 | + //Push the variables in the DM_Sprite object |
160 | + JUMPMAN.sprite->screen_pos.x = JUMPMAN.pos_x; |
161 | + JUMPMAN.sprite->screen_pos.y = JUMPMAN.pos_y; |
162 | + JUMPMAN.sprite->current_mov = JUMPMAN.movement; |
163 | + //Update the collide point and rect |
164 | + if (JUMPMAN.sprite->items[JUMPMAN.movement].n > 0) |
165 | + { |
166 | + //Platform collide point |
167 | + JUMPMAN.platform_collide.x1 = JUMPMAN.pos_x + JUMPMAN.sprite->items[JUMPMAN.movement].w / 2; |
168 | + JUMPMAN.platform_collide.y1 = JUMPMAN.pos_y + JUMPMAN.sprite->items[JUMPMAN.movement].h; |
169 | + //Enemies collide rect |
170 | + JUMPMAN.enemy_collide.x1 = JUMPMAN.pos_x; |
171 | + JUMPMAN.enemy_collide.y1 = JUMPMAN.pos_y; |
172 | + JUMPMAN.enemy_collide.x2 = JUMPMAN.pos_x + JUMPMAN.sprite->items[JUMPMAN.movement].w; |
173 | + JUMPMAN.enemy_collide.y2 = JUMPMAN.pos_y + JUMPMAN.sprite->items[JUMPMAN.movement].h; |
174 | + } |
175 | + else |
176 | + { |
177 | + //Platform collide point |
178 | + JUMPMAN.platform_collide.x1 = 0; |
179 | + JUMPMAN.platform_collide.y1 = 0; |
180 | + //Enemies collide rect |
181 | + JUMPMAN.enemy_collide.x1 = 0; |
182 | + JUMPMAN.enemy_collide.y1 = 0; |
183 | + JUMPMAN.enemy_collide.x2 = 0; |
184 | + JUMPMAN.enemy_collide.y2 = 0; |
185 | + } |
186 | +} |
187 | + |
188 | + |
189 | +/** |
190 | + * \fn int lets_play_yeah(SDL_Surface *screen, DM_Map *map) |
191 | + * \brief This is the main loop of the game. |
192 | + * |
193 | + * This function control the Jumpman moves, its collides with platforms, |
194 | + * the game status (Playing ? Paused ? Died ?...). |
195 | + * |
196 | + * \param screen The main surface. |
197 | + * \param map The DM_Map that contain collides and other informations about the |
198 | + * current level. |
199 | + * |
200 | + * \return Returns the game status (GAME_STATE_LEVEL_COMPLETED, GAME_STATE_LIFE_LOST). |
201 | + */ |
202 | +int lets_play_yeah(SDL_Surface *screen, DM_Map *map) { |
203 | + //Disable the key repetition |
204 | + SDL_EnableKeyRepeat(0, 0); |
205 | + //Initialize the GAME_STATE variable |
206 | + GAME_STATE = GAME_STATE_PLAYING; |
207 | + //Set the start position of Jumpman |
208 | + JUMPMAN.movement = map->start_look; |
209 | + JUMPMAN.pos_x = map->start_point_x - JUMPMAN.sprite->items[JUMPMAN.movement].w / 2; |
210 | + JUMPMAN.pos_y = map->start_point_y - JUMPMAN.sprite->items[JUMPMAN.movement].h; |
211 | + update_jumpman(); |
212 | + //Reference Jumman in the global refresh |
213 | + int jumpman_refresh = ref_object(&layer_active, JUMPMAN.sprite, sprite_cb); |
214 | + //Declaration of some variables |
215 | + int horiz_move = HORIZ_MOVE_NONE_R; |
216 | + int vert_move = VERT_MOVE_NONE; |
217 | + if (JUMPMAN.movement == SPRITE_LOOK_LEFT) |
218 | + { |
219 | + horiz_move = HORIZ_MOVE_NONE_L; |
220 | + } |
221 | + else |
222 | + { |
223 | + horiz_move = HORIZ_MOVE_NONE_R; |
224 | + } |
225 | + int jump = JUMP_NONE; |
226 | + int jump_y_start = 0; |
227 | + SDL_Event event; |
228 | + //The main loop of the game... LET'S GO ! :) |
229 | + while (GAME_STATE == GAME_STATE_PLAYING || GAME_STATE == GAME_STATE_PAUSED) |
230 | + { |
231 | + //Handle key events |
232 | + if (SDL_PollEvent(&event) && GAME_STATE == GAME_STATE_PLAYING) |
233 | + { |
234 | + //Key pressed |
235 | + if (event.type == SDL_KEYDOWN) |
236 | + { |
237 | + switch (event.key.keysym.sym) |
238 | + { |
239 | + case SDLK_ESCAPE: |
240 | + GAME_STATE = GAME_STATE_PAUSED; |
241 | + switch (pause_menu(screen)) |
242 | + { |
243 | + case 0: |
244 | + GAME_STATE = GAME_STATE_PLAYING; //Continue |
245 | + break; |
246 | + case 1: |
247 | + GAME_STATE = GAME_STATE_NONE; //Stop |
248 | + break; |
249 | + case 2: |
250 | + exit(EXIT_SUCCESS); //Quit |
251 | + break; |
252 | + default: |
253 | + GAME_STATE = GAME_STATE_PLAYING; |
254 | + printf("W: Unhandled item for pause menu.\n"); |
255 | + break; |
256 | + } |
257 | + break; |
258 | + case SDLK_LEFT: |
259 | + horiz_move = HORIZ_MOVE_LEFT; |
260 | + break; |
261 | + case SDLK_RIGHT: |
262 | + horiz_move = HORIZ_MOVE_RIGHT; |
263 | + break; |
264 | + case SDLK_UP: |
265 | + if (vert_move == VERT_MOVE_NONE) { |
266 | + if (check_ladder_bottom_collides(&JUMPMAN.platform_collide, map)) |
267 | + { |
268 | + vert_move = VERT_MOVE_UP; |
269 | + } |
270 | + } |
271 | + else |
272 | + { |
273 | + if (check_ladder_collides(&JUMPMAN.platform_collide, map)) |
274 | + { |
275 | + vert_move = VERT_MOVE_UP; |
276 | + } |
277 | + } |
278 | + break; |
279 | + case SDLK_DOWN: |
280 | + if (vert_move == VERT_MOVE_NONE) { |
281 | + if (check_ladder_top_collides(&JUMPMAN.platform_collide, map)) |
282 | + { |
283 | + vert_move = VERT_MOVE_DOWN; |
284 | + } |
285 | + } |
286 | + else |
287 | + { |
288 | + if (check_ladder_collides(&JUMPMAN.platform_collide, map)) |
289 | + { |
290 | + vert_move = VERT_MOVE_DOWN; |
291 | + } |
292 | + } |
293 | + break; |
294 | + case SDLK_SPACE: |
295 | + if (!jump && vert_move == VERT_MOVE_NONE) |
296 | + { |
297 | + jump = JUMP_UP; |
298 | + jump_y_start = JUMPMAN.pos_y; |
299 | + } |
300 | + break; |
301 | + default: |
302 | + break; |
303 | + } |
304 | + } |
305 | + //Key released |
306 | + else if (event.type == SDL_KEYUP) |
307 | + { |
308 | + switch (event.key.keysym.sym) |
309 | + { |
310 | + case SDLK_LEFT: |
311 | + if (horiz_move == HORIZ_MOVE_LEFT || horiz_move == HORIZ_MOVE_NONE_R) |
312 | + { |
313 | + horiz_move = HORIZ_MOVE_NONE_L; |
314 | + } |
315 | + break; |
316 | + case SDLK_RIGHT: |
317 | + if (horiz_move == HORIZ_MOVE_RIGHT || horiz_move == HORIZ_MOVE_NONE_L) |
318 | + { |
319 | + horiz_move = HORIZ_MOVE_NONE_R; |
320 | + } |
321 | + break; |
322 | + case SDLK_UP: |
323 | + if (vert_move == VERT_MOVE_UP) |
324 | + { |
325 | + vert_move = VERT_MOVE_IM; |
326 | + } |
327 | + break; |
328 | + case SDLK_DOWN: |
329 | + if (vert_move == VERT_MOVE_DOWN) |
330 | + { |
331 | + vert_move = VERT_MOVE_IM; |
332 | + } |
333 | + break; |
334 | + default: |
335 | + break; |
336 | + } |
337 | + } |
338 | + } |
339 | + //Update the Jumpman position |
340 | + if (!jump) // NOT JUMPING // |
341 | + { |
342 | + //Handle horizontal moves |
343 | + if (!check_ladder_collides(&JUMPMAN.platform_collide, map) || |
344 | + ( |
345 | + check_ladder_collides(&JUMPMAN.platform_collide, map) && |
346 | + check_ladder_top_collides(&JUMPMAN.platform_collide, map) |
347 | + ) || ( |
348 | + check_ladder_collides(&JUMPMAN.platform_collide, map) && |
349 | + check_ladder_bottom_collides(&JUMPMAN.platform_collide, map) |
350 | + ) |
351 | + ) |
352 | + { |
353 | + if (horiz_move == HORIZ_MOVE_LEFT) { |
354 | + JUMPMAN.movement = SPRITE_WALK_LEFT; |
355 | + JUMPMAN.platform_collide.x1--; |
356 | + if (!check_platform_collides(&JUMPMAN.platform_collide, map)) |
357 | + { |
358 | + JUMPMAN.pos_x -= 1; |
359 | + } |
360 | + else |
361 | + { |
362 | + JUMPMAN.platform_collide.y1--; |
363 | + if (!check_platform_collides(&JUMPMAN.platform_collide, map)) |
364 | + { |
365 | + JUMPMAN.pos_x -= 1; |
366 | + JUMPMAN.pos_y -= 1; |
367 | + } |
368 | + } |
369 | + } |
370 | + else if (horiz_move == HORIZ_MOVE_NONE_L) { |
371 | + JUMPMAN.movement = SPRITE_LOOK_LEFT; |
372 | + JUMPMAN.pos_x = JUMPMAN.platform_collide.x1 - JUMPMAN.sprite->items[JUMPMAN.movement].w / 2; |
373 | + } |
374 | + else if (horiz_move == HORIZ_MOVE_RIGHT) { |
375 | + JUMPMAN.movement = SPRITE_WALK_RIGHT; |
376 | + JUMPMAN.platform_collide.x1++; |
377 | + if (!check_platform_collides(&JUMPMAN.platform_collide, map)) |
378 | + { |
379 | + JUMPMAN.pos_x += 1; |
380 | + } |
381 | + else |
382 | + { |
383 | + JUMPMAN.platform_collide.y1--; |
384 | + if (!check_platform_collides(&JUMPMAN.platform_collide, map)) |
385 | + { |
386 | + JUMPMAN.pos_x += 1; |
387 | + JUMPMAN.pos_y -= 1; |
388 | + } |
389 | + } |
390 | + } |
391 | + else if (horiz_move == HORIZ_MOVE_NONE_R) { |
392 | + JUMPMAN.movement = SPRITE_LOOK_RIGHT; |
393 | + JUMPMAN.pos_x = JUMPMAN.platform_collide.x1 - JUMPMAN.sprite->items[JUMPMAN.movement].w / 2; |
394 | + } |
395 | + } |
396 | + //Handle vertical moves |
397 | + if (vert_move == VERT_MOVE_UP) //MOVE UP (ladders) |
398 | + { |
399 | + if (check_ladder_collides(&JUMPMAN.platform_collide, map)) |
400 | + { |
401 | + //Center Jumpman on the ladder |
402 | + JUMPMAN.pos_x = get_collide_ladder_center(&JUMPMAN.platform_collide, map) - \ |
403 | + JUMPMAN.sprite->items[JUMPMAN.movement].w / 2; |
404 | + if (check_ladder_top_collides(&JUMPMAN.platform_collide, map)) |
405 | + { |
406 | + JUMPMAN.pos_y -= 5; |
407 | + vert_move = VERT_MOVE_NONE; |
408 | + } |
409 | + else |
410 | + { |
411 | + JUMPMAN.pos_y--; |
412 | + JUMPMAN.movement = SPRITE_WALK_LADDER; |
413 | + } |
414 | + } |
415 | + else |
416 | + { |
417 | + vert_move = VERT_MOVE_NONE; |
418 | + } |
419 | + } |
420 | + else if (vert_move == VERT_MOVE_DOWN) //MOVE DOWN (ladders) |
421 | + { |
422 | + //Center Jumpman on the ladder |
423 | + JUMPMAN.pos_x = get_collide_ladder_center(&JUMPMAN.platform_collide, map) - \ |
424 | + JUMPMAN.sprite->items[JUMPMAN.movement].w / 2; |
425 | + if (check_ladder_collides(&JUMPMAN.platform_collide, map)) |
426 | + { |
427 | + JUMPMAN.platform_collide.y1++; |
428 | + if(!check_ladder_bottom_collides(&JUMPMAN.platform_collide, map)) |
429 | + { |
430 | + JUMPMAN.pos_y++; |
431 | + JUMPMAN.movement = SPRITE_WALK_LADDER; |
432 | + } |
433 | + else |
434 | + { |
435 | + vert_move = VERT_MOVE_NONE; |
436 | + JUMPMAN.pos_y--; |
437 | + } |
438 | + } |
439 | + else |
440 | + { |
441 | + vert_move = VERT_MOVE_NONE; |
442 | + } |
443 | + } |
444 | + else if (vert_move == VERT_MOVE_IM) |
445 | + { |
446 | + JUMPMAN.movement = SPRITE_LADDER; |
447 | + } |
448 | + } |
449 | + else // JUMPING // |
450 | + { |
451 | + if (horiz_move == HORIZ_MOVE_LEFT) { |
452 | + JUMPMAN.movement = SPRITE_JUMP_LEFT; |
453 | + JUMPMAN.platform_collide.x1--; |
454 | + if (!check_platform_collides(&JUMPMAN.platform_collide, map)) |
455 | + { |
456 | + JUMPMAN.pos_x -= 1; |
457 | + } |
458 | + else |
459 | + { |
460 | + JUMPMAN.platform_collide.y1--; |
461 | + if (!check_platform_collides(&JUMPMAN.platform_collide, map)) |
462 | + { |
463 | + JUMPMAN.pos_x -= 1; |
464 | + JUMPMAN.pos_y -= 1; |
465 | + } |
466 | + } |
467 | + } |
468 | + else if (horiz_move == HORIZ_MOVE_NONE_L) { |
469 | + JUMPMAN.movement = SPRITE_JUMP_LEFT; |
470 | + } |
471 | + else if (horiz_move == HORIZ_MOVE_RIGHT) { |
472 | + JUMPMAN.movement = SPRITE_JUMP_RIGHT; |
473 | + JUMPMAN.platform_collide.x1++; |
474 | + if (!check_platform_collides(&JUMPMAN.platform_collide, map)) |
475 | + { |
476 | + JUMPMAN.pos_x += 1; |
477 | + } |
478 | + else |
479 | + { |
480 | + JUMPMAN.platform_collide.y1--; |
481 | + if (!check_platform_collides(&JUMPMAN.platform_collide, map)) |
482 | + { |
483 | + JUMPMAN.pos_x += 1; |
484 | + JUMPMAN.pos_y -= 1; |
485 | + } |
486 | + } |
487 | + } |
488 | + else if (horiz_move == HORIZ_MOVE_NONE_R) { |
489 | + JUMPMAN.movement = SPRITE_JUMP_RIGHT; |
490 | + } |
491 | + |
492 | + if (jump == JUMP_UP) |
493 | + { |
494 | + if (jump_y_start - JUMPMAN.pos_y < 10) |
495 | + { |
496 | + JUMPMAN.pos_y -= 3; |
497 | + } |
498 | + else if (jump_y_start - JUMPMAN.pos_y < 25) |
499 | + { |
500 | + JUMPMAN.pos_y -= 2; |
501 | + } |
502 | + else if (jump_y_start - JUMPMAN.pos_y < 35) |
503 | + { |
504 | + JUMPMAN.pos_y -= 1; |
505 | + } |
506 | + else |
507 | + { |
508 | + jump = JUMP_DOWN; |
509 | + } |
510 | + } |
511 | + else |
512 | + { |
513 | + JUMPMAN.platform_collide.y1++; |
514 | + if (check_platform_collides(&JUMPMAN.platform_collide, map)) |
515 | + { |
516 | + jump = JUMP_NONE; |
517 | + } |
518 | + } |
519 | + } |
520 | + update_jumpman(); |
521 | + //Gravity |
522 | + if (jump != JUMP_UP && vert_move == VERT_MOVE_NONE) |
523 | + { |
524 | + JUMPMAN.platform_collide.y1++; |
525 | + if (!check_platform_collides(&JUMPMAN.platform_collide, map)) |
526 | + { |
527 | + JUMPMAN.pos_y++; |
528 | + } |
529 | + } |
530 | + update_jumpman(); |
531 | + //Finish area |
532 | + if (collide(&map->finish, &JUMPMAN.platform_collide)) |
533 | + { |
534 | + GAME_STATE = GAME_STATE_LEVEL_COMPLETED; |
535 | + } |
536 | + SDL_Delay(5); |
537 | + } //-- End of the main loop -- |
538 | + |
539 | + //If the player die |
540 | + if (GAME_STATE == GAME_STATE_LIFE_LOST) |
541 | + { |
542 | + JUMPMAN.movement = SPRITE_DEAD; |
543 | + update_jumpman(); |
544 | + SDL_Delay(1500); |
545 | + } |
546 | + |
547 | + //TODO if the player win, play a music,... |
548 | + |
549 | + //Dereference Jumpman |
550 | + deref_object(&layer_active, jumpman_refresh); |
551 | + //Return the game state |
552 | + return GAME_STATE; |
553 | +} |
554 | + |
555 | + |
556 | +/** |
557 | + * \fn DM_Map* load_map_infos(char *level_name) |
558 | + * \brief Load the level informations from a .map file. |
559 | + * |
560 | + * \param level_name The name of the level (e.g. "level_01"). |
561 | + * |
562 | + * \return Returns a pointer on a DM_Map that contain all level informations. |
563 | + */ |
564 | +DM_Map* load_map_infos(char *level_name) |
565 | +{ |
566 | + //Some variable declaration/initialisation |
567 | + int ladder_count = 0; |
568 | + int platform_count = 0; |
569 | + DM_Map *map = malloc(sizeof(DM_Map)); |
570 | + if (map == NULL) |
571 | + { |
572 | + fprintf(stderr, "E: Cannot allocate memory."); |
573 | + exit(EXIT_FAILURE); |
574 | + } |
575 | + //Make the level file path |
576 | + char path[42] = ""; |
577 | + sprintf(path, "levels/%s.map", level_name); |
578 | + //Parse the map file |
579 | + DM_Splited *map_infos = read_file(path); |
580 | + //Count the platforms and the ladders |
581 | + int i; |
582 | + for (i=0 ; i<map_infos->items_int ; i++) |
583 | + { |
584 | + if (map_infos->lines_array[i]->parameters_int == 5) |
585 | + { |
586 | + if (strcmp(map_infos->lines_array[i]->parameters[0], "platform-collide")) |
587 | + { |
588 | + platform_count++; |
589 | + } |
590 | + else if (strcmp(map_infos->lines_array[i]->parameters[0], "ladder-collide")) |
591 | + { |
592 | + ladder_count++; |
593 | + } |
594 | + } |
595 | + } |
596 | + //Initialize the DM_Map |
597 | + map->platforms = malloc(platform_count * sizeof(DM_Collide)); |
598 | + map->platform_count = platform_count; |
599 | + map->ladders = malloc(ladder_count * sizeof(DM_Collide)); |
600 | + map->ladder_count = ladder_count; |
601 | + map->finish.shape = COLLIDE_RECT; |
602 | + map->finish.x1 = 0; |
603 | + map->finish.y1 = 0; |
604 | + map->finish.x2 = 0; |
605 | + map->finish.y2 = 0; |
606 | + map->start_point_x = 0; |
607 | + map->start_point_y = 0; |
608 | + map->start_look = SPRITE_LOOK_RIGHT; |
609 | + //Fill the DM_Map |
610 | + platform_count--; |
611 | + ladder_count--; |
612 | + for (i=0 ; i<map_infos->items_int ; i++) |
613 | + { |
614 | + if (map_infos->lines_array[i]->parameters_int == 5) |
615 | + { |
616 | + if (!strcmp(map_infos->lines_array[i]->parameters[0], "platform-collide")) |
617 | + { |
618 | + map->platforms[platform_count].shape = COLLIDE_LINE; |
619 | + map->platforms[platform_count].x1 = atoi(map_infos->lines_array[i]->parameters[1]) + 1; |
620 | + map->platforms[platform_count].y1 = atoi(map_infos->lines_array[i]->parameters[2]) + 1; |
621 | + map->platforms[platform_count].x2 = atoi(map_infos->lines_array[i]->parameters[3]) + 1; |
622 | + map->platforms[platform_count].y2 = atoi(map_infos->lines_array[i]->parameters[4]) + 1; |
623 | + platform_count--; |
624 | + } |
625 | + else if (!strcmp(map_infos->lines_array[i]->parameters[0], "ladder-collide")) |
626 | + { |
627 | + map->ladders[ladder_count].shape = COLLIDE_RECT; |
628 | + map->ladders[ladder_count].x1 = atoi(map_infos->lines_array[i]->parameters[1]) + 1; |
629 | + map->ladders[ladder_count].y1 = atoi(map_infos->lines_array[i]->parameters[2]) + 1; |
630 | + map->ladders[ladder_count].x2 = atoi(map_infos->lines_array[i]->parameters[3]) + 1; |
631 | + map->ladders[ladder_count].y2 = atoi(map_infos->lines_array[i]->parameters[4]) + 1; |
632 | + ladder_count--; |
633 | + } |
634 | + else if (!strcmp(map_infos->lines_array[i]->parameters[0], "jumpman-start-right")) |
635 | + { |
636 | + map->start_look = SPRITE_LOOK_RIGHT; |
637 | + map->start_point_x = atoi(map_infos->lines_array[i]->parameters[1]) + 1; |
638 | + map->start_point_y = atoi(map_infos->lines_array[i]->parameters[2]) + 1; |
639 | + } |
640 | + else if (!strcmp(map_infos->lines_array[i]->parameters[0], "jumpman-start-left")) |
641 | + { |
642 | + map->start_look = SPRITE_LOOK_LEFT; |
643 | + map->start_point_x = atoi(map_infos->lines_array[i]->parameters[1]) + 1; |
644 | + map->start_point_y = atoi(map_infos->lines_array[i]->parameters[2]) + 1; |
645 | + } |
646 | + else if (!strcmp(map_infos->lines_array[i]->parameters[0], "finish-collide")) |
647 | + { |
648 | + map->finish.shape = COLLIDE_RECT; |
649 | + map->finish.x1 = atoi(map_infos->lines_array[i]->parameters[1]) + 1; |
650 | + map->finish.y1 = atoi(map_infos->lines_array[i]->parameters[2]) + 1; |
651 | + map->finish.x2 = atoi(map_infos->lines_array[i]->parameters[3]) + 1; |
652 | + map->finish.y2 = atoi(map_infos->lines_array[i]->parameters[4]) + 1; |
653 | + } |
654 | + } |
655 | + } |
656 | + //Free the parser's struct |
657 | + free_dm_splited(map_infos); |
658 | + //Return the DM_Map |
659 | + return map; |
660 | +} |
661 | + |
662 | + |
663 | +/** |
664 | + * \fn void free_dm_map(DM_Map *map) |
665 | + * \brief Free the memory of a DM_Map. |
666 | + * |
667 | + * \param map The DM_Map to free. |
668 | + */ |
669 | +void free_dm_map(DM_Map *map) |
670 | +{ |
671 | + free(map->platforms); |
672 | + free(map->ladders); |
673 | + free(map); |
674 | +} |
675 | + |
676 | + |
677 | +/** |
678 | + * \fn int check_platform_collides(DM_Collide *collide_point, DM_Map *map) |
679 | + * \brief Check if a point is in collision with any platform. |
680 | + * |
681 | + * \param collide_point The point that we have to check. |
682 | + * \param map the DM_Map that contain the list of all platforms. |
683 | + * |
684 | + * \return Returns true if there is a collide, false else. |
685 | + */ |
686 | +int check_platform_collides(DM_Collide *collide_point, DM_Map *map) |
687 | +{ |
688 | + int i; |
689 | + for (i=0 ; i<map->platform_count ; i++) |
690 | + { |
691 | + if (collide(collide_point, &map->platforms[i])) |
692 | + { |
693 | + return 1; |
694 | + } |
695 | + } |
696 | + return 0; |
697 | +} |
698 | + |
699 | + |
700 | +/** |
701 | + * \fn int check_ladder_collides(DM_Collide *collide_point, DM_Map *map) |
702 | + * \brief Check if a point is in collision with any ladder. |
703 | + * |
704 | + * \param collide_point The point that we have to check. |
705 | + * \param map the DM_Map that contain the list of all ladders. |
706 | + * |
707 | + * \return Return true if there is a collide, false else. |
708 | + */ |
709 | +int check_ladder_collides(DM_Collide *collide_point, DM_Map *map) |
710 | +{ |
711 | + int i; |
712 | + for (i=0 ; i<map->ladder_count ; i++) |
713 | + { |
714 | + if (collide(collide_point, &map->ladders[i])) |
715 | + { |
716 | + return 1; |
717 | + } |
718 | + } |
719 | + return 0; |
720 | +} |
721 | + |
722 | + |
723 | +/** |
724 | + * \fn int check_ladder_top_collides(DM_Collide *collide_point, DM_Map *map) |
725 | + * \brief Check if a point is in collision with the top of any ladder. |
726 | + * |
727 | + * \param collide_point The point that we have to check. |
728 | + * \param map the DM_Map that contain the list of all ladders. |
729 | + * |
730 | + * \return Returns true if there is a collide, false else. |
731 | + */ |
732 | +int check_ladder_top_collides(DM_Collide *collide_point, DM_Map *map) |
733 | +{ |
734 | + DM_Collide crect; |
735 | + crect.shape = COLLIDE_RECT; |
736 | + int i; |
737 | + for (i=0 ; i<map->ladder_count ; i++) |
738 | + { |
739 | + crect.x1 = map->ladders[i].x1; |
740 | + crect.x2 = map->ladders[i].x2; |
741 | + if (map->ladders[i].y1 < map->ladders[i].y2) |
742 | + { |
743 | + crect.y1 = map->ladders[i].y1; |
744 | + crect.y2 = map->ladders[i].y1 + 3; |
745 | + } |
746 | + else |
747 | + { |
748 | + crect.y1 = map->ladders[i].y2; |
749 | + crect.y2 = map->ladders[i].y2 + 3; |
750 | + } |
751 | + if (collide(collide_point, &crect)) |
752 | + { |
753 | + return 1; |
754 | + } |
755 | + } |
756 | + return 0; |
757 | +} |
758 | + |
759 | + |
760 | +/** |
761 | + * \fn int check_ladder_bottom_collides(DM_Collide *collide_point, DM_Map *map) |
762 | + * \brief Check if a point is in collision with the bottom of any ladder. |
763 | + * |
764 | + * \param collide_point The point that we have to check. |
765 | + * \param map the DM_Map that contain the list of all ladders. |
766 | + * |
767 | + * \return Returns true if there is a collide, false else. |
768 | + */ |
769 | +int check_ladder_bottom_collides(DM_Collide *collide_point, DM_Map *map) |
770 | +{ |
771 | + DM_Collide crect; |
772 | + crect.shape = COLLIDE_RECT; |
773 | + int i; |
774 | + for (i=0 ; i<map->ladder_count ; i++) |
775 | + { |
776 | + crect.x1 = map->ladders[i].x1; |
777 | + crect.x2 = map->ladders[i].x2; |
778 | + if (map->ladders[i].y1 < map->ladders[i].y2) |
779 | + { |
780 | + crect.y1 = map->ladders[i].y2 - 10; |
781 | + crect.y2 = map->ladders[i].y2; |
782 | + } |
783 | + else |
784 | + { |
785 | + crect.y1 = map->ladders[i].y1 - 10; |
786 | + crect.y2 = map->ladders[i].y1; |
787 | + } |
788 | + if (collide(collide_point, &crect)) |
789 | + { |
790 | + return 1; |
791 | + } |
792 | + } |
793 | + return 0; |
794 | +} |
795 | + |
796 | + |
797 | +/** |
798 | + * \fn int get_collide_ladder_center(DM_Collide *collide_point, DM_Map *map) |
799 | + * \brief Get the center (x point) of the ladder in collide with a point. |
800 | + * |
801 | + * \param collide_point The point that is in collide with a ladder. |
802 | + * \param map the DM_Map that contain the list of all ladders. |
803 | + * |
804 | + * \return Returns the x point of the center of the ladder, or -1; |
805 | + */ |
806 | +int get_collide_ladder_center(DM_Collide *collide_point, DM_Map *map) |
807 | +{ |
808 | + int i; |
809 | + for (i=0 ; i<map->ladder_count ; i++) |
810 | + { |
811 | + if (collide(collide_point, &map->ladders[i])) |
812 | + { |
813 | + return (map->ladders[i].x1 + map->ladders[i].x2) / 2; |
814 | + } |
815 | + } |
816 | + return -1; |
817 | +} |
818 | + |
819 | + |
820 | +/** |
821 | + * \fn collide(DM_Collide *collide1, DM_Collide *collide2) |
822 | + * \brief Check for collision between two collide area. |
823 | + * |
824 | + * \param collide1 The first collide area. |
825 | + * \param collide2 The second collide area. |
826 | + * |
827 | + * \return Returns true if there is a collide, false else. |
828 | + */ |
829 | +int collide(DM_Collide *collide1, DM_Collide *collide2) |
830 | +{ |
831 | + //Collide between a point and a line |
832 | + if (collide1->shape == COLLIDE_LINE && collide2->shape == COLLIDE_POINT) |
833 | + { |
834 | + return _collide_line_point(collide1, collide2); |
835 | + } |
836 | + else if (collide1->shape == COLLIDE_POINT && collide2->shape == COLLIDE_LINE) |
837 | + { |
838 | + return _collide_line_point(collide2, collide1); |
839 | + } |
840 | + //Collide between a point and a rect |
841 | + if (collide1->shape == COLLIDE_RECT && collide2->shape == COLLIDE_POINT) |
842 | + { |
843 | + return _collide_rect_point(collide1, collide2); |
844 | + } |
845 | + else if (collide1->shape == COLLIDE_POINT && collide2->shape == COLLIDE_RECT) |
846 | + { |
847 | + return _collide_rect_point(collide2, collide1); |
848 | + } |
849 | + //Collide between two rectangles |
850 | + if (collide1->shape == COLLIDE_RECT && collide2->shape == COLLIDE_RECT) |
851 | + { |
852 | + return _collide_rect_rect(collide1, collide2); |
853 | + } |
854 | + //Collide not implemented |
855 | + else |
856 | + { |
857 | + //FIXME Hide this annoying warning while we don't know why there is |
858 | + //abnormal collide shape that arrive in the DM_Map... (because it |
859 | + //floods my console !) |
860 | + //printf("W: Collide between shape %i and shape %i not implemented.\n", |
861 | + // collide1->shape, |
862 | + // collide2->shape |
863 | + // ); |
864 | + return 0; |
865 | + } |
866 | +} |
867 | + |
868 | + |
869 | +//This is a "private" function that check a collide between a line and |
870 | +//a point. Please use the collide() function instead of this one. |
871 | +int _collide_line_point(DM_Collide *cline, DM_Collide *cpoint) |
872 | +{ |
873 | + //Check if the point is in the rectangle |
874 | + if (!_collide_rect_point(cline, cpoint)) |
875 | + { |
876 | + return 0; |
877 | + } |
878 | + //Check if the point is on the line |
879 | + float dx1 = cline->x1; |
880 | + float dy1 = cline->y1; |
881 | + float dx2 = cline->x2; |
882 | + float dy2 = cline->y2; |
883 | + float ptx = cpoint->x1; |
884 | + int pty = cpoint->y1; |
885 | + |
886 | + float delta = dx1 - dx2; |
887 | + float delta_a = dy1 - dy2; |
888 | + float delta_b = dx1 * dy2 - dx2 * dy1; |
889 | + |
890 | + float a = delta_a / delta; |
891 | + float b = delta_b / delta; |
892 | + |
893 | + int result = a * ptx + b; |
894 | + |
895 | + if (pty == result) |
896 | + { |
897 | + return 1; |
898 | + } |
899 | + else |
900 | + { |
901 | + //Check again with a line just bellow the first one. |
902 | + //This is done for avoiding false negative result. |
903 | + dy1 += 1; |
904 | + dy2 += 1; |
905 | + |
906 | + delta = dx1 - dx2; |
907 | + delta_a = dy1 - dy2; |
908 | + delta_b = dx1 * dy2 - dx2 * dy1; |
909 | + |
910 | + a = delta_a / delta; |
911 | + b = delta_b / delta; |
912 | + |
913 | + result = a * ptx + b; |
914 | + |
915 | + if (pty == result) |
916 | + { |
917 | + return 1; |
918 | + } |
919 | + |
920 | + return 0; |
921 | + } |
922 | +} |
923 | + |
924 | + |
925 | +//This is a "private" function that check a collide between a rectangle |
926 | +//and a point. Please use the collide() function instead of this one. |
927 | +int _collide_rect_point(DM_Collide *crect, DM_Collide *cpoint) |
928 | +{ |
929 | + int x1, x2, y1, y2; |
930 | + if (crect->x1 < crect->x2) |
931 | + { |
932 | + x1 = crect->x1; |
933 | + x2 = crect->x2; |
934 | + } |
935 | + else |
936 | + { |
937 | + x1 = crect->x2; |
938 | + x2 = crect->x1; |
939 | + } |
940 | + if (crect->y1 < crect->y2) |
941 | + { |
942 | + y1 = crect->y1; |
943 | + y2 = crect->y2; |
944 | + } |
945 | + else |
946 | + { |
947 | + y1 = crect->y2; |
948 | + y2 = crect->y1; |
949 | + } |
950 | + if (cpoint->x1 < x1 || cpoint->x1 > x2 || cpoint->y1 < y1 || cpoint->y1 > y2) |
951 | + { |
952 | + return 0; |
953 | + } |
954 | + else |
955 | + { |
956 | + return 1; |
957 | + } |
958 | +} |
959 | + |
960 | + |
961 | +//This is a "private" function that check a collide between two rectangles |
962 | +//Please use the collide() function instead of this one. |
963 | +int _collide_rect_rect(DM_Collide *crect1, DM_Collide *crect2) |
964 | +{ |
965 | + //NOTE: This is a very basic rectangle collision detection. |
966 | + // It does not works for every cases, but it is sufficient |
967 | + // for our use. |
968 | + DM_Collide cpoint; |
969 | + //Test all the corners of the rect 1 |
970 | + cpoint.x1 = crect1->x1; |
971 | + cpoint.y1 = crect1->y1; |
972 | + if (_collide_rect_point(crect2, &cpoint)) |
973 | + { |
974 | + return 1; |
975 | + } |
976 | + cpoint.x1 = crect1->x1; |
977 | + cpoint.y1 = crect1->y2; |
978 | + if (_collide_rect_point(crect2, &cpoint)) |
979 | + { |
980 | + return 1; |
981 | + } |
982 | + cpoint.x1 = crect1->x2; |
983 | + cpoint.y1 = crect1->y2; |
984 | + if (_collide_rect_point(crect2, &cpoint)) |
985 | + { |
986 | + return 1; |
987 | + } |
988 | + cpoint.x1 = crect1->x2; |
989 | + cpoint.y1 = crect1->y1; |
990 | + if (_collide_rect_point(crect2, &cpoint)) |
991 | + { |
992 | + return 1; |
993 | + } |
994 | + //Test all the corners of the rect 2 |
995 | + cpoint.x1 = crect2->x1; |
996 | + cpoint.y1 = crect2->y1; |
997 | + if (_collide_rect_point(crect1, &cpoint)) |
998 | + { |
999 | + return 1; |
1000 | + } |
1001 | + cpoint.x1 = crect2->x1; |
1002 | + cpoint.y1 = crect2->y2; |
1003 | + if (_collide_rect_point(crect1, &cpoint)) |
1004 | + { |
1005 | + return 1; |
1006 | + } |
1007 | + cpoint.x1 = crect2->x2; |
1008 | + cpoint.y1 = crect2->y2; |
1009 | + if (_collide_rect_point(crect1, &cpoint)) |
1010 | + { |
1011 | + return 1; |
1012 | + } |
1013 | + cpoint.x1 = crect2->x2; |
1014 | + cpoint.y1 = crect2->y1; |
1015 | + if (_collide_rect_point(crect1, &cpoint)) |
1016 | + { |
1017 | + return 1; |
1018 | + } |
1019 | + return 0; |
1020 | +} |
1021 | + |
1022 | + |
1023 | |
1024 | === added file 'src/game.h' |
1025 | --- src/game.h 1970-01-01 00:00:00 +0000 |
1026 | +++ src/game.h 2011-05-07 13:57:29 +0000 |
1027 | @@ -0,0 +1,139 @@ |
1028 | +#ifndef GAME_H_INCLUDED |
1029 | +#define GAME_H_INCLUDED |
1030 | + |
1031 | + |
1032 | +/** |
1033 | + * \file game.h |
1034 | + * \brief The header file of game.c. |
1035 | + */ |
1036 | + |
1037 | + |
1038 | +#include "conf.h" |
1039 | + |
1040 | +#include <stdio.h> |
1041 | +#include <stdlib.h> |
1042 | +#include <string.h> |
1043 | + |
1044 | +#ifdef LINUX |
1045 | +#include "SDL.h" |
1046 | +#include "SDL_image.h" |
1047 | +#include "SDL_mixer.h" |
1048 | +#endif |
1049 | + |
1050 | +#ifdef MAC_OS |
1051 | +#include <SDL/SDL.h> |
1052 | +#include <SDL_image/SDL_image.h> |
1053 | +#include <SDL_mixer/SDL_mixer.h> |
1054 | +#endif |
1055 | + |
1056 | +#ifdef WINDOWS |
1057 | +#include <SDL.h> |
1058 | +#include <SDL_image.h> |
1059 | +#include <SDL_mixer.h> |
1060 | +#endif |
1061 | + |
1062 | +#include "sprite.h" |
1063 | +#include "refresh.h" |
1064 | +#include "parser.h" |
1065 | +#include "pause_menu.h" |
1066 | + |
1067 | + |
1068 | +#define COLLIDE_RECT 0 |
1069 | +#define COLLIDE_LINE 1 |
1070 | +#define COLLIDE_POINT 2 |
1071 | + |
1072 | +#define GAME_STATE_NONE 0 |
1073 | +#define GAME_STATE_PLAYING 1 |
1074 | +#define GAME_STATE_PAUSED 2 |
1075 | +#define GAME_STATE_LEVEL_COMPLETED 3 |
1076 | +#define GAME_STATE_LIFE_LOST 4 |
1077 | +#define GAME_STATE_OVER 5 |
1078 | + |
1079 | +#define HORIZ_MOVE_NONE_L 0 |
1080 | +#define HORIZ_MOVE_NONE_R 1 |
1081 | +#define HORIZ_MOVE_LEFT 2 |
1082 | +#define HORIZ_MOVE_RIGHT 3 |
1083 | + |
1084 | +#define VERT_MOVE_NONE 0 |
1085 | +#define VERT_MOVE_IM 1 |
1086 | +#define VERT_MOVE_UP 2 |
1087 | +#define VERT_MOVE_DOWN 3 |
1088 | + |
1089 | +#define JUMP_NONE 0 |
1090 | +#define JUMP_UP 1 |
1091 | +#define JUMP_DOWN 2 |
1092 | + |
1093 | + |
1094 | +/** |
1095 | + * \struct DM_Collide |
1096 | + * \brief Contain informations about one collision surface. |
1097 | + */ |
1098 | +typedef struct DM_Collide DM_Collide; |
1099 | +struct DM_Collide |
1100 | +{ |
1101 | + int shape; /*!< The collide shape (COLLIDE_RECT, COLLIDE_LINE, COLLIDE_POINT). */ |
1102 | + int x1; /*!< x1 point */ |
1103 | + int y1; /*!< y1 point */ |
1104 | + int x2; /*!< x2 point */ |
1105 | + int y2; /*!< y2 point */ |
1106 | +}; |
1107 | + |
1108 | + |
1109 | +/** |
1110 | + * \struct DM_Collide |
1111 | + * \brief Contain all collisions of the map. |
1112 | + */ |
1113 | +typedef struct DM_Map DM_Map; |
1114 | +struct DM_Map |
1115 | +{ |
1116 | + DM_Collide *platforms; /*!< Platfoms collides. */ |
1117 | + int platform_count; /*!< The number of platforms. */ |
1118 | + DM_Collide *ladders; /*!< Ladders collides. */ |
1119 | + int ladder_count; /*!< The number of ladders. */ |
1120 | + DM_Collide finish; /*!< Finish area collide. */ |
1121 | + int start_point_x; /*!< Jumpman start point (x). */ |
1122 | + int start_point_y; /*!< Jumpman start point (y). */ |
1123 | + int start_look; /*!< Where Jumpman look at the start. */ |
1124 | +}; |
1125 | + |
1126 | + |
1127 | +/** |
1128 | + * \struct DM_Jumpman |
1129 | + * \brief Contain informations about Jumpman. |
1130 | + */ |
1131 | +typedef struct DM_Jumpman DM_Jumpman; |
1132 | +struct DM_Jumpman |
1133 | +{ |
1134 | + DM_Collide platform_collide; /*!< Collision point with platforms. */ |
1135 | + DM_Collide enemy_collide; /*!< Collision rect with enemies. */ |
1136 | + DM_Sprite *sprite; /*!< The sprite of Jumpman. */ |
1137 | + int pos_x; /*!< The position of Jumpman (x). */ |
1138 | + int pos_y; /*!< The position of Jumpman (y). */ |
1139 | + int movement; /*!< The current movement for animation (SPRITE_*). */ |
1140 | +}; |
1141 | + |
1142 | + |
1143 | +//Some global vars |
1144 | +DM_Jumpman JUMPMAN; |
1145 | +int GAME_SPEED; |
1146 | +int GAME_STATE; |
1147 | + |
1148 | + |
1149 | +void init_game(); |
1150 | +void update_jumpman(); |
1151 | +int lets_play_yeah(SDL_Surface *screen, DM_Map *map); |
1152 | +DM_Map* load_map_infos(char *level_name); |
1153 | +void free_dm_map(DM_Map *map); |
1154 | +int check_platform_collides(DM_Collide *collide_point, DM_Map *map); |
1155 | +int check_ladder_collides(DM_Collide *collide_point, DM_Map *map); |
1156 | +int check_ladder_top_collides(DM_Collide *collide_point, DM_Map *map); |
1157 | +int check_ladder_bottom_collides(DM_Collide *collide_point, DM_Map *map); |
1158 | +int get_collide_ladder_center(DM_Collide *collide_point, DM_Map *map); |
1159 | +int collide(DM_Collide *collide1, DM_Collide *collide2); |
1160 | +int _collide_line_point(DM_Collide *collide1, DM_Collide *collide2); |
1161 | +int _collide_rect_point(DM_Collide *crect, DM_Collide *cpoint); |
1162 | +int _collide_rect_rect(DM_Collide *crect1, DM_Collide *crect2); |
1163 | + |
1164 | + |
1165 | +#endif //GAME_H_INCLUDED |
1166 | + |
1167 | |
1168 | === added directory 'src/levels' |
1169 | === added file 'src/levels/level_01.c' |
1170 | --- src/levels/level_01.c 1970-01-01 00:00:00 +0000 |
1171 | +++ src/levels/level_01.c 2011-05-07 13:57:29 +0000 |
1172 | @@ -0,0 +1,58 @@ |
1173 | +/*************************************************************************** |
1174 | +* * |
1175 | +* This file is part of Damn Monkey * |
1176 | +* * |
1177 | +* Copyright (C) 2010 - 2011 Fabien LOISON, Mathilde BOUTIGNY, * |
1178 | +* Vincent PEYROUSE, Germain CARRÉ and Matthis FRENAY * |
1179 | +* * |
1180 | +* Damn Monkey is free software: you can redistribute it and/or modify * |
1181 | +* it under the terms of the GNU General Public License as published by * |
1182 | +* the Free Software Foundation, either version 3 of the License, or * |
1183 | +* (at your option) any later version. * |
1184 | +* * |
1185 | +* This program is distributed in the hope that it will be useful, * |
1186 | +* but WITHOUT ANY WARRANTY; without even the implied warranty of * |
1187 | +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * |
1188 | +* GNU General Public License for more details. * |
1189 | +* * |
1190 | +* You should have received a copy of the GNU General Public License * |
1191 | +* along with this program. If not, see <http://www.gnu.org/licenses/>. * |
1192 | +* * |
1193 | +***************************************************************************/ |
1194 | + |
1195 | + |
1196 | +/** |
1197 | + * \file level_01.c |
1198 | + * \brief TODO. |
1199 | + */ |
1200 | + |
1201 | + |
1202 | +#include "level_01.h" |
1203 | + |
1204 | + |
1205 | +/** |
1206 | + * \fn void level_01() |
1207 | + * \brief Draw the first level. |
1208 | + * |
1209 | + * \param screen The main surface. |
1210 | + * |
1211 | + * \return Nothing. |
1212 | + */ |
1213 | +void level_01(SDL_Surface *screen) |
1214 | +{ |
1215 | + //Load the background |
1216 | + DM_Surface *level_surface = load_resource_as_dm_surface("level_01.png"); |
1217 | + int level_surface_refresh = ref_object(&layer_bg, level_surface, surface_refresh_cb); |
1218 | + |
1219 | + //Load the level infos (collides,...) |
1220 | + DM_Map *map = load_map_infos("level_01"); |
1221 | + lets_play_yeah(screen, map); |
1222 | + //FIXME: free dm_map |
1223 | + |
1224 | + //Dereference objects and free the memory |
1225 | + deref_object(&layer_bg, level_surface_refresh); |
1226 | + SDL_Delay(20); |
1227 | + free_dm_surface(level_surface); |
1228 | +} |
1229 | + |
1230 | + |
1231 | |
1232 | === added file 'src/levels/level_01.h' |
1233 | --- src/levels/level_01.h 1970-01-01 00:00:00 +0000 |
1234 | +++ src/levels/level_01.h 2011-05-07 13:57:29 +0000 |
1235 | @@ -0,0 +1,20 @@ |
1236 | +#ifndef LEVEL_01_H_INCLUDED |
1237 | +#define LEVEL_01_H_INCLUDED |
1238 | + |
1239 | + |
1240 | +/** |
1241 | + * \file level_01.h |
1242 | + * \brief The header file of level_01.c. |
1243 | + */ |
1244 | + |
1245 | + |
1246 | +#include "../main_functions.h" |
1247 | +#include "../refresh.h" |
1248 | +#include "../game.h" |
1249 | + |
1250 | + |
1251 | +void level_01(SDL_Surface *screen); |
1252 | + |
1253 | + |
1254 | +#endif //LEVEL_01_H_INCLUDED |
1255 | + |
1256 | |
1257 | === modified file 'src/main.c' |
1258 | --- src/main.c 2011-04-30 20:10:07 +0000 |
1259 | +++ src/main.c 2011-05-07 13:57:29 +0000 |
1260 | @@ -53,6 +53,9 @@ |
1261 | #include "refresh.h" |
1262 | #include "main_menu.h" |
1263 | #include "credits.h" |
1264 | +#include "game.h" |
1265 | +#include "levels/level_01.h" |
1266 | + |
1267 | |
1268 | |
1269 | /** |
1270 | @@ -95,8 +98,10 @@ |
1271 | //Menus music |
1272 | Mix_Music *menu_music = load_music_resource("menu.ogg"); |
1273 | Mix_PlayMusic(menu_music, -1); |
1274 | - //Refresh |
1275 | + //Init refresh |
1276 | refresh_init(screen); |
1277 | + //Init game |
1278 | + init_game(); |
1279 | //Main menu |
1280 | int selected; |
1281 | while (1) |
1282 | @@ -106,7 +111,7 @@ |
1283 | { |
1284 | case 0: |
1285 | Mix_HaltMusic(); |
1286 | - printf("Main menu > Play\n"); //TODO |
1287 | + level_01(screen); |
1288 | Mix_PlayMusic(menu_music, -1); |
1289 | break; |
1290 | case 1: |
1291 | |
1292 | === modified file 'src/parser.c' |
1293 | --- src/parser.c 2011-05-02 20:33:13 +0000 |
1294 | +++ src/parser.c 2011-05-07 13:57:29 +0000 |
1295 | @@ -174,7 +174,7 @@ |
1296 | //TODO |
1297 | #endif |
1298 | #ifdef MAC_OS |
1299 | - strcpy(filepath, "./Damn Monkey.app/Contents/Resources"); |
1300 | + strcpy(filepath, "./Damn Monkey.app/Contents/Resources/"); |
1301 | strcat(filepath, resource_path); |
1302 | #endif |
1303 | file = fopen(filepath,"r"); |