Merge lp:~damn-monkey-devs/damn-monkey/barrels into lp:damn-monkey
- barrels
- Merge into trunk
Proposed by
Vincent PEYROUSE (GodezInc)
Status: | Merged |
---|---|
Approved by: | Fabien LOISON |
Approved revision: | 33 |
Merge reported by: | Vincent PEYROUSE (GodezInc) |
Merged at revision: | not available |
Proposed branch: | lp:~damn-monkey-devs/damn-monkey/barrels |
Merge into: | lp:damn-monkey |
Diff against target: |
639 lines (+478/-47) 8 files modified
levels/level_01.map (+17/-25) pixmaps/barrel.sprite (+6/-0) pixmaps/damnmonkey.sprite (+6/-4) pixmaps/help.sprite (+4/-0) pixmaps/lady.sprite (+4/-4) src/game.c (+11/-7) src/levels/level_01.c (+365/-5) src/levels/level_01.h (+65/-2) |
To merge this branch: | bzr merge lp:~damn-monkey-devs/damn-monkey/barrels |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Fabien LOISON | Pending | ||
Review via email: mp+63502@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 'levels/level_01.map' |
2 | --- levels/level_01.map 2011-05-12 20:20:45 +0000 |
3 | +++ levels/level_01.map 2011-06-05 20:31:10 +0000 |
4 | @@ -1,25 +1,17 @@ |
5 | -#Jumpman start point ; x ; y ; - ; - ; |
6 | -jumpman-start-left ; 762 ; 557 ; 0 ; 0 ; |
7 | - |
8 | -#Finish rectangle ; x1 ; y1 ; x2 ; y2 ; |
9 | -finish-collide ; 462 ; 88 ; 491 ; 91 ; |
10 | - |
11 | -#Platforms collide lines ; x1 ; y1 ; x2 ; y2 ; |
12 | -platform-collide ; 799 ; 558 ; 661 ; 558 ; |
13 | -platform-collide ; 661 ; 558 ; 13 ; 542 ; |
14 | -platform-collide ; 135 ; 467 ; 787 ; 451 ; |
15 | -platform-collide ; 665 ; 382 ; 13 ; 366 ; |
16 | -platform-collide ; 135 ; 291 ; 787 ; 275 ; |
17 | -platform-collide ; 667 ; 206 ; 297 ; 175 ; |
18 | -platform-collide ; 297 ; 175 ; 8 ; 175 ; |
19 | - |
20 | -#Platforms collide rect ; x1 ; y1 ; x2 ; y2 ; |
21 | -ladder-collide ; 156 ; 465 ; 185 ; 547 ; |
22 | -ladder-collide ; 394 ; 374 ; 423 ; 462 ; |
23 | -ladder-collide ; 600 ; 379 ; 629 ; 457 ; |
24 | -ladder-collide ; 275 ; 286 ; 304 ; 374 ; |
25 | -ladder-collide ; 149 ; 289 ; 178 ; 371 ; |
26 | -ladder-collide ; 604 ; 200 ; 633 ; 280 ; |
27 | -ladder-collide ; 462 ; 90 ; 491 ; 192 ; |
28 | - |
29 | - |
30 | +jumpman-start-left ; 762 ; 557 ; 0 ; 0 ; |
31 | +finish-collide ; 462 ; 88 ; 491 ; 91 ; |
32 | +platform-collide ; 799 ; 558 ; 661 ; 558 ; |
33 | +platform-collide ; 661 ; 558 ; 13 ; 542 ; |
34 | +platform-collide ; 135 ; 467 ; 787 ; 451 ; |
35 | +platform-collide ; 665 ; 382 ; 13 ; 366 ; |
36 | +platform-collide ; 135 ; 291 ; 787 ; 275 ; |
37 | +platform-collide ; 667 ; 206 ; 297 ; 175 ; |
38 | +platform-collide ; 297 ; 175 ; 8 ; 175 ; |
39 | +platform-collide ; 297 ; 175 ; 297 ; 117 ; |
40 | +ladder-collide ; 156 ; 465 ; 185 ; 547 ; |
41 | +ladder-collide ; 394 ; 374 ; 423 ; 462 ; |
42 | +ladder-collide ; 600 ; 379 ; 629 ; 457 ; |
43 | +ladder-collide ; 275 ; 286 ; 304 ; 374 ; |
44 | +ladder-collide ; 149 ; 289 ; 178 ; 371 ; |
45 | +ladder-collide ; 604 ; 200 ; 633 ; 280 ; |
46 | +ladder-collide ; 462 ; 90 ; 491 ; 192 ; |
47 | |
48 | === added file 'pixmaps/barrel.png' |
49 | Binary files pixmaps/barrel.png 1970-01-01 00:00:00 +0000 and pixmaps/barrel.png 2011-06-05 20:31:10 +0000 differ |
50 | === added file 'pixmaps/barrel.sprite' |
51 | --- pixmaps/barrel.sprite 1970-01-01 00:00:00 +0000 |
52 | +++ pixmaps/barrel.sprite 2011-06-05 20:31:10 +0000 |
53 | @@ -0,0 +1,6 @@ |
54 | +#Movement ; x ; y ; w ; h ; numb. img ; delay ms ; |
55 | +walk-right ; 0 ; 0 ; 24 ; 20 ; 4 ; 100 ; |
56 | +walk-left ; 0 ; 20 ; 24 ; 20 ; 4 ; 100 ; |
57 | +walk-ladder ; 0 ; 41 ; 34 ; 20 ; 2 ; 100 ; |
58 | + |
59 | + |
60 | |
61 | === modified file 'pixmaps/damnmonkey.png' (properties changed: +x to -x) |
62 | Binary files pixmaps/damnmonkey.png 2011-06-04 14:03:47 +0000 and pixmaps/damnmonkey.png 2011-06-05 20:31:10 +0000 differ |
63 | === modified file 'pixmaps/damnmonkey.sprite' (properties changed: +x to -x) |
64 | --- pixmaps/damnmonkey.sprite 2011-06-04 14:03:47 +0000 |
65 | +++ pixmaps/damnmonkey.sprite 2011-06-05 20:31:10 +0000 |
66 | @@ -1,4 +1,6 @@ |
67 | -#Movement ; x ; y ; w ; h ; numb. items ; delay ms ; |
68 | -ladder-walk ; 0 ; 163 ; 84 ; 95 ; 2 ; 160 ; |
69 | -throw-barrel; 0 ; 81 ; 109 ; 82 ; 3 ; 100 ; |
70 | -custom ; 0 ; 0 ; 87 ; 81 ; 1 ; 100 ; |
71 | \ No newline at end of file |
72 | +#Movement ; x ; y ; w ; h ; numb. img ; delay ms ; |
73 | +ladder-walk ; 0 ; 163 ; 84 ; 95 ; 2 ; 160 ; |
74 | +throw-barrel ; 0 ; 81 ; 110 ; 82 ; 3 ; 220 ; |
75 | +custom ; 0 ; 0 ; 87 ; 81 ; 1 ; 100 ; |
76 | + |
77 | + |
78 | |
79 | === added file 'pixmaps/help.png' |
80 | Binary files pixmaps/help.png 1970-01-01 00:00:00 +0000 and pixmaps/help.png 2011-06-05 20:31:10 +0000 differ |
81 | === added file 'pixmaps/help.sprite' |
82 | --- pixmaps/help.sprite 1970-01-01 00:00:00 +0000 |
83 | +++ pixmaps/help.sprite 2011-06-05 20:31:10 +0000 |
84 | @@ -0,0 +1,4 @@ |
85 | +#Movement ; x ; y ; w ; h ; numb. img ; delay ms ; |
86 | +custom ; 0 ; 0 ; 54 ; 36 ; 2 ; 1500 ; |
87 | + |
88 | + |
89 | |
90 | === modified file 'pixmaps/jumpman.png' (properties changed: +x to -x) |
91 | === modified file 'pixmaps/lady.png' (properties changed: +x to -x) |
92 | Binary files pixmaps/lady.png 2011-06-01 15:27:06 +0000 and pixmaps/lady.png 2011-06-05 20:31:10 +0000 differ |
93 | === modified file 'pixmaps/lady.sprite' (properties changed: +x to -x) |
94 | --- pixmaps/lady.sprite 2011-06-01 15:27:06 +0000 |
95 | +++ pixmaps/lady.sprite 2011-06-05 20:31:10 +0000 |
96 | @@ -1,4 +1,4 @@ |
97 | -#Movement ; x ; y ; w ; h ; numb. items ; delay ms ; |
98 | -ask-help ; 0 ; 42 ; 54 ; 36 ; 1 ; 100 ; |
99 | -custom ; 0 ; 0 ; 40 ; 42 ; 2 ; 1000 ; |
100 | - |
101 | +#Movement ; x ; y ; w ; h ; numb. img ; delay ms ; |
102 | +ask-help ; 0 ; 0 ; 40 ; 42 ; 2 ; 1000 ; |
103 | + |
104 | + |
105 | |
106 | === modified file 'pixmaps/life.png' (properties changed: +x to -x) |
107 | === modified file 'pixmaps/pause_menu.png' (properties changed: +x to -x) |
108 | === modified file 'src/game.c' |
109 | --- src/game.c 2011-06-03 11:20:13 +0000 |
110 | +++ src/game.c 2011-06-05 20:31:10 +0000 |
111 | @@ -60,7 +60,7 @@ |
112 | int current_level = 1; |
113 | int levels_count = 1; //Number of levels |
114 | JUMPMAN_LIVES = 3; |
115 | - GAME_SPEED = 1; |
116 | + GAME_SPEED = 0; |
117 | GAME_STATE = GAME_STATE_PLAYING; |
118 | |
119 | while (GAME_STATE != GAME_STATE_NONE && GAME_STATE != GAME_STATE_OVER) |
120 | @@ -85,11 +85,15 @@ |
121 | } |
122 | break; |
123 | case GAME_STATE_LEVEL_COMPLETED: |
124 | - current_level += 1; |
125 | + GAME_SPEED += 1; |
126 | + if (GAME_SPEED >= 4) |
127 | + { |
128 | + current_level +=1; |
129 | + GAME_SPEED = 0; |
130 | + } |
131 | if (current_level > levels_count) |
132 | { |
133 | - current_level = 1; //Restart with the first level; |
134 | - GAME_SPEED++; |
135 | + current_level = 1; //Restart with the first level; |
136 | } |
137 | break; |
138 | case GAME_STATE_NONE: |
139 | @@ -120,7 +124,7 @@ |
140 | free_dm_surface(text); |
141 | } |
142 | //End of the game |
143 | - GAME_STATE == GAME_STATE_NONE; |
144 | + GAME_STATE = GAME_STATE_NONE; |
145 | } |
146 | |
147 | |
148 | @@ -509,7 +513,7 @@ |
149 | JUMPMAN.platform_collide.x1--; |
150 | if (!check_platform_collides(&JUMPMAN.platform_collide, map)) |
151 | { |
152 | - JUMPMAN.pos_x -= 1; |
153 | + JUMPMAN.pos_x -= 2; |
154 | } |
155 | else |
156 | { |
157 | @@ -531,7 +535,7 @@ |
158 | JUMPMAN.platform_collide.x1++; |
159 | if (!check_platform_collides(&JUMPMAN.platform_collide, map)) |
160 | { |
161 | - JUMPMAN.pos_x += 1; |
162 | + JUMPMAN.pos_x += 2; |
163 | } |
164 | else |
165 | { |
166 | |
167 | === modified file 'src/levels/level_01.c' |
168 | --- src/levels/level_01.c 2011-06-03 11:20:13 +0000 |
169 | +++ src/levels/level_01.c 2011-06-05 20:31:10 +0000 |
170 | @@ -44,6 +44,283 @@ |
171 | |
172 | |
173 | /** |
174 | + * \fn void barrel_init(SDL_Surface *screen) |
175 | + * \brief Initialize the barrel refresh |
176 | + * |
177 | + * \param screen The main SDL_Surface. |
178 | + */ |
179 | +void barrel_init(SDL_Surface *screen) |
180 | +{ |
181 | + barrel_timer = SDL_AddTimer(20, _barrel_cb, NULL); |
182 | +} |
183 | + |
184 | + |
185 | +/** |
186 | + * \fn void barrel_destroy() |
187 | + * \brief Stop the refresh |
188 | + */ |
189 | +void barrel_destroy() |
190 | +{ |
191 | + SDL_RemoveTimer(barrel_timer); |
192 | +} |
193 | + |
194 | + |
195 | +/** |
196 | + * \fn int ref_barrel(void *object, void (*callback)()) |
197 | + * \brief Add a barrel to the refresh list. |
198 | + * |
199 | + * \param object A pointer on the object |
200 | + * \param callback The callback function that will be called for blitting the |
201 | + * object. This function must have a prototype that looks |
202 | + * like that: |
203 | + * \code |
204 | + * void function_name(void *object, SDL_Surface *screen); |
205 | + * \endcode |
206 | + * |
207 | + * \return The id of the refresh item. |
208 | + */ |
209 | +int ref_barrel(void *object, void (*callback)()) |
210 | +{ |
211 | + int barrel_id = ref_object(&LAYER_ACTIVE, object, callback); |
212 | + return barrel_id; |
213 | +} |
214 | + |
215 | + |
216 | +/** |
217 | + * \fn void deref_barrel(int id) |
218 | + * \brief Dereference a barrel. |
219 | + * |
220 | + * \param id The identifier of the object. |
221 | + */ |
222 | +void deref_barrel(int id) |
223 | +{ |
224 | + deref_object(&LAYER_ACTIVE, id); |
225 | +} |
226 | + |
227 | + |
228 | +/** \cond */ //Hide the "privates" functions to Doxygen |
229 | + |
230 | +//Callback function for the barrel_timer |
231 | +Uint32 _barrel_cb(Uint32 interval, void *arg) |
232 | +{ |
233 | + if (GAME_STATE != GAME_STATE_PAUSED) |
234 | + { |
235 | + int i; |
236 | + //Every 'turn' we check every barrel |
237 | + for (i=0 ; i<BARRELS->numb_items ; i++) |
238 | + { |
239 | + if (BARRELS->barrels[i].sprite->screen_pos.x > 780 \ |
240 | + || BARRELS->barrels[i].sprite->screen_pos.y > 550) |
241 | + { |
242 | + //The barrel is at the level end, we dereference it and replace |
243 | + //at the level beginning |
244 | + deref_barrel(BARRELS->barrels[i].refresh_id); |
245 | + BARRELS->barrels[i].refresh_id = -1; |
246 | + SDL_Delay(20); |
247 | + BARRELS->barrels[i].sprite->screen_pos.x = 0; |
248 | + BARRELS->barrels[i].sprite->screen_pos.y = 150; |
249 | + } |
250 | + else if (BARRELS->barrels[i].sprite->screen_pos.x == 150 \ |
251 | + && BARRELS->barrels[i].sprite->screen_pos.y == 150) |
252 | + { |
253 | + //The barrel is after Donkey Kong, we reference it and show it |
254 | + BARRELS->barrels[i].refresh_id = ref_barrel( |
255 | + &BARRELS->barrels[i], |
256 | + barrel_cb |
257 | + ); |
258 | + } |
259 | + else if (BARRELS->barrels[i].sprite->screen_pos.x < 150 \ |
260 | + && BARRELS->barrels[i].sprite->screen_pos.y == 150) |
261 | + { |
262 | + //The barrel is waiting to being launched |
263 | + if (BARRELS->barrels[BARRELS->last_sent].sprite->screen_pos.y \ |
264 | + >= 180 - 8 * GAME_SPEED - 5) |
265 | + { |
266 | + BARRELS->damnmonkey->current_mov = SPRITE_THROW_BARREL; |
267 | + } |
268 | + if (BARRELS->barrels[BARRELS->last_sent].sprite->screen_pos.y \ |
269 | + >= 180 - 8 * GAME_SPEED) |
270 | + { |
271 | + //The last barrel is already sent with an enough offset, |
272 | + //we can launch the next one. |
273 | + BARRELS->damnmonkey->current_mov = SPRITE_CUSTOM; |
274 | + BARRELS->last_sent = i; |
275 | + BARRELS->barrels[i].sprite->screen_pos.x = 150; |
276 | + } |
277 | + } |
278 | + } |
279 | + return refresh_cb(interval, &LAYER_ACTIVE); |
280 | + } |
281 | + return interval; |
282 | +} |
283 | + |
284 | +/** \endcond */ |
285 | + |
286 | + |
287 | +/** |
288 | + * \fn void barrel_cb(void *object, SDL_Surface *screen) |
289 | + * \brief Callback function for blitting DM_Barrel |
290 | + * |
291 | + * \param object The DM_Barrel to blit. |
292 | + * \param screen The main surface. |
293 | + */ |
294 | +void barrel_cb(void *object, SDL_Surface *screen) |
295 | +{ |
296 | + if (GAME_STATE != GAME_STATE_PAUSED) |
297 | + { |
298 | + DM_Barrel *barrel = object; |
299 | + |
300 | + //Damn Monkey collide initialisation |
301 | + DM_Collide damnmonkey_collide; |
302 | + damnmonkey_collide.shape = COLLIDE_RECT; |
303 | + damnmonkey_collide.x1 = BARRELS->damnmonkey->screen_pos.x; |
304 | + damnmonkey_collide.y1 = BARRELS->damnmonkey->screen_pos.y; |
305 | + damnmonkey_collide.x2 = BARRELS->damnmonkey->screen_pos.x + \ |
306 | + BARRELS->damnmonkey->screen_pos.w; |
307 | + damnmonkey_collide.y2 = BARRELS->damnmonkey->screen_pos.y + \ |
308 | + BARRELS->damnmonkey->screen_pos.h; |
309 | + |
310 | + if (!collide(barrel->jumpman_collide, &JUMPMAN.enemy_collide) \ |
311 | + && !collide(&JUMPMAN.enemy_collide, &damnmonkey_collide)) |
312 | + { |
313 | + //There's no collision between Jumpman and a barrel |
314 | + if (check_ladder_top_collides(barrel->platform_collide, barrel->map) \ |
315 | + && barrel->platform_collide->x1 == get_collide_ladder_center( |
316 | + barrel->platform_collide, barrel->map |
317 | + ) |
318 | + ) |
319 | + { |
320 | + //The barrel is on a ladder, random fall on the ladder |
321 | + if (rand()%2) |
322 | + { |
323 | + barrel->sprite->current_mov = SPRITE_WALK_LADDER; |
324 | + barrel->sprite->screen_pos.y = barrel->sprite->screen_pos.y \ |
325 | + + 4; |
326 | + } |
327 | + else |
328 | + { |
329 | + //Movement continuation |
330 | + if (barrel->sprite->current_mov != SPRITE_WALK_LEFT) |
331 | + { |
332 | + barrel->sprite->screen_pos.x++; |
333 | + } |
334 | + else |
335 | + { |
336 | + barrel->sprite->screen_pos.x--; |
337 | + } |
338 | + } |
339 | + } |
340 | + else |
341 | + { |
342 | + //The barrel isn't on a ladder so we check if it is in |
343 | + //collision with a platform |
344 | + if (check_platform_collides(barrel->platform_collide, barrel->map)) |
345 | + { |
346 | + //We generate the good movement according to the gravity |
347 | + barrel->sprite->current_mov = check_platform_orientation( |
348 | + barrel->platform_collide, |
349 | + barrel->map |
350 | + ); |
351 | + if (barrel->sprite->current_mov != SPRITE_WALK_LEFT) |
352 | + { |
353 | + barrel->sprite->screen_pos.x++; |
354 | + } |
355 | + else |
356 | + { |
357 | + barrel->sprite->screen_pos.x--; |
358 | + } |
359 | + } |
360 | + else |
361 | + { |
362 | + //No collision : the barrel is falling/descending |
363 | + barrel->sprite->screen_pos.y++; |
364 | + } |
365 | + } |
366 | + |
367 | + //Collision rect and point update |
368 | + barrel->jumpman_collide->x1 = barrel->sprite->screen_pos.x + 2; |
369 | + barrel->jumpman_collide->y1 = barrel->sprite->screen_pos.y + 2; |
370 | + barrel->jumpman_collide->x2 = barrel->jumpman_collide->x1 + barrel->sprite->items[barrel->sprite->current_mov].w - 4; |
371 | + barrel->jumpman_collide->y2 = barrel->jumpman_collide->y1 + barrel->sprite->items[barrel->sprite->current_mov].w - 4; |
372 | + barrel->platform_collide->x1 = barrel->jumpman_collide->x1 + (barrel->sprite->items[barrel->sprite->current_mov].w / 2); |
373 | + barrel->platform_collide->y1 = barrel->jumpman_collide->y1 + barrel->sprite->items[barrel->sprite->current_mov].h; |
374 | + barrel->platform_collide->x2 = 0; |
375 | + barrel->platform_collide->y2 = 0; |
376 | + } |
377 | + else |
378 | + { |
379 | + //There's a collision between Jumpman and a barrel => A life lost |
380 | + GAME_STATE = GAME_STATE_LIFE_LOST; |
381 | + } |
382 | + //Call of sprite_cb in order to update the screen |
383 | + sprite_cb(barrel->sprite, screen); |
384 | + } |
385 | +} |
386 | + |
387 | + |
388 | +/** |
389 | + * \fn int check_platform_orientation(DM_Collide *collide_point, DM_Map *map) |
390 | + * \brief Function for checking platform orientation |
391 | + * |
392 | + * \param collide_point The barrel collide point to check. |
393 | + * \param map The pointer to the DM_Map structure. |
394 | + * |
395 | + * \return int The barrel movement corresponding to the platform orientation. |
396 | + */ |
397 | +int check_platform_orientation(DM_Collide *collide_point, DM_Map *map) |
398 | +{ |
399 | + int i; |
400 | + for (i=0 ; i<map->platform_count ; i++) |
401 | + { |
402 | + //The collide function allow us to find the barrel which is considered |
403 | + if (collide(collide_point, &map->platforms[i])) |
404 | + { |
405 | + if (map->platforms[i].x1 < map->platforms[i].x2 \ |
406 | + && map->platforms[i].y1 > map->platforms[i].y2) |
407 | + { |
408 | + return SPRITE_WALK_LEFT; |
409 | + } |
410 | + else if (map->platforms[i].x1 < map->platforms[i].x2 \ |
411 | + && map->platforms[i].y1 < map->platforms[i].y2) |
412 | + { |
413 | + return SPRITE_WALK_RIGHT; |
414 | + } |
415 | + else if (map->platforms[i].x1 > map->platforms[i].x2 \ |
416 | + && map->platforms[i].y1 > map->platforms[i].y2) |
417 | + { |
418 | + return SPRITE_WALK_RIGHT; |
419 | + } |
420 | + else if (map->platforms[i].x1 > map->platforms[i].x2 \ |
421 | + && map->platforms[i].y1 < map->platforms[i].y2) |
422 | + { |
423 | + return SPRITE_WALK_LEFT; |
424 | + } |
425 | + else if (map->platforms[i].y1 == map->platforms[i].y2) |
426 | + { |
427 | + return SPRITE_WALK_RIGHT; |
428 | + } |
429 | + } |
430 | + } |
431 | + return 42; |
432 | +} |
433 | + |
434 | + |
435 | +/** |
436 | + * \fn void free_dm_barrel(DM_Barrel *barrels) |
437 | + * \brief Releases the memory of a DM_Barrel pointer. |
438 | + * |
439 | + * \param splited The DM_Barrel pointer to free. |
440 | + */ |
441 | +void free_dm_barrel(DM_Barrel *barrel) |
442 | +{ |
443 | + //We don't deallocate the map pointer because it'll be freed later |
444 | + free_sprite(barrel->sprite); |
445 | + free(barrel->jumpman_collide); |
446 | + free(barrel->platform_collide); |
447 | +} |
448 | + |
449 | + |
450 | +/** |
451 | * \fn void level_01(SDL_Surface *screen) |
452 | * \brief Play to the first level. |
453 | * |
454 | @@ -53,17 +330,100 @@ |
455 | { |
456 | //Load the background |
457 | DM_Surface *level_surface = load_resource_as_dm_surface("level_01.png"); |
458 | - int level_surface_refresh = ref_object(&LAYER_BG, level_surface, surface_refresh_cb); |
459 | - |
460 | + int level_surface_refresh = ref_object( |
461 | + &LAYER_BG, |
462 | + level_surface, |
463 | + surface_refresh_cb |
464 | + ); |
465 | + |
466 | + //Load Lady and help sprites |
467 | + DM_Sprite *lady = new_sprite("lady"); |
468 | + lady->current_mov = SPRITE_ASK_HELP; |
469 | + lady->screen_pos.x = 300; |
470 | + lady->screen_pos.y = 48; |
471 | + int lady_refresh = ref_object(&LAYER_ACTIVE, lady, sprite_cb); |
472 | + DM_Sprite *help = new_sprite("help"); |
473 | + help->current_mov = SPRITE_CUSTOM; |
474 | + help->screen_pos.x = 340; |
475 | + help->screen_pos.y = 10; |
476 | + int help_refresh = ref_object(&LAYER_ACTIVE, help, sprite_cb); |
477 | + |
478 | //Load the level infos (collides,...) |
479 | DM_Map *map = load_map_infos("level_01"); |
480 | - |
481 | + |
482 | + //Load and play level music |
483 | + Mix_Music *level_music = load_music_resource("game.ogg"); |
484 | + Mix_PlayMusic(level_music, -1); |
485 | + |
486 | + //Load barrels and launch the barrel timer |
487 | + int i; |
488 | + int barrels_nb = 20; |
489 | + BARRELS = malloc(sizeof(DM_Barrel_Array)); |
490 | + BARRELS->numb_items = barrels_nb; |
491 | + BARRELS->last_sent = 0; |
492 | + BARRELS->barrels = malloc(BARRELS->numb_items * sizeof(DM_Barrel)); |
493 | + for (i=0 ; i<BARRELS->numb_items ; i++) |
494 | + { |
495 | + BARRELS->barrels[i].map = map; |
496 | + BARRELS->barrels[i].sprite = new_sprite("barrel"); |
497 | + BARRELS->barrels[i].sprite->current_mov = SPRITE_WALK_RIGHT; |
498 | + BARRELS->barrels[i].sprite->screen_pos.x = 0; |
499 | + BARRELS->barrels[i].sprite->screen_pos.y = 150; |
500 | + BARRELS->barrels[i].jumpman_collide = malloc(sizeof(DM_Collide)); |
501 | + BARRELS->barrels[i].jumpman_collide->shape = COLLIDE_RECT; |
502 | + BARRELS->barrels[i].jumpman_collide->x1 = BARRELS->barrels[i].sprite->screen_pos.x + 2; |
503 | + BARRELS->barrels[i].jumpman_collide->y1 = BARRELS->barrels[i].sprite->screen_pos.y + 2; |
504 | + BARRELS->barrels[i].jumpman_collide->x2 = BARRELS->barrels[i].jumpman_collide->x1 + \ |
505 | + BARRELS->barrels[i].sprite->items[BARRELS->barrels[i].sprite->current_mov].w - 4; |
506 | + BARRELS->barrels[i].jumpman_collide->y2 = BARRELS->barrels[i].jumpman_collide->x1 + \ |
507 | + BARRELS->barrels[i].sprite->items[BARRELS->barrels[i].sprite->current_mov].h - 4; |
508 | + BARRELS->barrels[i].platform_collide = malloc(sizeof(DM_Collide)); |
509 | + BARRELS->barrels[i].platform_collide->shape = COLLIDE_POINT; |
510 | + BARRELS->barrels[i].platform_collide->x1 = BARRELS->barrels[i].jumpman_collide->x1 \ |
511 | + + (BARRELS->barrels[i].sprite->screen_pos.w / 2); |
512 | + BARRELS->barrels[i].platform_collide->y1 = BARRELS->barrels[i].jumpman_collide->y1 \ |
513 | + + (BARRELS->barrels[i].sprite->screen_pos.h); |
514 | + BARRELS->barrels[i].platform_collide->x2 = 0; |
515 | + BARRELS->barrels[i].platform_collide->y2 = 0; |
516 | + BARRELS->barrels[i].refresh_id = -1; |
517 | + } |
518 | + BARRELS->barrels[0].sprite->screen_pos.x = 150; |
519 | + |
520 | + //Load Damn Monkey |
521 | + BARRELS->damnmonkey = new_sprite("damnmonkey"); |
522 | + BARRELS->damnmonkey->screen_pos.x = 55; |
523 | + BARRELS->damnmonkey->screen_pos.y = 94; |
524 | + BARRELS->damnmonkey->current_mov = SPRITE_CUSTOM; |
525 | + int damnmonkey_refresh = ref_object( |
526 | + &LAYER_ACTIVE, |
527 | + BARRELS->damnmonkey, |
528 | + sprite_cb |
529 | + ); |
530 | + |
531 | + //GAME_STATE gestion |
532 | + barrel_init(screen); |
533 | lets_play_yeah(screen, map); |
534 | - |
535 | //Dereference objects and free the memory |
536 | + barrel_destroy(); |
537 | + for(i=0 ; i<BARRELS->numb_items ; i++) |
538 | + { |
539 | + deref_barrel(BARRELS->barrels[i].refresh_id); |
540 | + } |
541 | + deref_object(&LAYER_ACTIVE, damnmonkey_refresh); |
542 | + deref_object(&LAYER_ACTIVE, help_refresh); |
543 | + deref_object(&LAYER_ACTIVE, lady_refresh); |
544 | deref_object(&LAYER_BG, level_surface_refresh); |
545 | SDL_Delay(50); |
546 | - free_dm_surface(level_surface); |
547 | + Mix_FreeMusic(level_music); |
548 | + for(i=0 ; i<BARRELS->numb_items ; i++) |
549 | + { |
550 | + free_dm_barrel(&BARRELS->barrels[i]); |
551 | + } |
552 | + free_sprite(BARRELS->damnmonkey); |
553 | + free(BARRELS); |
554 | + free_sprite(help); |
555 | + free_sprite(lady); |
556 | + free_dm_surface(level_surface); |
557 | free_dm_map(map); |
558 | } |
559 | |
560 | |
561 | === modified file 'src/levels/level_01.h' |
562 | --- src/levels/level_01.h 2011-05-13 14:54:31 +0000 |
563 | +++ src/levels/level_01.h 2011-06-05 20:31:10 +0000 |
564 | @@ -43,12 +43,75 @@ |
565 | #ifndef LEVEL_01_H_INCLUDED |
566 | #define LEVEL_01_H_INCLUDED |
567 | |
568 | +#include <stdio.h> |
569 | +#include <stdlib.h> |
570 | + |
571 | +#include "../conf.h" |
572 | + |
573 | +#ifdef LINUX |
574 | +#include "SDL.h" |
575 | +#endif |
576 | + |
577 | +#ifdef MAC_OS |
578 | +#include <SDL/SDL.h> |
579 | +#endif |
580 | + |
581 | +#ifdef WINDOWS |
582 | +#include <SDL.h> |
583 | +#endif |
584 | |
585 | #include "../main_functions.h" |
586 | #include "../refresh.h" |
587 | #include "../game.h" |
588 | - |
589 | - |
590 | +#include "../sprite.h" |
591 | + |
592 | + |
593 | +/** |
594 | + * \struct DM_Barrel |
595 | + * \brief Contain informations about one barrel. |
596 | + */ |
597 | +typedef struct DM_Barrel DM_Barrel; |
598 | +struct DM_Barrel |
599 | +{ |
600 | + DM_Map *map; /*!< Pointer to the DM_Map considered*/ |
601 | + DM_Collide *platform_collide; /*!< Collision point with platforms. */ |
602 | + DM_Collide *jumpman_collide; /*!< Collision rect with jumpman. */ |
603 | + DM_Sprite *sprite; /*!< The sprite of barrel. */ |
604 | + int refresh_id; /*!< The refresh id*/ |
605 | +}; |
606 | + |
607 | + |
608 | +/** |
609 | + * \struct DM_Barrel_Array |
610 | + * \brief Contain informations about barrels. |
611 | + */ |
612 | +typedef struct DM_Barrel_Array DM_Barrel_Array; |
613 | +struct DM_Barrel_Array |
614 | +{ |
615 | + DM_Barrel *barrels; /*!< Barrels array*/ |
616 | + DM_Sprite *damnmonkey; /*!< Damn Monkey sprite */ |
617 | + int numb_items; /*!< The number of barrels in the array*/ |
618 | + int last_sent; /*!< The last sent barrel index in the array*/ |
619 | +}; |
620 | + |
621 | + |
622 | +/** \cond */ //Hide this to doxygen |
623 | +SDL_TimerID barrel_timer; |
624 | +/** \endcond */ |
625 | + |
626 | +DM_Barrel_Array *BARRELS; |
627 | + |
628 | + |
629 | +void barrel_init(SDL_Surface *screen); |
630 | +void barrel_destroy(); |
631 | +int ref_barrel(void *object, void (*callback)()); |
632 | +void deref_barrel(int id); |
633 | +void barrel_cb(void *object, SDL_Surface *screen); |
634 | +/** \cond */ //Hide this to doxygen |
635 | +Uint32 _barrel_cb(Uint32 interval, void *arg); |
636 | +/** \endcond */ |
637 | +int check_platform_orientation(DM_Collide *collide_point, DM_Map *map); |
638 | +void free_dm_barrel(DM_Barrel *barrels); |
639 | void level_01(SDL_Surface *screen); |
640 | |
641 |