Merge lp:~damn-monkey-devs/damn-monkey/game-and-lives-management into lp:damn-monkey

Proposed by Vincent PEYROUSE (GodezInc)
Status: Merged
Approved by: Fabien LOISON
Approved revision: 30
Merged at revision: 26
Proposed branch: lp:~damn-monkey-devs/damn-monkey/game-and-lives-management
Merge into: lp:damn-monkey
Diff against target: 172 lines (+103/-3)
4 files modified
src/game.c (+99/-1)
src/game.h (+2/-1)
src/levels/level_01.c (+1/-0)
src/main.c (+1/-1)
To merge this branch: bzr merge lp:~damn-monkey-devs/damn-monkey/game-and-lives-management
Reviewer Review Type Date Requested Status
Fabien LOISON Approve
Review via email: mp+63365@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Fabien LOISON (flozz) wrote :

I think that the code that display the remaining lives should be in the lets_play_yeah() function instead of the level_01() function. And the lives must be on the LAYER_FG layer instead of the LAYER_MENU layer.

review: Needs Fixing
30. By Vincent PEYROUSE (GodezInc)

* Some code refactoring

Revision history for this message
Fabien LOISON (flozz) wrote :

All right :)

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== added file 'pixmaps/life.png'
0Binary files pixmaps/life.png 1970-01-01 00:00:00 +0000 and pixmaps/life.png 2011-06-03 11:21:31 +0000 differ0Binary files pixmaps/life.png 1970-01-01 00:00:00 +0000 and pixmaps/life.png 2011-06-03 11:21:31 +0000 differ
=== modified file 'src/game.c'
--- src/game.c 2011-05-19 17:22:16 +0000
+++ src/game.c 2011-06-03 11:21:31 +0000
@@ -44,6 +44,84 @@
4444
4545
46#include "game.h"46#include "game.h"
47#include "levels/level_01.h"
48
49
50/**
51 * \fn void game(SDL_Surface *screen)
52 * \brief Play to the game.
53 *
54 * This function manage the levels and the lives.
55 *
56 * \param screen The main surface (called screen in the main() function).
57 */
58void game(SDL_Surface *screen)
59{
60 int current_level = 1;
61 int levels_count = 1; //Number of levels
62 JUMPMAN_LIVES = 3;
63 GAME_SPEED = 1;
64 GAME_STATE = GAME_STATE_PLAYING;
65
66 while (GAME_STATE != GAME_STATE_NONE && GAME_STATE != GAME_STATE_OVER)
67 {
68 //Launch the level
69 switch (current_level)
70 {
71 case 1:
72 level_01(screen);
73 break;
74 default:
75 break;
76 }
77 //Check the status
78 switch (GAME_STATE)
79 {
80 case GAME_STATE_LIFE_LOST:
81 JUMPMAN_LIVES -= 1;
82 if (JUMPMAN_LIVES <= 0)
83 {
84 GAME_STATE = GAME_STATE_OVER;
85 }
86 break;
87 case GAME_STATE_LEVEL_COMPLETED:
88 current_level += 1;
89 if (current_level > levels_count)
90 {
91 current_level = 1; //Restart with the first level;
92 GAME_SPEED++;
93 }
94 break;
95 case GAME_STATE_NONE:
96 break;
97 default:
98 printf("W: Abnormal game status: %i", GAME_STATE);
99 GAME_STATE = GAME_STATE_NONE;
100 break;
101 }
102 }
103 if (GAME_STATE == GAME_STATE_OVER)
104 {
105 DM_Surface *bg = load_resource_as_dm_surface("menu_bg.png");
106 int bg_refresh = ref_object(&LAYER_MENU, bg, surface_refresh_cb);
107 DM_Surface *text = malloc(sizeof(DM_Surface));
108 text->surface = str_to_surface("font_menu.png", "GAME OVER");
109 text->rect.w = text->surface->w;
110 text->rect.h = text->surface->h;
111 text->rect.x = (screen->w - text->rect.w) / 2;
112 text->rect.y = (screen->h / 3);
113 int text_refresh = ref_object(&LAYER_MENU, text, surface_refresh_cb);
114 //TODO : Make it became sexier with a picture and sad song
115 SDL_Delay(2000);
116 deref_object(&LAYER_MENU, bg_refresh);
117 deref_object(&LAYER_MENU, text_refresh);
118 SDL_Delay(20);
119 free_dm_surface(bg);
120 free_dm_surface(text);
121 }
122 //End of the game
123 GAME_STATE == GAME_STATE_NONE;
124}
47125
48126
49/**127/**
@@ -155,6 +233,21 @@
155 Mix_Chunk *sound_die = load_sound_resource("die.wav");233 Mix_Chunk *sound_die = load_sound_resource("die.wav");
156 //Initialize the GAME_STATE variable234 //Initialize the GAME_STATE variable
157 GAME_STATE = GAME_STATE_PLAYING;235 GAME_STATE = GAME_STATE_PLAYING;
236 //Load and show remaining lifes
237 DM_Surface *life = load_resource_as_dm_surface("life.png");
238 life->rect.x = 730;
239 life->rect.y = 17;
240 int life_refresh = ref_object(&LAYER_FG, life, surface_refresh_cb);
241 DM_Surface *life_text = malloc(sizeof(DM_Surface));
242 //"x <number of remaining lives>" surface creation
243 char life_char[3];
244 sprintf(life_char, "x%d", JUMPMAN_LIVES);
245 life_text->surface = str_to_surface("font_main.png", life_char);
246 life_text->rect.w = life_text->surface->w;
247 life_text->rect.h = life_text->surface->h;
248 life_text->rect.x = life->rect.x + life->rect.w + 5;
249 life_text->rect.y = life->rect.y;
250 int life_text_refresh = ref_object(&LAYER_FG, life_text, surface_refresh_cb);
158 //Set the start position of Jumpman251 //Set the start position of Jumpman
159 JUMPMAN.movement = map->start_look;252 JUMPMAN.movement = map->start_look;
160 JUMPMAN.pos_x = map->start_point_x - JUMPMAN.sprite->items[JUMPMAN.movement].w / 2;253 JUMPMAN.pos_x = map->start_point_x - JUMPMAN.sprite->items[JUMPMAN.movement].w / 2;
@@ -573,10 +666,15 @@
573666
574 //TODO if the player win, play a music,...667 //TODO if the player win, play a music,...
575668
576 //Dereference Jumpman669 //Dereference Jumpman and remaining lifes
577 deref_object(&LAYER_ACTIVE, jumpman_refresh);670 deref_object(&LAYER_ACTIVE, jumpman_refresh);
671 deref_object(&LAYER_FG, life_text_refresh);
672 deref_object(&LAYER_FG, life_refresh);
673 SDL_Delay(50);
578 //Free the memory674 //Free the memory
579 Mix_FreeChunk(sound_die);675 Mix_FreeChunk(sound_die);
676 free_dm_surface(life_text);
677 free_dm_surface(life);
580 //Return the game state678 //Return the game state
581 return GAME_STATE;679 return GAME_STATE;
582}680}
583681
=== modified file 'src/game.h'
--- src/game.h 2011-05-13 18:40:34 +0000
+++ src/game.h 2011-06-03 11:21:31 +0000
@@ -233,11 +233,12 @@
233int GAME_STATE;233int GAME_STATE;
234/**234/**
235 * \var JUMPMAN_LIVES235 * \var JUMPMAN_LIVES
236 * \brief The remaining lives of Jumpman (FIXME not implemented yet).236 * \brief The remaining lives of Jumpman
237 */237 */
238int JUMPMAN_LIVES;238int JUMPMAN_LIVES;
239239
240240
241void game(SDL_Surface *screen);
241void init_game();242void init_game();
242void update_jumpman();243void update_jumpman();
243int lets_play_yeah(SDL_Surface *screen, DM_Map *map);244int lets_play_yeah(SDL_Surface *screen, DM_Map *map);
244245
=== modified file 'src/levels/level_01.c'
--- src/levels/level_01.c 2011-05-13 18:51:52 +0000
+++ src/levels/level_01.c 2011-06-03 11:21:31 +0000
@@ -57,6 +57,7 @@
57 57
58 //Load the level infos (collides,...)58 //Load the level infos (collides,...)
59 DM_Map *map = load_map_infos("level_01");59 DM_Map *map = load_map_infos("level_01");
60
60 lets_play_yeah(screen, map);61 lets_play_yeah(screen, map);
61 62
62 //Dereference objects and free the memory63 //Dereference objects and free the memory
6364
=== modified file 'src/main.c'
--- src/main.c 2011-05-13 14:54:31 +0000
+++ src/main.c 2011-06-03 11:21:31 +0000
@@ -147,7 +147,7 @@
147 {147 {
148 case MAIN_MENU_PLAY:148 case MAIN_MENU_PLAY:
149 Mix_HaltMusic();149 Mix_HaltMusic();
150 level_01(screen);150 game(screen);
151 Mix_PlayMusic(menu_music, -1);151 Mix_PlayMusic(menu_music, -1);
152 break;152 break;
153 case MAIN_MENU_CREDITS:153 case MAIN_MENU_CREDITS:

Subscribers

People subscribed via source and target branches

to all changes: